/** * Internal function for adding translation data * * This may be a new language or additional data for an existing language * If the options 'clear' is true, then the translation data for the specified * language is replaced and added otherwise * * @see IfwPsn_Vendor_Zend_Locale * @param array|IfwPsn_Vendor_Zend_Config $content Translation data to add * @throws IfwPsn_Vendor_Zend_Translate_Exception * @return IfwPsn_Vendor_Zend_Translate_Adapter Provides fluent interface */ private function _addTranslationData($options = array()) { if ($options instanceof IfwPsn_Vendor_Zend_Config) { $options = $options->toArray(); } else { if (func_num_args() > 1) { $args = func_get_args(); $options['content'] = array_shift($args); if (!empty($args)) { $options['locale'] = array_shift($args); } if (!empty($args)) { $options += array_shift($args); } } } if ($options['content'] instanceof IfwPsn_Vendor_Zend_Translate || $options['content'] instanceof IfwPsn_Vendor_Zend_Translate_Adapter) { $options['usetranslateadapter'] = true; if (!empty($options['locale']) && $options['locale'] !== 'auto') { $options['content'] = $options['content']->getMessages($options['locale']); } else { $content = $options['content']; $locales = $content->getList(); foreach ($locales as $locale) { $options['locale'] = $locale; $options['content'] = $content->getMessages($locale); $this->_addTranslationData($options); } return $this; } } try { $options['locale'] = IfwPsn_Vendor_Zend_Locale::findLocale($options['locale']); } catch (IfwPsn_Vendor_Zend_Locale_Exception $e) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Translate/Exception.php'; throw new IfwPsn_Vendor_Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e); } if ($options['clear'] || !isset($this->_translate[$options['locale']])) { $this->_translate[$options['locale']] = array(); } $read = true; if (isset(self::$_cache)) { $id = 'IfwPsn_Vendor_Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); $temp = self::$_cache->load($id); if ($temp) { $read = false; } } if ($options['reload']) { $read = true; } if ($read) { if (!empty($options['usetranslateadapter'])) { $temp = array($options['locale'] => $options['content']); } else { $temp = $this->_loadTranslationData($options['content'], $options['locale'], $options); } } if (empty($temp)) { $temp = array(); } $keys = array_keys($temp); foreach ($keys as $key) { if (!isset($this->_translate[$key])) { $this->_translate[$key] = array(); } if (array_key_exists($key, $temp) && is_array($temp[$key])) { $this->_translate[$key] = $temp[$key] + $this->_translate[$key]; } } if ($this->_automatic === true) { $find = new IfwPsn_Vendor_Zend_Locale($options['locale']); $browser = $find->getEnvironment() + $find->getBrowser(); arsort($browser); foreach ($browser as $language => $quality) { if (isset($this->_translate[$language])) { $this->_options['locale'] = $language; break; } } } if ($read and isset(self::$_cache)) { $id = 'IfwPsn_Vendor_Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); if (self::$_cacheTags) { self::$_cache->save($temp, $id, array($this->_options['tag'])); } else { self::$_cache->save($temp, $id); } } return $this; }
/** * Read the LDML file, get a single path defined value * * @param string $locale * @param string $path * @param string $value * @return string * @access public */ public static function getContent($locale, $path, $value = false) { $locale = self::_checkLocale($locale); if (!isset(self::$_cache) && !self::$_cacheDisabled) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Cache.php'; self::$_cache = IfwPsn_Vendor_Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true), array()); } $val = $value; if (is_array($value)) { $val = implode('_', $value); } $val = urlencode($val); $id = strtr('IfwPsn_Vendor_Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_')); if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { return unserialize($result); } switch (strtolower($path)) { case 'language': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type'); break; case 'script': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type'); break; case 'country': case 'territory': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type'); break; case 'variant': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type'); break; case 'key': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type'); break; case 'defaultcalendar': $givenLocale = new IfwPsn_Vendor_Zend_Locale($locale); $territory = $givenLocale->getRegion(); unset($givenLocale); $temp = self::_getFile('supplementalData', '/supplementalData/calendarPreferenceData/calendarPreference[contains(@territories,\'' . $territory . '\')]', 'ordering', 'ordering'); if (isset($temp['ordering'])) { list($temp) = explode(' ', $temp['ordering']); } else { $temp = 'gregorian'; } break; case 'monthcontext': /* default context is always 'format' if (empty ($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context'); */ $temp = 'format'; break; case 'defaultmonth': /* default width is always 'wide' if (empty ($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default'); */ $temp = 'wide'; break; case 'month': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month[@type=\'' . $value[3] . '\']', 'type'); break; case 'daycontext': /* default context is always 'format' if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context'); */ $temp = 'format'; break; case 'defaultday': /* default width is always 'wide' if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default'); */ $temp = 'wide'; break; case 'day': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day[@type=\'' . $value[3] . '\']', 'type'); break; case 'quarter': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter[@type=\'' . $value[3] . '\']', 'type'); break; case 'am': if (empty($value)) { $value = array("gregorian", "format", "wide"); } if (!is_array($value)) { $temp = $value; $value = array($temp, "format", "wide"); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'am\']', '', 'dayPeriod'); break; case 'pm': if (empty($value)) { $value = array("gregorian", "format", "wide"); } if (!is_array($value)) { $temp = $value; $value = array($temp, "format", "wide"); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'pm\']', '', 'dayPeriod'); break; case 'era': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "Abbr", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type'); break; case 'defaultdate': /* default choice is deprecated in CDLR - should be always medium here if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default'); */ $temp = 'medium'; break; case 'date': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); break; case 'defaulttime': /* default choice is deprecated in CDLR - should be always medium here if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default'); */ $temp = 'medium'; break; case 'time': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); break; case 'datetime': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $date = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); $time = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); $datetime = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'' . $value[1] . '\']/dateTimeFormat/pattern', '', 'pattern'); $temp = str_replace(array('{0}', '{1}'), array(current($time), current($date)), current($datetime)); break; case 'dateitem': if (empty($value)) { $value = array("gregorian", "yyMMdd"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/availableFormats/dateFormatItem[@id=\'' . $value[1] . '\']', ''); break; case 'dateinterval': if (empty($value)) { $value = array("gregorian", "yMd", "y"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp, $temp[0]); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\'' . $value[1] . '\']/greatestDifference[@id=\'' . $value[2] . '\']', ''); break; case 'field': if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]); break; case 'relative': if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'day\']/relative[@type=\'' . $value[1] . '\']', '', $value[1]); // $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]); break; case 'defaultnumberingsystem': $temp = self::_getFile($locale, '/ldml/numbers/defaultNumberingSystem', '', 'default'); break; case 'decimalnumber': $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default'); break; case 'scientificnumber': $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default'); break; case 'percentnumber': $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default'); break; case 'currencynumber': $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default'); break; case 'nametocurrency': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); break; case 'currencytoname': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); $temp = array(); foreach ($_temp as $key => $keyvalue) { $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key); if (!isset($val[$key]) or $val[$key] != $value) { continue; } if (!isset($temp[$val[$key]])) { $temp[$val[$key]] = $key; } else { $temp[$val[$key]] .= " " . $key; } } break; case 'currencysymbol': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value); break; case 'question': $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value); break; case 'currencyfraction': if (empty($value)) { $value = "DEFAULT"; } $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits'); break; case 'currencyrounding': if (empty($value)) { $value = "DEFAULT"; } $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding'); break; case 'currencytoregion': $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value); break; case 'regiontocurrency': $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166'); $temp = array(); foreach ($_temp as $key => $keyvalue) { $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key); if (!isset($val[$key]) or $val[$key] != $value) { continue; } if (!isset($temp[$val[$key]])) { $temp[$val[$key]] = $key; } else { $temp[$val[$key]] .= " " . $key; } } break; case 'regiontoterritory': $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value); break; case 'territorytoregion': $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'scripttolanguage': $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value); break; case 'languagetoscript': $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'territorytolanguage': $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value); break; case 'languagetoterritory': $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'timezonetowindows': $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@other=\'' . $value . '\']', 'type', $value); break; case 'windowstotimezone': $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@type=\'' . $value . '\']', 'other', $value); break; case 'territorytotimezone': $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@type=\'' . $value . '\']', 'territory', $value); break; case 'timezonetoterritory': $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@territory=\'' . $value . '\']', 'type', $value); break; case 'citytotimezone': $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value); break; case 'timezonetocity': $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type'); $temp = array(); foreach ($_temp as $key => $found) { $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key); if (!empty($temp[$key])) { if ($temp[$key] == $value) { $temp[$temp[$key]] = $key; } } unset($temp[$key]); } break; case 'phonetoterritory': $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value); break; case 'territorytophone': $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'numerictoterritory': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $value . '\']', 'numeric', $value); break; case 'territorytonumeric': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $value . '\']', 'type', $value); break; case 'alpha3toterritory': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $value . '\']', 'alpha3', $value); break; case 'territorytoalpha3': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $value . '\']', 'type', $value); break; case 'postaltoterritory': $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId'); break; case 'numberingsystem': $temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . strtolower($value) . '\']', 'digits', $value); break; case 'chartofallback': $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value'); foreach ($_temp as $key => $keyvalue) { $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key); if (current($temp2) == $value) { $temp = $key; } } break; $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '', $value); break; case 'fallbacktochar': $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', ''); break; case 'localeupgrade': $temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $value . '\']', 'to', $value); break; case 'unit': $temp = self::_getFile($locale, '/ldml/units/unitLength/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', ''); break; default: require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php'; throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown detail ({$path}) for parsing locale data."); break; } if (is_array($temp)) { $temp = current($temp); } if (isset(self::$_cache)) { if (self::$_cacheTags) { self::$_cache->save(serialize($temp), $id, array('IfwPsn_Vendor_Zend_Locale')); } else { self::$_cache->save(serialize($temp), $id); } } return $temp; }