3 * Part of Text_LanguageDetect
8 * @package Text_LanguageDetect
9 * @author Christian Weiske <cweiske@php.net>
10 * @copyright 2011 Christian Weiske <cweiske@php.net>
11 * @license http://www.debian.org/misc/bsd.license BSD
13 * @link http://pear.php.net/package/Text_LanguageDetect/
17 * Provides a mapping between the languages from lang.dat and the
18 * ISO 639-1 and ISO-639-2 codes.
20 * Note that this class contains only languages that exist in lang.dat.
23 * @package Text_LanguageDetect
24 * @author Christian Weiske <cweiske@php.net>
25 * @copyright 2011 Christian Weiske <cweiske@php.net>
26 * @license http://www.debian.org/misc/bsd.license BSD
27 * @link http://www.loc.gov/standards/iso639-2/php/code_list.php
29 class Text_LanguageDetect_ISO639
32 * Maps all language names from the language database to the
33 * ISO 639-1 2-letter language code.
35 * NULL indicates that there is no 2-letter code.
39 public static $nameToCode2 = array(
95 * Maps all language names from the language database to the
96 * ISO 639-2 3-letter language code.
100 public static $nameToCode3 = array(
105 'bulgarian' => 'bul',
120 'hungarian' => 'hun',
121 'icelandic' => 'isl',
122 'indonesian' => 'ind',
128 'lithuanian' => 'lit',
129 'macedonian' => 'mkd',
130 'mongolian' => 'mon',
132 'norwegian' => 'nor',
136 'portuguese' => 'por',
148 'ukrainian' => 'ukr',
151 'vietnamese' => 'vie',
156 * Maps ISO 639-1 2-letter language codes to the language names
157 * in the language database
159 * Not all languages have a 2 letter code, so some are missing
163 public static $code2ToName = array(
182 'id' => 'indonesian',
188 'lt' => 'lithuanian',
190 'mk' => 'macedonian',
197 'pt' => 'portuguese',
212 'vi' => 'vietnamese',
216 * Maps ISO 639-2 3-letter language codes to the language names
217 * in the language database.
221 public static $code3ToName = array(
225 'bul' => 'bulgarian',
241 'hun' => 'hungarian',
242 'ind' => 'indonesian',
243 'isl' => 'icelandic',
249 'lit' => 'lithuanian',
250 'mkd' => 'macedonian',
251 'mon' => 'mongolian',
254 'nor' => 'norwegian',
256 'por' => 'portuguese',
270 'ukr' => 'ukrainian',
273 'vie' => 'vietnamese',
277 * Returns the 2-letter ISO 639-1 code for the given language name.
279 * @param string $lang English language name like "swedish"
281 * @return string Two-letter language code (e.g. "sv") or NULL if not found
283 public static function nameToCode2($lang)
285 $lang = strtolower($lang);
286 if (!isset(self::$nameToCode2[$lang])) {
289 return self::$nameToCode2[$lang];
293 * Returns the 3-letter ISO 639-2 code for the given language name.
295 * @param string $lang English language name like "swedish"
297 * @return string Three-letter language code (e.g. "swe") or NULL if not found
299 public static function nameToCode3($lang)
301 $lang = strtolower($lang);
302 if (!isset(self::$nameToCode3[$lang])) {
305 return self::$nameToCode3[$lang];
309 * Returns the language name for the given 2-letter ISO 639-1 code.
311 * @param string $code Two-letter language code (e.g. "sv")
313 * @return string English language name like "swedish"
315 public static function code2ToName($code)
317 $lang = strtolower($code);
318 if (!isset(self::$code2ToName[$code])) {
321 return self::$code2ToName[$code];
325 * Returns the language name for the given 3-letter ISO 639-2 code.
327 * @param string $code Three-letter language code (e.g. "swe")
329 * @return string English language name like "swedish"
331 public static function code3ToName($code)
333 $lang = strtolower($code);
334 if (!isset(self::$code3ToName[$code])) {
337 return self::$code3ToName[$code];