[5301] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[5301] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
[5301] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | define('PHPWG_ROOT_PATH', '../'); |
---|
| 25 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
[5622] | 26 | include_once( PHPWG_ROOT_PATH.'tools/language/translation_validated.inc.php' ); |
---|
[5301] | 27 | $languages = array_keys(get_languages()); |
---|
[5314] | 28 | sort($languages); |
---|
[5301] | 29 | |
---|
| 30 | $page['ref_compare'] = 'en_UK'; |
---|
| 31 | $page['ref_default_values'] = 'en_UK'; |
---|
| 32 | |
---|
[5312] | 33 | if (!isset($_GET['lang'])) |
---|
| 34 | { |
---|
| 35 | echo '<a href="?lang=all">All languages</a><br><br>'; |
---|
| 36 | echo '<ul>'; |
---|
| 37 | foreach ($languages as $language) |
---|
| 38 | { |
---|
| 39 | if ($page['ref_compare'] == $language) |
---|
| 40 | { |
---|
| 41 | continue; |
---|
| 42 | } |
---|
| 43 | echo '<li><a href="?lang='.$language.'">'.$language.'</a></li>'; |
---|
| 44 | } |
---|
| 45 | echo '</ul>'; |
---|
| 46 | exit(); |
---|
| 47 | } |
---|
| 48 | else if (in_array($_GET['lang'], $languages)) |
---|
| 49 | { |
---|
| 50 | $languages = array($_GET['lang']); |
---|
| 51 | } |
---|
| 52 | |
---|
[5301] | 53 | $file_list = array('common', 'admin', 'install', 'upgrade'); |
---|
| 54 | |
---|
| 55 | $metalang = array(); |
---|
| 56 | |
---|
| 57 | // preload reference languages |
---|
| 58 | $metalang[ $page['ref_compare'] ] = load_metalang($page['ref_compare'], $file_list); |
---|
| 59 | $metalang[ $page['ref_default_values'] ] = load_metalang($page['ref_default_values'], $file_list); |
---|
| 60 | |
---|
| 61 | foreach ($languages as $language) |
---|
| 62 | { |
---|
| 63 | if (in_array($language, array($page['ref_compare'], $page['ref_default_values']))) |
---|
| 64 | { |
---|
| 65 | continue; |
---|
| 66 | } |
---|
| 67 | echo '<h2>'.$language.'</h2>'; |
---|
| 68 | $metalang[$language] = load_metalang($language, $file_list); |
---|
| 69 | |
---|
| 70 | foreach ($file_list as $file) |
---|
| 71 | { |
---|
| 72 | if (isset($metalang[ $language ][$file])) |
---|
| 73 | { |
---|
| 74 | $missing_keys = array_diff( |
---|
| 75 | array_keys($metalang[ $page['ref_compare'] ][$file]), |
---|
| 76 | array_keys($metalang[ $language ][$file]) |
---|
| 77 | ); |
---|
| 78 | |
---|
| 79 | $output_missing = ''; |
---|
| 80 | foreach ($missing_keys as $key) |
---|
| 81 | { |
---|
| 82 | $output_missing.= get_line_to_translate($file, $key); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // strings not "really" translated? |
---|
| 86 | $output_duplicated = ''; |
---|
[5309] | 87 | $output_lost = ''; |
---|
[5301] | 88 | foreach (array_keys($metalang[$language][$file]) as $key) |
---|
| 89 | { |
---|
| 90 | $exceptions = array('Level 0'); |
---|
| 91 | if (in_array($key, $exceptions)) |
---|
| 92 | { |
---|
| 93 | continue; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | if (isset($validated_keys[$language]) and in_array($key, $validated_keys[$language])) |
---|
| 97 | { |
---|
| 98 | continue; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | $local_value = $metalang[$language][$file][$key]; |
---|
[5309] | 102 | if (!isset($metalang[ $page['ref_default_values'] ][$file][$key])) |
---|
[5301] | 103 | { |
---|
[5309] | 104 | $output_lost.= '#'.$key.'# does not exist in the reference language'."\n"; |
---|
[5301] | 105 | } |
---|
[5309] | 106 | else |
---|
| 107 | { |
---|
| 108 | $ref_value = $metalang[ $page['ref_default_values'] ][$file][$key]; |
---|
| 109 | if ($local_value == $ref_value) |
---|
| 110 | { |
---|
| 111 | $output_duplicated.= get_line_to_translate($file, $key); |
---|
| 112 | } |
---|
| 113 | } |
---|
[5301] | 114 | } |
---|
| 115 | |
---|
[5563] | 116 | echo '<h3>'.$file.'.lang.php</h3>'; |
---|
| 117 | |
---|
[5301] | 118 | if ('' != $output_missing or '' != $output_duplicated) |
---|
| 119 | { |
---|
| 120 | $output = ''; |
---|
| 121 | if ('' != $output_missing) |
---|
| 122 | { |
---|
| 123 | $output.= "// missing translations\n".$output_missing; |
---|
| 124 | } |
---|
| 125 | if ('' != $output_duplicated) |
---|
| 126 | { |
---|
| 127 | $output.= "\n// untranslated yet\n".$output_duplicated; |
---|
| 128 | } |
---|
[5314] | 129 | echo '<textarea style="width:100%;height:250px;">'.$output.'</textarea>'; |
---|
[5301] | 130 | } |
---|
[5309] | 131 | |
---|
| 132 | if ('' != $output_lost) |
---|
| 133 | { |
---|
| 134 | echo '<pre>'.$output_lost.'</pre>'; |
---|
| 135 | } |
---|
[5301] | 136 | } |
---|
| 137 | else |
---|
| 138 | { |
---|
| 139 | echo '<h3>'.$file.'.lang.php is missing</h3>'; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | function load_metalang($language, $file_list) |
---|
| 145 | { |
---|
| 146 | global $lang, $user; |
---|
| 147 | |
---|
| 148 | $metalang = array(); |
---|
| 149 | foreach ($file_list as $file) |
---|
| 150 | { |
---|
| 151 | $lang = array(); |
---|
| 152 | $user['language'] = $language; |
---|
| 153 | if (load_language($file.'.lang', '', array('language'=>$language, 'no_fallback'=>true))) |
---|
| 154 | { |
---|
| 155 | $metalang[$file] = $lang; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | return $metalang; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | function get_line_to_translate($file, $key) |
---|
| 162 | { |
---|
| 163 | global $metalang, $page; |
---|
| 164 | |
---|
| 165 | $print_key = str_replace("'", '\\\'', $key); |
---|
| 166 | $print_value = str_replace("'", '\\\'', $metalang[ $page['ref_default_values'] ][$file][$key]); |
---|
| 167 | return '$'."lang['".$print_key."'] = '".$print_value."';\n"; |
---|
| 168 | } |
---|
| 169 | ?> |
---|