diff options
author | Romain d'Alverny <rda@mageia.org> | 2012-05-24 13:45:06 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2012-05-24 13:45:06 +0000 |
commit | 095b3d81037f5a3b3de44444845651c9c4f5c411 (patch) | |
tree | 6e654a24620a7db2f9d9c5c882fe8fa770473887 /langs/lib.php | |
parent | afeb046afd018f21547cd66d728f5181bb3628c1 (diff) | |
download | www-095b3d81037f5a3b3de44444845651c9c4f5c411.tar www-095b3d81037f5a3b3de44444845651c9c4f5c411.tar.gz www-095b3d81037f5a3b3de44444845651c9c4f5c411.tar.bz2 www-095b3d81037f5a3b3de44444845651c9c4f5c411.tar.xz www-095b3d81037f5a3b3de44444845651c9c4f5c411.zip |
reporting tools
Diffstat (limited to 'langs/lib.php')
-rw-r--r-- | langs/lib.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/langs/lib.php b/langs/lib.php new file mode 100644 index 000000000..86b13bf6f --- /dev/null +++ b/langs/lib.php @@ -0,0 +1,97 @@ +<?php +/** +*/ + +include '../langs.inc.php'; + +/** + * Diff two .lang files, to get: + * - strings count of each + * - missing strings (in $a, not in $b) + * - extra strings (in $b, not in $a) + * - untranslated strings (same in $a and $b, or empty in $b) + * + * @param string $a file name + * @param string $b file name + * + * @return array + * + * @todo some strings may be left untranslated on purpose +*/ +function _lang_diff($a, $b) +{ + $fa = _lang_return($a); + $fb = _lang_return($b); + + $ret = array( + 'aCount' => count($fa), + 'bCount' => count($fb), + 'diff' => count($fa) - count($fb), + ); + $missing = array(); + $notrans = array(); + + $ka = array_keys($fa); + $kb = array_keys($fb); + + $missing = array_diff($ka, $kb); + $extra = array_diff($kb, $ka); + + // search for untranslated strings + foreach ($fa as $k => $v) { + if (array_key_exists($k, $fb)) { + if ($v == $fb[$k] || '' == $fb[$k]) { + $notrans[] = $k . ': ' . $v; + } + } + } + + return array( + 'a' => count($fa), + 'b' => count($fb), + 'missing' => $missing, + 'notrans' => $notrans, + 'extra' => $extra + ); +} + + +if ( ! function_exists('glob_recursive')) +{ + // Does not support flag GLOB_BRACE + + function glob_recursive($pattern, $flags = 0) + { + $files = glob($pattern, $flags); + + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) + { + $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); + } + + return $files; + } +} + +function _lang_file_switch($s, $l) +{ + return $l . substr(str_replace('.en.lang', '.' . $l . '.lang', $s), 2); +} + +function get_lang_references() +{ + return glob_recursive('en/*', GLOB_MARK); +} + +function get_other_langs() +{ + $ls = glob('*'); + $re = array(); + foreach ($ls as $l) { + if (!is_dir($l)) continue; + if ($l == 'en') continue; + $re[] = $l; + } + array_unshift($re, 'en'); + return $re; +}
\ No newline at end of file |