#!/usr/bin/php
<?php

$lngs = array('e', 'g', 'f', 's', 'i');

$msg_ary = array();

foreach ($lngs as $lng) {
	$cont = file(__DIR__.'/../patch/'.$lng.'.txt');

	foreach ($cont as $c) {
		preg_match('@^\\[(.*)\\] (.*)@s', $c, $m);

		$key = $m[1];
		$msg = $m[2];

		$msg = str_replace("\n", '', $msg);
		$msg = str_replace("\r", '', $msg);
		$msg = str_replace('#', '', $msg);

		$msg_ = str_replace('#', '', $msg);
		$lastchar = substr($msg_, -1, 1);

		$punctation = ($lastchar == '.') || ($lastchar == '!') || ($lastchar == '?');

		$ary[$key][$lng] = $punctation;
		$msg_ary[$key][$lng] = $msg;
	}
}

foreach ($ary as $key => $data) {
	if (!array_has_same_contents($data)) {
		/*
		echo "Punctations are not equal. Key $key . Amounts: ";
		foreach ($data as $lng => $punctation) {
			$punctation = $punctation ? 'yes' : 'no';
			echo "$lng=$punctation ";
		}
		echo "- Hint: ".trim($e_ary[$key])."\n";
		*/
		echo "$key has no punctations in one language, but other languages have them:\n";
		foreach ($data as $lng => $punctation) {
			echo "\t$lng = ".trim($msg_ary[$key][$lng])."\n";
		}

	}
}


# ---

function array_has_same_contents($ary) {
	$first = true;
	$first_element = null;

	foreach ($ary as $element) {
		if ($first) {
			$first = false;
			$first_element = $element;
		} else {
			if ($element != $first_element) return false;
		}
	}

	return true;
}
