source: extensions/AMetaData/JpegMetaData/Common/Locale.class.php @ 4698

Last change on this file since 4698 was 4698, checked in by grum, 14 years ago

[Plugin:AMetaData] Finished to comment the JpegMetaData classes and rename some methods

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1<?php
2/*
3 * --:: JPEG MetaDatas ::-------------------------------------------------------
4 *
5 *  Author    : Grum
6 *   email    : grum at piwigo.org
7 *   website  : http://photos.grum.fr
8 *
9 *   << May the Little SpaceFrog be with you ! >>
10 *
11 *
12 * +-----------------------------------------------------------------------+
13 * | JpegMetaData - a PHP based Jpeg Metadata manager                      |
14 * +-----------------------------------------------------------------------+
15 * | Copyright(C) 2010  Grum - http://www.grum.fr                          |
16 * +-----------------------------------------------------------------------+
17 * | This program is free software; you can redistribute it and/or modify  |
18 * | it under the terms of the GNU General Public License as published by  |
19 * | the Free Software Foundation                                          |
20 * |                                                                       |
21 * | This program is distributed in the hope that it will be useful, but   |
22 * | WITHOUT ANY WARRANTY; without even the implied warranty of            |
23 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
24 * | General Public License for more details.                              |
25 * |                                                                       |
26 * | You should have received a copy of the GNU General Public License     |
27 * | along with this program; if not, write to the Free Software           |
28 * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
29 * | USA.                                                                  |
30 * +-----------------------------------------------------------------------+
31 *
32 *
33 * -----------------------------------------------------------------------------
34 *
35 * The Locale class is used for tag translation, reading the .mo files
36 *
37 * There is one directory per language, the directories tree must respect this
38 * structure
39 *
40 * --\ Locale                           => main directory for languages
41 *     |
42 *     +--\ en_UK                       => language
43 *     |    |
44 *     |    +--\ LC_MESSAGES
45 *     |         |
46 *     |         +--\ Tag.mo            => names & values translations
47 *     |         +--\ TadDesc.mo        => descriptions translations
48 *     |
49 *     +--\ fr_FR
50 *          |
51 *          +--\ LC_MESSAGES
52 *               |
53 *               +--\ Tag.mo
54 *               +--\ TadDesc.mo
55 *
56 *
57 * -----------------------------------------------------------------------------
58 *
59 * .. Notes ..
60 *
61 * This class don't use the PHP gettext functions, but the php-gettext extension
62 * ==> See files in External/php-gettext for more information about this project
63 *
64 *
65 *
66 * This class provides theses public functions :
67 *  - (static) setLanguage
68 *  - (static) getLanguage
69 *  - (static) get
70 *  - (static) getDesc
71 *
72 * -----------------------------------------------------------------------------
73 */
74
75
76require_once(JPEG_METADATA_DIR."External/php-gettext/gettext.inc");
77
78/**
79 * $supported_locales is a global variable need by the php-gettext package.
80 * the array is automatically initialized with the setLanguage() function
81 */
82$supported_locales = array();
83
84/**
85 * assume a default language is set in any case...
86 */
87Locale::setLanguage();
88
89
90class Locale
91{
92  const JMD_TAG = "Tag";
93  const JMD_TAGDESC = "TagDesc";
94
95  static private $language = "";
96
97  /**
98   * This function is used to set the locale language.
99   * If no language is given, assume the default "en_UK" language
100   *
101   * If there is no translation file for the the given language, assume the
102   * default "en_UK" language
103   *
104   * @param String $language : the language
105   * @return String : the defined language
106   */
107  static function setLanguage($language="en_UK")
108  {
109    global $supported_locales;
110
111    /*
112     * Scan the Locale directory.
113     * Any directory with a sub directory "LC_MESSAGES" is considered as a
114     * supported locale language
115     */
116    $directory=scandir(JPEG_METADATA_DIR."Locale");
117    foreach($directory as $key => $file)
118    {
119      if(is_dir(JPEG_METADATA_DIR."Locale/".$file) and
120         $file!='.' and
121         $file!='..' and
122         file_exists(JPEG_METADATA_DIR."Locale/".$file."/LC_MESSAGES/Tag.mo"))
123         $supported_locales[]=$file;
124
125    }
126
127    /*
128     * if the desired language doesn't exist, apply the en_UK locale
129     * (assuming the en_UK exists and was not deleted)
130     */
131    if(!in_array($language, $supported_locales))
132      self::$language='en_UK';
133    else
134      self::$language=$language;
135
136    /*
137     * set the locale
138     */
139    T_setlocale(LC_MESSAGES, self::$language);
140
141    /*
142     * set one domain "TAG" for tags name&values, and one domaine "TAGDESC" for
143     * tags description
144     */
145    T_bindtextdomain(self::JMD_TAG, dirname(dirname(__FILE__))."/Locale");
146    T_bindtextdomain(self::JMD_TAGDESC, dirname(dirname(__FILE__))."/Locale");
147
148    return(self::$language);
149  }
150
151  /**
152   * returns the defined current language
153   *
154   * @return String
155   */
156  static function getLanguage()
157  {
158    return(self::$language);
159  }
160
161  /**
162   * returns the translation in current language for the given key
163   *
164   * @return String
165   */
166  static function get($key)
167  {
168    return(@T_dgettext(self::JMD_TAG, $key));
169  }
170
171  /**
172   * returns the description in current language for the given tagName
173   *
174   * @return String
175   */
176  static function getDesc($tagName)
177  {
178    return(@T_dgettext(self::JMD_TAGDESC, $tagName));
179  }
180
181}
182
183
184?>
Note: See TracBrowser for help on using the repository browser.