123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?php
- # ***** BEGIN LICENSE BLOCK *****
- # This file is part of DotClear.
- # Copyright (c) 2004 Olivier Meunier and contributors. All rights
- # reserved.
- #
- # DotClear is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # DotClear is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with DotClear; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- # ***** END LICENSE BLOCK *****
- function __($str)
- {
- return (!empty($GLOBALS['__l10n'][$str])) ? $GLOBALS['__l10n'][$str] : $str;
- }
- class l10n
- {
- function init()
- {
- $GLOBALS['__l10n'] = array();
- $GLOBALS['__l10n_files'] = array();
- }
-
- function set($file)
- {
- $lang_file = $file.'.lang';
- $po_file = $file.'.po';
- $php_file = $file.'.lang.php';
-
- if (file_exists($php_file))
- {
- require $php_file;
- }
- /*elseif (($tmp = l10n::getPoFile($po_file)) !== false)
- {
- $GLOBALS['__l10n_files'][] = $lang_file;
- $GLOBALS['__l10n'] = array_merge($GLOBALS['__l10n'],$tmp);
- }*/
- elseif (($tmp = l10n::getLangFile($lang_file)) !== false)
- {
- $GLOBALS['__l10n_files'][] = $lang_file;
- $GLOBALS['__l10n'] = array_merge($GLOBALS['__l10n'],$tmp);
- }
- else
- {
- return false;
- }
- }
-
- function getLangFile($file)
- {
- if (!file_exists($file)) {
- //trigger_error('l10n file not found',E_USER_NOTICE);
- return false;
- }
-
- $f = file($file);
- $res = array();
-
- for ($i=0; $i<count($f); $i++) {
- if (substr($f[$i],0,1) == ';' && !empty($f[$i+1])) {
- $res[trim(substr($f[$i],1))] = trim($f[$i+1]);
- $i++;
- }
- }
-
- return $res;
- }
-
- function getPoFile($file)
- {
- if (!file_exists($file)) {
- //trigger_error('l10n file not found',E_USER_NOTICE);
- return false;
- }
-
- $fc = implode('',file($file));
-
- $res = array();
-
- $matched = preg_match_all('/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+'.
- '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
- $fc, $matches);
-
- if (!$matched) {
- return false;
- }
-
- for ($i=0; $i<$matched; $i++)
- {
- $msgid = preg_replace('/\s*msgid\s*"(.*)"\s*/s','\\1',$matches[1][$i]);
- $msgstr= preg_replace('/\s*msgstr\s*"(.*)"\s*/s','\\1',$matches[4][$i]);
- $res[l10n::poString($msgid)] = l10n::poString($msgstr);
- }
-
- if (!empty($res[''])) {
- $meta = $res[''];
- unset($res['']);
- }
-
- return $res;
- }
-
- function poString($string,$reverse=false)
- {
- if ($reverse) {
- $smap = array('"', "\n", "\t", "\r");
- $rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
- return (string) str_replace($smap, $rmap, $string);
- } else {
- $smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\"/');
- $rmap = array('', "\n", "\r", "\t", '"');
- return (string) preg_replace($smap, $rmap, $string);
- }
- }
-
- function lang2po($file)
- {
- $map = l10n::getLangFile($file);
-
- if ($map === false) {
- return false;
- }
-
- $res = '';
-
- foreach ($map as $k => $v)
- {
- $res .= "\n".'msgid "'.l10n::poString($k,true).'"'."\n";
- $res .= 'msgstr "'.l10n::poString($v,true).'"'."\n";
- }
-
- return $res;
- }
-
- function getHtmlFile($dir,$file,$lang,$encoding)
- {
- if ($encoding == 'UTF-8') {
- $lang .= '-utf8';
- }
-
- $f = $dir.'/'.$lang.'/'.$file;
- if (!file_exists($f)) {
- $f = $dir.'/en/'.$file;
- }
-
- if (!file_exists($f)) {
- return '<p>No file.</p>';
- } else {
- return implode('',file($f));
- }
- }
-
- function getISOcodes($flip=false)
- {
- $res = array(
- 'aa' => 'Afar',
- 'ab' => 'Abkhazian',
- 'af' => 'Afrikaans',
- 'am' => 'Amharic',
- 'ar' => 'Arabic',
- 'as' => 'Assamese',
- 'ay' => 'Aymara',
- 'az' => 'Azerbaijani',
- 'ba' => 'Bashkir',
- 'be' => 'Byelorussian',
- 'bg' => 'Bulgarian',
- 'bh' => 'Bihari',
- 'bi' => 'Bislama',
- 'bn' => 'Bengali',
- 'bo' => 'Tibetan',
- 'br' => 'Breton',
- 'ca' => 'Catalan',
- 'co' => 'Corsican',
- 'cs' => 'Czech',
- 'cy' => 'Welsh',
- 'da' => 'Danish',
- 'de' => 'German',
- 'dz' => 'Bhutani',
- 'el' => 'Greek',
- 'en' => 'English',
- 'eo' => 'Esperanto',
- 'es' => 'Spanish',
- 'et' => 'Estonian',
- 'eu' => 'Basque',
- 'fa' => 'Persian',
- 'fi' => 'Finnish',
- 'fj' => 'Fiji',
- 'fo' => 'Faeroese',
- 'fr' => 'French',
- 'fy' => 'Frisian',
- 'ga' => 'Irish',
- 'gd' => 'Gaelic',
- 'gl' => 'Galician',
- 'gn' => 'Guarani',
- 'gu' => 'Gujarati',
- 'ha' => 'Hausa',
- 'hi' => 'Hindi',
- 'hr' => 'Croatian',
- 'hu' => 'Hungarian',
- 'hy' => 'Armenian',
- 'ia' => 'Interlingua',
- 'ie' => 'Interlingue',
- 'ik' => 'Inupiak',
- 'in' => 'Indonesian',
- 'is' => 'Icelandic',
- 'it' => 'Italian',
- 'iw' => 'Hebrew',
- 'ja' => 'Japanese',
- 'ji' => 'Yiddish',
- 'jw' => 'Javanese',
- 'ka' => 'Georgian',
- 'kk' => 'Kazakh',
- 'kl' => 'Greenlandic',
- 'km' => 'Cambodian',
- 'kn' => 'Kannada',
- 'ko' => 'Korean',
- 'ks' => 'Kashmiri',
- 'ku' => 'Kurdish',
- 'ky' => 'Kirghiz',
- 'la' => 'Latin',
- 'ln' => 'Lingala',
- 'lo' => 'Laothian',
- 'lt' => 'Lithuanian',
- 'lv' => 'Latvian',
- 'mg' => 'Malagasy',
- 'mi' => 'Maori',
- 'mk' => 'Macedonian',
- 'ml' => 'Malayalam',
- 'mn' => 'Mongolian',
- 'mo' => 'Moldavian',
- 'mr' => 'Marathi',
- 'ms' => 'Malay',
- 'mt' => 'Maltese',
- 'my' => 'Burmese',
- 'na' => 'Nauru',
- 'ne' => 'Nepali',
- 'nl' => 'Dutch',
- 'no' => 'Norwegian',
- 'oc' => 'Occitan',
- 'om' => 'Oromo',
- 'or' => 'Oriya',
- 'pa' => 'Punjabi',
- 'pl' => 'Polish',
- 'ps' => 'Pashto',
- 'pt' => 'Portuguese',
- 'qu' => 'Quechua',
- 'rm' => 'Rhaeto-Romance',
- 'rn' => 'Kirundi',
- 'ro' => 'Romanian',
- 'ru' => 'Russian',
- 'rw' => 'Kinyarwanda',
- 'sa' => 'Sanskrit',
- 'sd' => 'Sindhi',
- 'sg' => 'Sangro',
- 'sh' => 'Serbo-Croatian',
- 'si' => 'Singhalese',
- 'sk' => 'Slovak',
- 'sl' => 'Slovenian',
- 'sm' => 'Samoan',
- 'sn' => 'Shona',
- 'so' => 'Somali',
- 'sq' => 'Albanian',
- 'sr' => 'Serbian',
- 'ss' => 'Siswati',
- 'st' => 'Sesotho',
- 'su' => 'Sudanese',
- 'sv' => 'Swedish',
- 'sw' => 'Swahili',
- 'ta' => 'Tamil',
- 'te' => 'Tegulu',
- 'tg' => 'Tajik',
- 'th' => 'Thai',
- 'ti' => 'Tigrinya',
- 'tk' => 'Turkmen',
- 'tl' => 'Tagalog',
- 'tn' => 'Setswana',
- 'to' => 'Tonga',
- 'tr' => 'Turkish',
- 'ts' => 'Tsonga',
- 'tt' => 'Tatar',
- 'tw' => 'Twi',
- 'uk' => 'Ukrainian',
- 'ur' => 'Urdu',
- 'uz' => 'Uzbek',
- 'vi' => 'Vietnamese',
- 'vo' => 'Volapuk',
- 'wo' => 'Wolof',
- 'xh' => 'Xhosa',
- 'yo' => 'Yoruba',
- 'zh' => 'Chinese',
- 'zu' => 'Zulu'
- );
-
- if ($flip) {
- $res = array_flip($res);
- ksort($res);
- }
-
- return $res;
- }
- }
- ?>
|