Commit 2f05321f authored by haemmer's avatar haemmer

Added option to output all strings of en and another language

parent 77eba402
<?php <?php
/*
Usage:
* php check-locales.php
Checks all language strings against the reference language (Enlish).
It is checked whether a string is missing, obsolete and whether it contains
the same number of macros.
* php check-locales.php [langauge]
e.g. php check-locales.php fr
Outputs a HTML document that contains all strings of the reference language
(English) and [language]. This allows to easier spot discrepancies and
retranslate strings.
*/
// This script checks for missing and incomplete locales // This script checks for missing and incomplete locales
if (isset($_SERVER['REMOTE_ADDR'])){ if (isset($_SERVER['REMOTE_ADDR'])){
exit('No direct script access allowed'); exit('No direct script access allowed');
...@@ -7,29 +23,73 @@ if (isset($_SERVER['REMOTE_ADDR'])){ ...@@ -7,29 +23,73 @@ if (isset($_SERVER['REMOTE_ADDR'])){
require_once('languages.php'); require_once('languages.php');
include('custom-languages.php'); include('custom-languages.php');
echo "The following problems were found:\n"; if ($argc > 1){
$refLang = 'en'; $refLang = $argv[1];
foreach(array_keys($langStrings) as $lang){ echo <<<HEADER
if ($lang == 'en'){ <html>
continue; <head>
} <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h2>Output all "{$refLang}' language strings</h2>
<dl>
HEADER;
foreach ($langStrings['en'] as $k => $v){ foreach ($langStrings['en'] as $k => $v){
if (!isset($langStrings[$lang][$k])){ echo "<dt style='font-weigth: bold; color: purple;'>String: ".$k."</dt>\n<dd>\n";
echo "* In '$lang' missing locale '$k'\n";
} else if (substr_count($langStrings['en'][$k], '%s') != substr_count($langStrings[$lang][$k], '%s')){ echo "<strong>[en]:</strong> <span style='color: gray'>";
echo "* In '$lang' the number of substitutions (%s) differ for '$k': "; if (substr_count($langStrings['en'][$k], '%s') > 0) {
echo substr_count($langStrings['en'][$k], '%s').' vs '.substr_count($langStrings[$lang][$k], '%s'); echo sprintf($langStrings['en'][$k], 'https://example.value/1', 'https://example.value/2');
echo "\n"; } else {
echo $langStrings['en'][$k];
}
echo "</span><br />\n";
echo "<strong>[".$refLang."]:</strong> ";
if (isset($langStrings[$refLang][$k]) && substr_count($langStrings[$refLang][$k], '%s') > 0){
echo sprintf($langStrings[$refLang][$k], 'https://example.value/1', 'https://example.value/2');
} elseif (isset($langStrings[$refLang][$k])) {
echo $langStrings[$refLang][$k];
} else {
echo "---Missing---";
} }
echo "\n</dd>\n";
} }
foreach ($langStrings[$lang] as $k => $v){ echo <<<FOOTER
if (!isset($langStrings['en'][$k])){ </dl>
echo "In $lang obsolete locale $k\n"; </html>
FOOTER;
} else {
echo "The following problems were found:\n";
$refLang = 'en';
foreach(array_keys($langStrings) as $lang){
if ($lang == 'en'){
continue;
}
foreach ($langStrings['en'] as $k => $v){
if (!isset($langStrings[$lang][$k])){
echo "* In '$lang' missing locale '$k'\n";
} else if (substr_count($langStrings['en'][$k], '%s') != substr_count($langStrings[$lang][$k], '%s')){
echo "* In '$lang' the number of substitutions (%s) differ for '$k': ";
echo substr_count($langStrings['en'][$k], '%s').' vs '.substr_count($langStrings[$lang][$k], '%s');
echo "\n";
}
}
foreach ($langStrings[$lang] as $k => $v){
if (!isset($langStrings['en'][$k])){
echo "In $lang obsolete locale $k\n";
}
} }
} }
} }
?> ?>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment