| 29 |
function mamboLanguage($lang, $path = null) { |
function mamboLanguage($lang, $path = null) { |
| 30 |
$this->name = $lang; |
$this->name = $lang; |
| 31 |
$this->path = $path; |
$this->path = $path; |
| 32 |
if (is_null($this->path)) $this->path = realpath('../language/') . DIRECTORY_SEPARATOR; |
if (is_null($this->path)) $this->path = mamboCore::get('rootPath').'/language/'; |
| 33 |
$this->load(); |
$this->load(); |
| 34 |
} |
} |
| 35 |
function &getInstance($lang, $path = null) { |
|
|
static $languages; |
|
|
if (!isset($languages[$lang]) || is_null($languages[$lang])) { |
|
|
$lobj = new mamboLanguage($lang, $path); |
|
|
$languages[$lang] = $lobj; |
|
|
} |
|
|
return $languages[$lang]; |
|
|
} |
|
| 36 |
function getFileName() { |
function getFileName() { |
| 37 |
$file = $this->iso639; |
$file = $this->iso639; |
| 38 |
$file .= strlen($this->iso3166_2) == 2 ? '_' . $this->iso3166_2 : ''; |
$file .= strlen($this->iso3166_2) == 2 ? '_' . $this->iso3166_2 : ''; |
| 47 |
} |
} |
| 48 |
function save() { |
function save() { |
| 49 |
$this->updateFiles(); |
$this->updateFiles(); |
| 50 |
|
|
| 51 |
|
$xml = $this->toXML(); |
| 52 |
|
|
| 53 |
|
if (strtolower($this->charset) != 'utf-8') { |
| 54 |
|
if (function_exists('iconv')) { |
| 55 |
|
$xml = iconv("utf-8", $this->charset, $xml); |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
/**/ |
| 59 |
$fp = fopen($this->path . $this->getFileName() . '.xml', 'w+'); |
$fp = fopen($this->path . $this->getFileName() . '.xml', 'w+'); |
| 60 |
fwrite($fp, $this->toXML()); |
fwrite($fp, $xml); |
| 61 |
fclose($fp); |
fclose($fp); |
| 62 |
} |
} |
| 63 |
|
|
| 66 |
foreach($langfiles as $xml) { |
foreach($langfiles as $xml) { |
| 67 |
$xml = str_replace($this->path, '', $xml); |
$xml = str_replace($this->path, '', $xml); |
| 68 |
if (substr($xml, 0, -4) != 'locales') { |
if (substr($xml, 0, -4) != 'locales') { |
| 69 |
$lobj = &mamboLanguage::getInstance(substr($xml, 0, -4), $this->path) ; |
$lobj = &new mamboLanguage(substr($xml, 0, -4), $this->path) ; |
| 70 |
$langs[$lobj->name] = $lobj; |
$langs[$lobj->name] = $lobj; |
| 71 |
} |
} |
| 72 |
} |
} |
| 92 |
|
|
| 93 |
function load($load_catalogs = false) { |
function load($load_catalogs = false) { |
| 94 |
if (is_readable($this->path . $this->name . ".xml")) { |
if (is_readable($this->path . $this->name . ".xml")) { |
| 95 |
$p = xml_parser_create(); |
|
| 96 |
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); |
$source = file_get_contents($this->path . $this->name . ".xml"); |
| 97 |
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); |
if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
| 98 |
xml_parse_into_struct($p, implode("", file($this->path . $this->name . ".xml")), $values); |
$encoding = strtoupper($m[1]); |
| 99 |
xml_parser_free($p); |
} else { |
| 100 |
|
$encoding = "UTF-8"; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
if($encoding == "UTF-8" || $encoding == "US-ASCII" || $encoding == "ISO-8859-1") { |
| 104 |
|
$parser = xml_parser_create($encoding); |
| 105 |
|
} else { |
| 106 |
|
|
| 107 |
|
#if(function_exists('mb_convert_encoding')) { |
| 108 |
|
$encoded_source = iconv($encoding, "UTF-8", $source); |
| 109 |
|
# } |
| 110 |
|
|
| 111 |
|
if($encoded_source != NULL) { |
| 112 |
|
$source = str_replace ( $m[0],'<?xml version="1.0" encoding="utf-8"?>', $encoded_source); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
$parser = xml_parser_create("UTF-8"); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); |
| 119 |
|
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
| 120 |
|
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
| 121 |
|
if (!xml_parse_into_struct($parser, implode("", file($this->path . $this->name . ".xml")), $values)) { |
| 122 |
|
die(sprintf("XML error: %s at ".$this->path . $this->name.".xml in line %d", |
| 123 |
|
xml_error_string(xml_get_error_code($parser)), |
| 124 |
|
xml_get_current_line_number($parser))); |
| 125 |
|
} |
| 126 |
|
xml_parser_free($parser); |
| 127 |
|
|
| 128 |
|
|
| 129 |
foreach($values as $key => $value) { |
foreach($values as $key => $value) { |
| 130 |
$tag = strtolower($value['tag']); |
$tag = strtolower($value['tag']); |
| 131 |
switch ($tag) { |
switch ($tag) { |
| 174 |
break; |
break; |
| 175 |
} |
} |
| 176 |
} |
} |
| 177 |
|
$this->codesets = array_unique($this->codesets); |
| 178 |
|
|
| 179 |
return true; |
return true; |
| 180 |
} |
} |
| 181 |
return false; |
return false; |
| 182 |
} |
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
function updateFiles() { |
function updateFiles() { |
| 188 |
$dir = $this->path . $this->name . '/'; |
$dir = $this->path . $this->name . '/'; |
| 189 |
$langfiles = mosReadDirectory($dir, '.po$'); |
$langfiles = mosReadDirectory($dir, '.po$'); |
| 203 |
$file['fuzzy'] = 0; |
$file['fuzzy'] = 0; |
| 204 |
$pluralfuzz = false; |
$pluralfuzz = false; |
| 205 |
foreach ($catalog->strings as $msg) { |
foreach ($catalog->strings as $msg) { |
| 206 |
|
if (is_array($msg->msgstr)) { |
| 207 |
|
foreach ($msg->msgstr as $i) { |
| 208 |
|
$unt = empty($i); |
| 209 |
|
} |
| 210 |
|
if (!$unt) { |
| 211 |
|
$file['translated']++; |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
if (!is_array($msg->msgstr) && !empty($msg->msgstr) && !$msg->is_fuzzy) { |
if (!is_array($msg->msgstr) && !empty($msg->msgstr) && !$msg->is_fuzzy) { |
| 215 |
$file['translated']++; |
$file['translated']++; |
| 216 |
} |
} |
| 301 |
} |
} |
| 302 |
return $xml; |
return $xml; |
| 303 |
} |
} |
|
} |
|
| 304 |
|
|
| 305 |
function getlocales() { |
function getLocales() { |
| 306 |
$xmlfile = "../language/locales.xml"; |
$xmlfile = "../language/locales.xml"; |
| 307 |
$p = xml_parser_create(); |
$p = xml_parser_create(); |
| 308 |
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); |
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); |
| 356 |
$locales['plural_forms'] = $plural_forms; |
$locales['plural_forms'] = $plural_forms; |
| 357 |
return $locales; |
return $locales; |
| 358 |
} |
} |
| 359 |
|
} |
| 360 |
|
|
| 361 |
|
function getlocales() { |
| 362 |
|
return mamboLanguage::getLocales(); |
| 363 |
|
} |
| 364 |
?> |
?> |