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

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

feature 1374; first version of the script to detect missing translations. It
is very basic with an ugly output. It just does the job.

File size: 3.2 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    $missing_keys = array_diff(
52      array_keys($metalang[ $page['ref_compare'] ][$file]),
53      array_keys($metalang[ $language ][$file])
54      );
55
56    $output = '';
57    foreach ($missing_keys as $key)
58    {
59      $print_key = str_replace("'", '\\\'', $key);
60      $print_value = str_replace("'", '\\\'', $metalang[ $page['ref_default_values'] ][$file][$key]);
61      $output.= '$'."lang['".$print_key."'] = '".$print_value."';\n";
62    }
63
64    if ('' != $output)
65    {
66      echo '<h3>'.$file.'.lang.php</h3>';
67      echo '<textarea style="width:100%;height:150px;">'.$output.'</textarea>';
68    }
69  }
70}
71
72function load_metalang($language, $file_list)
73{
74  global $lang;
75 
76  $metalang = array();
77  foreach ($file_list as $file)
78  {
79    $lang = array();
80    load_language($file.'.lang', '', array('language'=>$language));
81    $metalang[$file] = $lang;
82  }
83  return $metalang;
84}
85?>
Note: See TracBrowser for help on using the repository browser.