Exemplo n.º 1
0
 /**
  * 
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
Arquivo: I18n.php Projeto: rsms/phpab
 /**
  * @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);
     }
 }