当前位置: 首页>>代码示例>>PHP>>正文


PHP I18n::domain方法代码示例

本文整理汇总了PHP中I18n::domain方法的典型用法代码示例。如果您正苦于以下问题:PHP I18n::domain方法的具体用法?PHP I18n::domain怎么用?PHP I18n::domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在I18n的用法示例。


在下文中一共展示了I18n::domain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * 
  * Initializes the php-gettext
  * Remember to load first php-gettext
  * @param string $locale
  * @param string $charset
  * @param string $domain
  */
 public static function initialize($locale = 'en_UK', $charset = 'utf-8', $domain = 'messages')
 {
     /**
      * setting the statics so later we can access them from anywhere
      */
     //we allow to choose lang from the url
     if (Core::config('i18n.allow_query_language') == 1) {
         if (Core::get('language') !== NULL) {
             $locale = Core::get('language');
         } elseif (Cookie::get('user_language') !== NULL) {
             $locale = Cookie::get('user_language');
         }
         Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
     }
     self::$lang = $locale;
     //used in i18n kohana
     self::$locale = $locale;
     self::$charset = $charset;
     self::$domain = $domain;
     //time zone set in the config
     date_default_timezone_set(Kohana::$config->load('i18n')->timezone);
     //Kohana core charset, used in the HTML templates as well
     Kohana::$charset = self::$charset;
     /**
      * In Windows LC_MESSAGES are not recognized by any reason.
      * So we check if LC_MESSAGES is defined to avoid bugs,
      * and force using gettext
      */
     if (defined('LC_MESSAGES')) {
         $locale_res = setlocale(LC_MESSAGES, self::$locale);
     } else {
         $locale_res = FALSE;
     }
     // used with a function money_format
     setlocale(LC_MONETARY, self::$locale);
     /**
      * check if gettext exists if not uses gettext dropin
      */
     if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) {
         /**
          * gettext override
          * v 1.0.11
          * https://launchpad.net/php-gettext/
          * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it.
          * PHP-gettext already does this.
          */
         require Kohana::find_file('vendor', 'php-gettext/gettext', 'inc');
         T_setlocale(LC_MESSAGES, self::$locale);
         T_bindtextdomain(self::$domain, DOCROOT . 'languages');
         T_bind_textdomain_codeset(self::$domain, self::$charset);
         T_textdomain(self::$domain);
         //force to use the gettext dropin
         self::$dropin = TRUE;
     } else {
         bindtextdomain(self::$domain, DOCROOT . 'languages');
         bind_textdomain_codeset(self::$domain, self::$charset);
         textdomain(self::$domain);
     }
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:67,代码来源:i18n.php

示例2: translate

 /**
  * Used by the translation functions in basics.php
  * Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
  *
  * @param string $singular String to translate
  * @param string $plural Plural string (if any)
  * @param string $domain Domain
  * @param string $category Category
  * @param integer $count Count
  * @return string translated strings.
  * @access public
  */
 public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null)
 {
     self::init();
     if (strpos($singular, "\r\n") !== false) {
         $singular = str_replace("\r\n", "\n", $singular);
     }
     if ($plural !== null && strpos($plural, "\r\n") !== false) {
         $plural = str_replace("\r\n", "\n", $plural);
     }
     if (is_numeric($category)) {
         self::$category = self::$__categories[$category];
     }
     $language = Configure::read('Config.language');
     if (!empty($_SESSION['Config']['language'])) {
         $language = $_SESSION['Config']['language'];
     }
     if (self::$__lang && self::$__lang !== $language || !self::$__lang) {
         self::$__lang = self::$L10n->get($language);
     }
     if (is_null($domain)) {
         $domain = 'default';
     }
     self::$domain = $domain . '_' . self::$L10n->locale;
     if (empty(self::$__domains)) {
         self::$__domains = Cache::read(self::$domain, '_cake_core_');
     }
     if (!isset(self::$__domains[self::$category][self::$__lang][$domain])) {
         self::__bindTextDomain($domain);
         self::$__cache = true;
     }
     if (!isset($count)) {
         $plurals = 0;
     } elseif (!empty(self::$__domains[self::$category][self::$__lang][$domain]["%plural-c"]) && self::$__noLocale === false) {
         $header = self::$__domains[self::$category][self::$__lang][$domain]["%plural-c"];
         $plurals = self::__pluralGuess($header, $count);
     } else {
         if ($count != 1) {
             $plurals = 1;
         } else {
             $plurals = 0;
         }
     }
     if (!empty(self::$__domains[self::$category][self::$__lang][$domain][$singular])) {
         if (($trans = self::$__domains[self::$category][self::$__lang][$domain][$singular]) || $plurals && ($trans = self::$__domains[self::$category][self::$__lang][$domain][$plural])) {
             if (is_array($trans)) {
                 if (isset($trans[$plurals])) {
                     $trans = $trans[$plurals];
                 }
             }
             if (strlen($trans)) {
                 $singular = $trans;
                 return $singular;
             }
         }
     }
     if (!empty($plurals)) {
         return $plural;
     }
     return $singular;
 }
开发者ID:robksawyer,项目名称:cakephp2x,代码行数:72,代码来源:i18n.php

示例3: setDomain

 /**
  * @param  string
  * @return void
  * @throws IllegalArgumentException if there is no such domain registered.
  */
 public static function setDomain($domain)
 {
     if (isset(self::$domains[$domain])) {
         self::$domain = self::$domains[$domain];
     } else {
         throw new IllegalArgumentException('No such domain is registered: ' . $domain);
     }
 }
开发者ID:rsms,项目名称:phpab,代码行数:13,代码来源:I18n.php


注:本文中的I18n::domain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。