source: branches/2.0/tools/translation_analysis.php @ 4638

Last change on this file since 4638 was 4638, checked in by plg, 14 years ago

feature 1374 related: force to load exactly the language requested and not any
fallback language. If the language file is missing, we tell it explicitely.

File size: 3.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
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
24define('PHPWG_ROOT_PATH', '../');
25include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
26
27$languages = array_keys(get_languages());
28
29$page['ref_compare'] = 'en_UK';
30$page['ref_default_values'] = 'en_UK';
31
32$file_list = array('common', 'admin', 'install', 'upgrade');
33
34$metalang = array();
35
36// preload reference languages
37$metalang[ $page['ref_compare'] ] = load_metalang($page['ref_compare'], $file_list);
38$metalang[ $page['ref_default_values'] ] = load_metalang($page['ref_default_values'], $file_list);
39
40foreach ($languages as $language)
41{
42  if (in_array($language, array($page['ref_compare'], $page['ref_default_values'])))
43  {
44    continue;
45  }
46  echo '<h2>'.$language.'</h2>';
47  $metalang[$language] = load_metalang($language, $file_list);
48
49  foreach ($file_list as $file)
50  {
51    if (isset($metalang[ $language ][$file]))
52    {
53      $missing_keys = array_diff(
54        array_keys($metalang[ $page['ref_compare'] ][$file]),
55        array_keys($metalang[ $language ][$file])
56        );
57
58      $output = '';
59      foreach ($missing_keys as $key)
60      {
61        $print_key = str_replace("'", '\\\'', $key);
62        $print_value = str_replace("'", '\\\'', $metalang[ $page['ref_default_values'] ][$file][$key]);
63        $output.= '$'."lang['".$print_key."'] = '".$print_value."';\n";
64      }
65
66      if ('' != $output)
67      {
68        echo '<h3>'.$file.'.lang.php</h3>';
69        echo '<textarea style="width:100%;height:150px;">'.$output.'</textarea>';
70      }
71    }
72    else
73    {
74      echo '<h3>'.$file.'.lang.php is missing</h3>';
75    }
76  }
77}
78
79function load_metalang($language, $file_list)
80{
81  global $lang, $user;
82 
83  $metalang = array();
84  foreach ($file_list as $file)
85  {
86    $lang = array();
87    $user['language'] = $language;
88    if (load_language($file.'.lang', '', array('language'=>$language, 'no_fallback'=>true)))
89    {
90      $metalang[$file] = $lang;
91    }
92  }
93  return $metalang;
94}
95?>
Note: See TracBrowser for help on using the repository browser.