Skip to content

Instantly share code, notes, and snippets.

@vain
Created May 29, 2010 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vain/418194 to your computer and use it in GitHub Desktop.
Save vain/418194 to your computer and use it in GitHub Desktop.
#!/bin/bash
# a) Compare existing language resources.
# b) Check if some of the keys in the reference language resources are
# not used.
# c) Try to find all keys in the code and check if they're present in
# the reference language resources.
# Launch this script from the root directory of FluxBB.
lang_reference="${1:-lang/English}"
lang_trans="${2:-lang/German}"
ref_keys="${3:-/tmp/keys}"
> "$ref_keys"
for reffile in "$lang_reference"/*.php
do
basefile=$(basename "$reffile")
transfile="$lang_trans/$basefile"
basemodule=$(grep -o '^\$lang_[^ ]\+' "$reffile")
echo "** Comparing $basefile ($basemodule)... "
php <<EOF
<?php
include('$reffile');
\$reflang = $basemodule;
include('$transfile');
\$translang = $basemodule;
\$miss = array_keys(array_diff_key(\$reflang, \$translang));
if (count(\$miss) > 0)
echo "Missing in $lang_trans:\n\t".implode("\n\t", \$miss)."\n";
\$miss = array_keys(array_diff_key(\$translang, \$reflang));
if (count(\$miss) > 0)
echo "Missing in $lang_reference:\n\t".implode("\n\t", \$miss)."\n";
foreach (\$reflang as \$rk => \$dummy)
file_put_contents("$ref_keys",
'$basemodule'."['".\$rk."']\n", FILE_APPEND);
?>
EOF
done
echo "----------------"
echo "** Checking for unused keys of reference language..."
while read -r line
do
grep -R -F "$line" . >/dev/null 2>&1 || echo "Unused key: $line"
done < "$ref_keys"
echo "----------------"
echo "** Checking for missing keys in reference language..."
while read -r line
do
grep -F "$line" "$ref_keys" >/dev/null 2>&1 \
|| echo "Missing key: $line"
done < <(grep -R -oh "\$lang_[^[]\+\['[^']\+'\]" . | sort | uniq)
echo "----------------"
echo "Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment