コード例 #1
0
ファイル: Translate.php プロジェクト: jasmun/Noco100
 /**
  * Translate a message
  * You can give multiple params or an array of params.
  * If you want to output another locale just set it as last single parameter
  * Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
  * Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
  *
  * @param  string $messageid Id of the message to be translated
  * @return string|IfwPsn_Vendor_Zend_View_Helper_Translate Translated message
  */
 public function translate($messageid = null)
 {
     if ($messageid === null) {
         return $this;
     }
     $translate = $this->getTranslator();
     $options = func_get_args();
     array_shift($options);
     $count = count($options);
     $locale = null;
     if ($count > 0) {
         if (IfwPsn_Vendor_Zend_Locale::isLocale($options[$count - 1], null, false) !== false) {
             $locale = array_pop($options);
         }
     }
     if (count($options) === 1 and is_array($options[0]) === true) {
         $options = $options[0];
     }
     if ($translate !== null) {
         $messageid = $translate->translate($messageid, $locale);
     }
     if (count($options) === 0) {
         return $messageid;
     }
     return vsprintf($messageid, $options);
 }
コード例 #2
0
ファイル: Currency.php プロジェクト: jasmun/Noco100
 /**
  * Output a formatted currency
  *
  * @param  integer|float            $value    Currency value to output
  * @param  string|IfwPsn_Vendor_Zend_Locale|array $currency OPTIONAL Currency to use for
  *                                            this call
  * @return string Formatted currency
  */
 public function currency($value = null, $currency = null)
 {
     if ($value === null) {
         return $this;
     }
     if (is_string($currency) || $currency instanceof IfwPsn_Vendor_Zend_Locale) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale.php';
         if (IfwPsn_Vendor_Zend_Locale::isLocale($currency)) {
             $currency = array('locale' => $currency);
         }
     }
     if (is_string($currency)) {
         $currency = array('currency' => $currency);
     }
     if (is_array($currency)) {
         return $this->_currency->toCurrency($value, $currency);
     }
     return $this->_currency->toCurrency($value);
 }
コード例 #3
0
ファイル: Boolean.php プロジェクト: jasmun/Noco100
 /**
  * Determine the value of a localized string, and compare it to a given value
  *
  * @param  string $value
  * @param  boolean $yes
  * @param  array $locale
  * @return boolean
  */
 protected function _getLocalizedQuestion($value, $yes, $locale)
 {
     if ($yes == true) {
         $question = 'yes';
         $return = true;
     } else {
         $question = 'no';
         $return = false;
     }
     $str = IfwPsn_Vendor_Zend_Locale::getTranslation($question, 'question', $locale);
     $str = explode(':', $str);
     if (!empty($str)) {
         foreach ($str as $no) {
             if ($no == $value || strtolower($no) == strtolower($value)) {
                 return $return;
             }
         }
     }
 }
コード例 #4
0
ファイル: Date.php プロジェクト: jasmun/Noco100
 /**
  * Checks if the given date is a real date or datepart.
  * Returns false if a expected datepart is missing or a datepart exceeds its possible border.
  * But the check will only be done for the expected dateparts which are given by format.
  * If no format is given the standard dateformat for the actual locale is used.
  * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
  *
  * @param  string|array|IfwPsn_Vendor_Zend_Date $date   Date to parse for correctness
  * @param  string                 $format (Optional) Format for parsing the date string
  * @param  string|IfwPsn_Vendor_Zend_Locale     $locale (Optional) Locale for parsing date parts
  * @return boolean                True when all date parts are correct
  */
 public static function isDate($date, $format = null, $locale = null)
 {
     if (!is_string($date) && !is_numeric($date) && !$date instanceof IfwPsn_Vendor_Zend_Date && !is_array($date)) {
         return false;
     }
     if ($format !== null && $format != 'ee' && $format != 'ss' && $format != 'GG' && $format != 'MM' && $format != 'EE' && $format != 'TT' && IfwPsn_Vendor_Zend_Locale::isLocale($format, null, false)) {
         $locale = $format;
         $format = null;
     }
     $locale = IfwPsn_Vendor_Zend_Locale::findLocale($locale);
     if ($format === null) {
         $format = IfwPsn_Vendor_Zend_Locale_Format::getDateFormat($locale);
     } else {
         if (self::$_options['format_type'] == 'php' && !defined($format)) {
             $format = IfwPsn_Vendor_Zend_Locale_Format::convertPhpToIsoFormat($format);
         }
     }
     $format = self::_getLocalizedToken($format, $locale);
     if (!is_array($date)) {
         try {
             $parsed = IfwPsn_Vendor_Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
         } catch (IfwPsn_Vendor_Zend_Locale_Exception $e) {
             // Date can not be parsed
             return false;
         }
     } else {
         $parsed = $date;
     }
     if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
         // Year expected but not found
         return false;
     }
     if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
         // Month expected but not found
         return false;
     }
     if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
         // Day expected but not found
         return false;
     }
     if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
         // Hour expected but not found
         return false;
     }
     if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
         // Minute expected but not found
         return false;
     }
     if (strpos($format, 's') !== false and !isset($parsed['second'])) {
         // Second expected  but not found
         return false;
     }
     // Set not given dateparts
     if (isset($parsed['hour']) === false) {
         $parsed['hour'] = 12;
     }
     if (isset($parsed['minute']) === false) {
         $parsed['minute'] = 0;
     }
     if (isset($parsed['second']) === false) {
         $parsed['second'] = 0;
     }
     if (isset($parsed['month']) === false) {
         $parsed['month'] = 1;
     }
     if (isset($parsed['day']) === false) {
         $parsed['day'] = 1;
     }
     if (isset($parsed['year']) === false) {
         $parsed['year'] = 1970;
     }
     if (self::isYearLeapYear($parsed['year'])) {
         $parsed['year'] = 1972;
     } else {
         $parsed['year'] = 1971;
     }
     $date = new self($parsed, null, $locale);
     $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
     if ($parsed['year'] != $date->date('Y', $timestamp)) {
         // Given year differs from parsed year
         return false;
     }
     if ($parsed['month'] != $date->date('n', $timestamp)) {
         // Given month differs from parsed month
         return false;
     }
     if ($parsed['day'] != $date->date('j', $timestamp)) {
         // Given day differs from parsed day
         return false;
     }
     if ($parsed['hour'] != $date->date('G', $timestamp)) {
         // Given hour differs from parsed hour
         return false;
     }
     if ($parsed['minute'] != $date->date('i', $timestamp)) {
         // Given minute differs from parsed minute
         return false;
     }
     if ($parsed['second'] != $date->date('s', $timestamp)) {
         // Given second differs from parsed second
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: Adapter.php プロジェクト: jasmun/Noco100
 /**
  * Checks if a string is translated within the source or not
  * returns boolean
  *
  * @param  string             $messageId Translation string
  * @param  boolean            $original  (optional) Allow translation only for original language
  *                                       when true, a translation for 'en_US' would give false when it can
  *                                       be translated with 'en' only
  * @param  string|IfwPsn_Vendor_Zend_Locale $locale    (optional) Locale/Language to use, identical with locale identifier,
  *                                       see IfwPsn_Vendor_Zend_Locale for more information
  * @return boolean
  */
 public function isTranslated($messageId, $original = false, $locale = null)
 {
     if ($original !== false and $original !== true) {
         $locale = $original;
         $original = false;
     }
     if ($locale === null) {
         $locale = $this->_options['locale'];
     }
     if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, true, false)) {
         if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, false, false)) {
             // language does not exist, return original string
             return false;
         }
         $locale = new IfwPsn_Vendor_Zend_Locale($locale);
     }
     $locale = (string) $locale;
     if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
         // return original translation
         return true;
     } else {
         if (strlen($locale) != 2 and $original === false) {
             // faster than creating a new locale and separate the leading part
             $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
             if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
                 // return regionless translation (en_US -> en)
                 return true;
             }
         }
     }
     // No translation found, return original
     return false;
 }
コード例 #6
0
ファイル: Format.php プロジェクト: jasmun/Noco100
 /**
  * Internal function for checking the options array of proper input values
  * See {@link setOptions()} for details.
  *
  * @param  array  $options  Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false,
  *                          locale = IfwPsn_Vendor_Zend_Locale | locale string, precision = whole number between -1 and 30
  * @throws IfwPsn_Vendor_Zend_Locale_Exception
  * @return Options array if no option was given
  */
 private static function _checkOptions(array $options = array())
 {
     if (count($options) == 0) {
         return self::$_options;
     }
     foreach ($options as $name => $value) {
         $name = strtolower($name);
         if ($name !== 'locale') {
             if (gettype($value) === 'string') {
                 $value = strtolower($value);
             }
         }
         switch ($name) {
             case 'number_format':
                 if ($value == IfwPsn_Vendor_Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['number_format'] = IfwPsn_Vendor_Zend_Locale_Data::getContent($locale, 'decimalnumber');
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                         $stringValue = (string) (is_array($value) ? implode(' ', $value) : $value);
                         throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " . "Format '{$stringValue}' must be a valid number format string.");
                     }
                 }
                 break;
             case 'date_format':
                 if ($value == IfwPsn_Vendor_Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['date_format'] = IfwPsn_Vendor_Zend_Locale_Format::getDateFormat($locale);
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                         $stringValue = (string) (is_array($value) ? implode(' ', $value) : $value);
                         throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$stringValue}' must be a valid ISO or PHP date format string.");
                     } else {
                         if (isset($options['format_type']) === true and $options['format_type'] == 'php' or isset($options['format_type']) === false and self::$_options['format_type'] == 'php') {
                             $options['date_format'] = IfwPsn_Vendor_Zend_Locale_Format::convertPhpToIsoFormat($value);
                         }
                     }
                 }
                 break;
             case 'format_type':
                 if ($value != 'php' && $value != 'iso') {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported.");
                 }
                 break;
             case 'fix_date':
                 if ($value !== true && $value !== false) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("Enabling correction of dates must be either true or false" . "(fix_date='{$value}').");
                 }
                 break;
             case 'locale':
                 $options['locale'] = IfwPsn_Vendor_Zend_Locale::findLocale($value);
                 break;
             case 'cache':
                 if ($value instanceof IfwPsn_Vendor_Zend_Cache_Core) {
                     IfwPsn_Vendor_Zend_Locale_Data::setCache($value);
                 }
                 break;
             case 'disablecache':
                 IfwPsn_Vendor_Zend_Locale_Data::disableCache($value);
                 break;
             case 'precision':
                 if ($value === NULL) {
                     $value = -1;
                 }
                 if ($value < -1 || $value > 30) {
                     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                     throw new IfwPsn_Vendor_Zend_Locale_Exception("'{$value}' precision is not a whole number less than 30.");
                 }
                 break;
             default:
                 require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php';
                 throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown option: '{$name}' = '{$value}'");
                 break;
         }
     }
     return $options;
 }
コード例 #7
0
ファイル: Locale.php プロジェクト: jasmun/Noco100
 /**
  * Search the locale automatically and return all used locales
  * ordered by quality
  *
  * Standard Searchorder is Browser, Environment, Default
  *
  * @param  string  $searchorder (Optional) Searchorder
  * @return array Returns an array of all detected locales
  */
 public static function getOrder($order = null)
 {
     switch ($order) {
         case self::ENVIRONMENT:
             self::$_breakChain = true;
             $languages = self::getEnvironment() + self::getBrowser() + self::getDefault();
             break;
         case self::ZFDEFAULT:
             self::$_breakChain = true;
             $languages = self::getDefault() + self::getEnvironment() + self::getBrowser();
             break;
         default:
             self::$_breakChain = true;
             $languages = self::getBrowser() + self::getEnvironment() + self::getDefault();
             break;
     }
     return $languages;
 }
コード例 #8
0
ファイル: Data.php プロジェクト: jasmun/Noco100
 /**
  * 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;
 }
コード例 #9
0
ファイル: Tmx.php プロジェクト: jasmun/Noco100
 /**
  * Internal method, called by xml element handler at start
  *
  * @param resource $file   File handler
  * @param string   $name   Elements name
  * @param array    $attrib Attributes for this element
  */
 protected function _startElement($file, $name, $attrib)
 {
     if ($this->_seg !== null) {
         $this->_content .= "<" . $name;
         foreach ($attrib as $key => $value) {
             $this->_content .= " {$key}=\"{$value}\"";
         }
         $this->_content .= ">";
     } else {
         switch (strtolower($name)) {
             case 'header':
                 if (empty($this->_useId) && isset($attrib['srclang'])) {
                     if (IfwPsn_Vendor_Zend_Locale::isLocale($attrib['srclang'])) {
                         $this->_srclang = IfwPsn_Vendor_Zend_Locale::findLocale($attrib['srclang']);
                     } else {
                         if (!$this->_options['disableNotices']) {
                             if ($this->_options['log']) {
                                 $this->_options['log']->notice("The language '{$attrib['srclang']}' can not be set because it does not exist.");
                             } else {
                                 trigger_error("The language '{$attrib['srclang']}' can not be set because it does not exist.", E_USER_NOTICE);
                             }
                         }
                         $this->_srclang = $attrib['srclang'];
                     }
                 }
                 break;
             case 'tu':
                 if (isset($attrib['tuid'])) {
                     $this->_tu = $attrib['tuid'];
                 }
                 break;
             case 'tuv':
                 if (isset($attrib['xml:lang'])) {
                     if (IfwPsn_Vendor_Zend_Locale::isLocale($attrib['xml:lang'])) {
                         $this->_tuv = IfwPsn_Vendor_Zend_Locale::findLocale($attrib['xml:lang']);
                     } else {
                         if (!$this->_options['disableNotices']) {
                             if ($this->_options['log']) {
                                 $this->_options['log']->notice("The language '{$attrib['xml:lang']}' can not be set because it does not exist.");
                             } else {
                                 trigger_error("The language '{$attrib['xml:lang']}' can not be set because it does not exist.", E_USER_NOTICE);
                             }
                         }
                         $this->_tuv = $attrib['xml:lang'];
                     }
                     if (!isset($this->_data[$this->_tuv])) {
                         $this->_data[$this->_tuv] = array();
                     }
                 }
                 break;
             case 'seg':
                 $this->_seg = true;
                 $this->_content = null;
                 break;
             default:
                 break;
         }
     }
 }
コード例 #10
0
ファイル: Locale.php プロジェクト: jasmun/Noco100
 /**
  * Set the cache
  *
  * @param string|IfwPsn_Vendor_Zend_Cache_Core $cache
  * @return IfwPsn_Vendor_Zend_Application_Resource_Locale
  */
 public function setCache($cache)
 {
     if (is_string($cache)) {
         $bootstrap = $this->getBootstrap();
         if ($bootstrap instanceof IfwPsn_Vendor_Zend_Application_Bootstrap_ResourceBootstrapper && $bootstrap->hasPluginResource('CacheManager')) {
             $cacheManager = $bootstrap->bootstrap('CacheManager')->getResource('CacheManager');
             if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
                 $cache = $cacheManager->getCache($cache);
             }
         }
     }
     if ($cache instanceof IfwPsn_Vendor_Zend_Cache_Core) {
         IfwPsn_Vendor_Zend_Locale::setCache($cache);
     }
     return $this;
 }
コード例 #11
0
ファイル: Float.php プロジェクト: jasmun/Noco100
 /**
  * Sets the locale to use
  *
  * @param string|IfwPsn_Vendor_Zend_Locale $locale
  */
 public function setLocale($locale = null)
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale.php';
     $this->_locale = IfwPsn_Vendor_Zend_Locale::findLocale($locale);
     return $this;
 }
コード例 #12
0
ファイル: PostCode.php プロジェクト: jasmun/Noco100
 /**
  * Sets the locale to use
  *
  * @param string|IfwPsn_Vendor_Zend_Locale $locale
  * @throws IfwPsn_Vendor_Zend_Validate_Exception On unrecognised region
  * @throws IfwPsn_Vendor_Zend_Validate_Exception On not detected format
  * @return IfwPsn_Vendor_Zend_Validate_PostCode  Provides fluid interface
  */
 public function setLocale($locale = null)
 {
     require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale.php';
     $this->_locale = IfwPsn_Vendor_Zend_Locale::findLocale($locale);
     $locale = new IfwPsn_Vendor_Zend_Locale($this->_locale);
     $region = $locale->getRegion();
     if (empty($region)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php';
         throw new IfwPsn_Vendor_Zend_Validate_Exception("Unable to detect a region for the locale '{$locale}'");
     }
     $format = IfwPsn_Vendor_Zend_Locale::getTranslation($locale->getRegion(), 'postaltoterritory', $this->_locale);
     if (empty($format)) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php';
         throw new IfwPsn_Vendor_Zend_Validate_Exception("Unable to detect a postcode format for the region '{$locale->getRegion()}'");
     }
     $this->setFormat($format);
     return $this;
 }
コード例 #13
0
ファイル: Iban.php プロジェクト: jasmun/Noco100
 /**
  * Sets the locale option
  *
  * @param  string|IfwPsn_Vendor_Zend_Locale $locale
  * @return IfwPsn_Vendor_Zend_Validate_Date provides a fluent interface
  */
 public function setLocale($locale = null)
 {
     if ($locale !== false) {
         require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale.php';
         $locale = IfwPsn_Vendor_Zend_Locale::findLocale($locale);
         if (strlen($locale) < 4) {
             require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php';
             throw new IfwPsn_Vendor_Zend_Validate_Exception('Region must be given for IBAN validation');
         }
     }
     $this->_locale = $locale;
     return $this;
 }