/**
 * ------------------------------------------------------------------------- *
 * This library is free software; you can redistribute it and/or             *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * This library is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with this library; if not, write to the Free Software       *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
 * ------------------------------------------------------------------------- *
 *
 * @package smarty-gettext
 * @link https://github.com/smarty-gettext/smarty-gettext/
 * @author Karlheinz Toni <*****@*****.**>
 * @author Boleslaw Tekielski <*****@*****.**>
 * @author Elan Ruusamäe <*****@*****.**>
 * @copyright 2012 Karlheinz Toni
 * @copyright 2015 Boleslaw Tekielski
 * @copyright 2015 Elan Ruusamäe
 */
function smarty_function_locale($params, &$smarty)
{
    static $stack;
    // init stack as array
    if ($stack === null) {
        $stack = array();
    }
    $path = null;
    $template_dirs = method_exists($smarty, 'getTemplateDir') ? $smarty->getTemplateDir() : $smarty->template_dir;
    $path_param = isset($params['path']) ? $params['path'] : '';
    $domain = isset($params['domain']) ? $params['domain'] : 'messages';
    $stack_operation = isset($params['stack']) ? $params['stack'] : 'push';
    foreach ((array) $template_dirs as $template_dir) {
        $path = $template_dir . $path_param;
        if (is_dir($path)) {
            break;
        }
    }
    if (!$path && $stack_operation != 'pop') {
        trigger_error("Directory for locales not found (path='{$path_param}')", E_USER_ERROR);
    }
    if ($stack_operation == 'push') {
        $stack[] = array($domain, $path);
    } elseif ($stack_operation == 'pop') {
        if (count($stack) > 1) {
            array_pop($stack);
        }
        list($domain, $path) = end($stack);
    } else {
        trigger_error("Unknown stack operation '{$stack_operation}'", E_USER_ERROR);
    }
    bind_textdomain_codeset($domain, 'UTF-8');
    bindtextdomain($domain, $path);
    textdomain($domain);
}
Esempio n. 2
0
 /**
  * Init Translation system using gettext
  *
  * @param object $locale instance of Zend_Locale
  *
  * @return void
  */
 public function iniTranslation($locale, array $availableDomains = array())
 {
     if (!$locale instanceof Zend_Locale) {
         $locale = new Zend_Locale($locale);
     }
     $localeDirPath = $this->getConfig('localeDirPath');
     // init available gettext domains
     foreach ($availableDomains as $domain) {
         bindtextdomain($domain, $localeDirPath);
         bind_textdomain_codeset($domain, 'UTF-8');
     }
     // set first domain has default domain
     $defaultDomain = array_shift($availableDomains);
     textdomain($defaultDomain);
     $localeWithEncoding = $locale . '.utf8';
     // mandatory for gettext
     if (putenv('LANGUAGE') != $locale->getLanguage()) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Could not set the ENV variable LANGUAGE = %s', $locale));
     }
     if (setlocale(LC_MESSAGES, $localeWithEncoding) !== $localeWithEncoding) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Unable to set locale "%s" to value "%s", please check installed locales on system', 'LC_MESSAGES', $localeWithEncoding));
     }
     if (setlocale(LC_TIME, $localeWithEncoding) !== $localeWithEncoding) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Unable to set locale "%s" to value "%s", please check installed locales on system', 'LC_TIME', $localeWithEncoding));
     }
     return $this;
 }
Esempio n. 3
0
File: lang.php Progetto: hardikk/HNH
 /**
  * Sets i18n locale language
  *
  * sets the language for i18n php gettext module
  * (gettext has to be enabled in the php.ini)
  *
  */
 function set()
 {
     if (extension_loaded('gettext')) {
         // try and find the default locale
         $default_lang = preg_replace('/-/', '_', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         $locale = 'en_US';
         $locale_dir = "./locale";
         $directories = getdirectories($locale_dir, "");
         foreach ($directories as $directory) {
             $buf = substr($directory, strlen($locale_dir) + 1, strlen($directory) - strlen($locale_dir));
             if (preg_match("/" . $buf . "/i", $default_lang)) {
                 $locale = $buf;
                 break;
             }
         }
         // set locale
         $language = isset($_COOKIE['ari_lang']) ? $_COOKIE['ari_lang'] : $locale;
         putenv("LANG={$language}");
         putenv("LANGUAGE={$language}");
         setlocale(LC_MESSAGES, $language);
         bindtextdomain('ari', './locale');
         bind_textdomain_codeset('ari', 'UTF-8');
         textdomain('ari');
     } else {
         function _($str)
         {
             return $str;
         }
     }
 }
function translate($lang, $test = 0)
{
    global $LOCALE_PATH;
    putenv("LANGUAGE={$lang}");
    bindtextdomain("zarafa", "{$LOCALE_PATH}");
    if (STORE_SUPPORTS_UNICODE == false) {
        bind_textdomain_codeset('zarafa', "windows-1252");
    } else {
        bind_textdomain_codeset('zarafa', "utf-8");
    }
    textdomain('zarafa');
    setlocale(LC_ALL, $lang);
    $trans_array["Sent Items"] = _("Sent Items");
    $trans_array["Outbox"] = _("Outbox");
    $trans_array["Deleted Items"] = _("Deleted Items");
    $trans_array["Inbox"] = _("Inbox");
    $trans_array["Calendar"] = _("Calendar");
    $trans_array["Contacts"] = _("Contacts");
    $trans_array["Drafts"] = _("Drafts");
    $trans_array["Journal"] = _("Journal");
    $trans_array["Notes"] = _("Notes");
    $trans_array["Tasks"] = _("Tasks");
    $trans_array["Junk E-mail"] = _("Junk E-mail");
    return $trans_array;
}
Esempio n. 5
0
 /** Set domain name.
  *
  * @param string  $dir Directory path, where to find domain. In this directory current locale named subdirectory will be searched.
  * @param string  $domain Domain name - filename without MO extension.
  * @param string  $codeset Domain file codeset.
  *
  * @return $this
  */
 public final function setDomain($dir, $domain, $codeset = 'UTF-8')
 {
     bindtextdomain($domain, $dir);
     bind_textdomain_codeset($domain, $codeset);
     $this->domains[] = $domain;
     return $this;
 }
Esempio n. 6
0
 public function setOptions($options)
 {
     if (!is_array($options)) {
         throw new \Exception('Invalid options');
     }
     if (!isset($options['locale'])) {
         throw new \Exception('Parameter "locale" is required');
     }
     if (strpos($options['locale'], '..') !== false) {
         throw new \Exception('Locale has dangerous characters');
     }
     if (!isset($options['domains'])) {
         throw new \Exception('domains must be specified and it must be an array.');
     }
     if (isset($options['compileAlways']) && $options['compileAlways'] === true) {
         $compiler = new Compiler();
         $compiler->compileLocale(['locale' => $options['locale'], 'domains' => $options['domains'], 'localeDir' => $options['localeDir'], 'localeCacheDir' => $options['localeCacheDir']]);
     }
     $codeset = 'UTF-8';
     putenv('LANG=' . $options['locale'] . '.' . $codeset);
     putenv('LANGUAGE=' . $options['locale'] . '.' . $codeset);
     setlocale(LC_ALL, $options['locale'] . '.' . $codeset);
     foreach ($options['domains'] as $domain) {
         bindtextdomain($domain, $options['localeCacheDir']);
         bind_textdomain_codeset($domain, $codeset);
     }
     $this->domains = $options['domains'];
     $this->defaultDomain = reset($options['domains']);
     textdomain($this->defaultDomain);
 }
Esempio n. 7
0
 public function __construct($lang = 'en_EN', $domain = 'default')
 {
     /* ./locale/en_EN/LC_MESSAGES/default.po */
     $fnMO = dirname(__FILE__) . '/locale/' . $lang . '/LC_MESSAGES/' . $domain . '.mo';
     if (!file_exists($fnMO)) {
         $fnPO = substr($fnMO, 0, -2) . 'po';
         if (file_exists($fnPO) && is_readable($fnPO)) {
             $this->_moConverter($fnPO);
         }
     }
     @putenv('LC_ALL=' . $lang);
     @setlocale(LC_ALL, $lang);
     if (function_exists('bindtextdomain')) {
         bindtextdomain($domain, dirname(__FILE__) . '/locale');
     }
     if (function_exists('bind_textdomain_codeset')) {
         bind_textdomain_codeset($domain, 'UTF-8');
     }
     if (function_exists('textdomain')) {
         textdomain($domain);
     }
     $this->_defaultFunction = false;
     $this->_cache = array();
     if (function_exists('gettext')) {
         $this->_defaultFunction = true;
     } else {
         $_tmp = $this->_moRead($fnMO, $lang);
         if (is_array($_tmp)) {
             $this->_cache = $_tmp[$lang];
         }
         unset($_tmp);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function bindTextDomain($textDomain, $codeSet = null)
 {
     $this->bendTextDomains[$textDomain] = array();
     $textDomainDir = bindtextdomain($textDomain, $this->directory);
     $translationFileDir = $textDomainDir . DIRECTORY_SEPARATOR . StringUtils::beforeFirst(setlocale(LC_MESSAGES, '0'), '.') . DIRECTORY_SEPARATOR . 'LC_MESSAGES';
     $moFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.mo';
     $poFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.po';
     if (file_exists($moFilePath) === true) {
         $this->bendTextDomains[$textDomain]['file_path'] = $moFilePath;
         $this->bendTextDomains[$textDomain]['type'] = 'mo';
     } elseif (file_exists($poFilePath) === true && $this->poParserInterface instanceof PoParserInterface === true) {
         $this->bendTextDomains[$textDomain]['file_path'] = $poFilePath;
         $this->bendTextDomains[$textDomain]['type'] = 'po';
         $this->bendTextDomains[$textDomain]['plural_expr'] = false;
         $this->bendTextDomains[$textDomain]['entries'] = $this->poParserInterface->extract($poFilePath);
         $this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $this->defaultPluralRule . ';';
         // Default plural rule
         $this->bendTextDomains[$textDomain]['plurals'] = 2;
         if (isset($this->bendTextDomains[$textDomain]['entries']['']) === true) {
             foreach ($this->bendTextDomains[$textDomain]['entries']['']['msgstr'] as $meta) {
                 if (preg_match('/Plural-Forms:\\s+nplurals=(\\d+);\\s+(plural=[^;]+)/', $meta, $matches) === 0) {
                     continue;
                 }
                 $this->bendTextDomains[$textDomain]['plurals'] = (int) $matches[1];
                 $this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $matches[2] . ';';
             }
         }
     } else {
         return;
     }
     $textDomainCodeSet = $codeSet !== null ? $codeSet : $this->defaultCodeSet;
     if (bind_textdomain_codeset($textDomain, $textDomainCodeSet) === $textDomainCodeSet) {
         $this->bendTextDomains[$textDomain]['code_set'] = $textDomainCodeSet;
     }
 }
Esempio n. 9
0
 /**
  * Initialise our use of Gettext
  */
 function init_gettext($domain, $location)
 {
     bindtextdomain($domain, $location);
     $codeset = bind_textdomain_codeset($domain, "UTF-8");
     textdomain($domain);
     dbg_error_log("I18N", "Bound domain =%s= to location =%s= using character set =%s=", $domain, $location, $codeset);
 }
 public function defineLanguage()
 {
     setlocale(LC_MESSAGES, $this->locales[$this->language]);
     bindtextdomain($this->route['view'], 'language');
     textdomain($this->route['view']);
     bind_textdomain_codeset($this->route['view'], 'UTF-8');
 }
Esempio n. 11
0
function localization_setup()
{
    global $lang, $domain, $encoding, $available_locales, $preferred_lang;
    // Choose a default language based on the client's HTTP headers.
    // TODO: Replace HTTP::negotiateLanguage with something less buggy.
    // (See http://www.dracos.co.uk/web/php/HTTP/ for details.)
    $supported = $available_locales;
    $preferred_lang = HTTP::negotiateLanguage($supported, $lang);
    if ($preferred_lang) {
        $lang = $preferred_lang;
    }
    // Override the default if the user has an explicit cookie or query string.
    $force_lang = get_requested_lang();
    if ($force_lang) {
        $lang = $force_lang;
    }
    if ($available_locales[$lang]) {
        // Set the locale.
        $locale = $available_locales[$lang][0];
        setlocale(LC_ALL, $locale);
        // Find the locale directory.
        $path_parts = pathinfo(__FILE__);
        $this_dir = $path_parts["dirname"];
        bindtextdomain($domain, "{$this_dir}/../locale");
        // Set up gettext message localization.
        textdomain($domain);
        bind_textdomain_codeset($domain, $encoding);
    }
    // Tell clients to cache different languages separately.
    header("Vary: Accept-Language");
}
Esempio n. 12
0
 function init($language, $baseDir)
 {
     if (!is_file($baseDir . 'language/' . $language . '/LC_MESSAGES/pommo.mo')) {
         Pommo::kill('Unknown Language (' . $language . ')');
     }
     // if LC_MESSAGES is not available.. make it (helpful for win32)
     if (!defined('LC_MESSAGES')) {
         define('LC_MESSAGES', 6);
     }
     // load gettext emulation layer if PHP is not compiled w/ gettext support
     if (!function_exists('gettext')) {
         require_once $baseDir . 'lib/gettext/gettext.php';
         require_once $baseDir . 'lib/gettext/gettext.inc';
     }
     // set the locale
     if (!Pommo_Helper_L10n::_setLocale(LC_MESSAGES, $language, $baseDir)) {
         // *** SYSTEM LOCALE COULD NOT BE USED, USE EMULTATION ****
         require_once $baseDir . 'lib/gettext/gettext.php';
         require_once $baseDir . 'lib/gettext/gettext.inc';
         if (!Pommo_Helper_L10n::_setLocaleEmu(LC_MESSAGES, $language, $baseDir)) {
             Pommo::kill('Error setting up language translation!');
         }
     } else {
         // *** SYSTEM LOCALE WAS USED ***
         if (!defined('_poMMo_gettext')) {
             // set gettext environment
             $domain = 'pommo';
             bindtextdomain($domain, $baseDir . 'language');
             textdomain($domain);
             if (function_exists('bind_textdomain_codeset')) {
                 bind_textdomain_codeset($domain, 'UTF-8');
             }
         }
     }
 }
Esempio n. 13
0
 /**
  * Specify the character encoding in which the messages
  * from the DOMAIN message catalog will be returned.
  *
  * @param  string $domain
  * @param  string $codeset
  * @return string
  */
 public function bindTextDomainCodeset($domain, $codeset)
 {
     if ($this->driver->hasLocaleAndFunction('bind_textdomain_codeset')) {
         return bind_textdomain_codeset($domain, $codeset);
     }
     return $this->driver->bindTextDomainCodeset($domain, $codeset);
 }
Esempio n. 14
0
 protected function registerTextDomains()
 {
     foreach (func_get_args() as $domain) {
         bindtextdomain($domain, __DIR__ . '/../Resources/translations');
         bind_textdomain_codeset($domain, 'UTF-8');
     }
 }
Esempio n. 15
0
 protected function setUp()
 {
     // override bootstrap settings
     bindtextdomain("default", E7_PATH . "/tests/i18n");
     textdomain("default");
     bind_textdomain_codeset("default", 'UTF-8');
 }
Esempio n. 16
0
 /**
  * TuiyoLocalize::initiate()
  * Initiates a language domain
  * @param mixed $domain
  * @param mixed $locale
  * @param mixed $encoding
  * @return
  */
 public function initiate($domain, $locale, $encoding)
 {
     //Initialize gettText
     $locale = !empty($locale) ? $locale : TUIYO_DEFAULT_LOCALE;
     $domain = !empty($domain) ? $domain : 'system';
     $encoding = !empty($encoding) ? $encoding : TUIYO_DEFAULT_ENCODING;
     putenv("LANG={$locale}");
     if (!extension_loaded('gettext')) {
         TuiyoLoader::import("gettext.gettext", "elibrary", "inc");
         T_setlocale(LC_ALL, $locale);
         T_bindtextdomain($domain, TUIYO_LOCALE);
         T_bind_textdomain_codeset($domain, $encoding);
         T_textdomain($domain);
         //return TRUE;
     }
     setlocale(LC_ALL, $locale);
     bindtextdomain($domain, TUIYO_LOCALE);
     bind_textdomain_codeset($domain, $encoding);
     textdomain($domain);
     $path = "components/com_tuiyo/locale/" . $locale;
     //Load the parameters for the site!
     if (!class_exists('JSite')) {
         $path = "../components/com_tuiyo/locale/" . $locale;
     }
     $GLOBALS['mainframe']->addMetaTag("locale", $locale);
     $GLOBALS['mainframe']->addCustomHeadTag('<link href="' . $path . '/LC_MESSAGES/system.client.json" lang="' . $locale . '" rel="gettext" />');
 }
Esempio n. 17
0
function ewatcher_translate($string)
{
    $ewatcher_domain = "messages";
    bindtextdomain($ewatcher_domain, "Modules/ewatcher/locale");
    bind_textdomain_codeset($ewatcher_domain, "UTF-8");
    return dgettext($ewatcher_domain, $string);
}
Esempio n. 18
0
function set_language()
{
    global $amp_conf, $db;
    $nt = notifications::create($db);
    if (extension_loaded('gettext')) {
        $nt->delete('core', 'GETTEXT');
        if (php_sapi_name() !== 'cli') {
            if (empty($_COOKIE['lang']) || !preg_match('/^[\\w\\._@-]+$/', $_COOKIE['lang'], $matches)) {
                $lang = $amp_conf['UIDEFAULTLANG'] ? $amp_conf['UIDEFAULTLANG'] : 'en_US';
                if (empty($_COOKIE['lang'])) {
                    setcookie("lang", $lang);
                }
            } else {
                preg_match('/^([\\w\\._@-]+)$/', $_COOKIE['lang'], $matches);
                $lang = !empty($matches[1]) ? $matches[1] : 'en_US';
            }
            $_COOKIE['lang'] = $lang;
        } else {
            $lang = $amp_conf['UIDEFAULTLANG'] ? $amp_conf['UIDEFAULTLANG'] : 'en_US';
        }
        putenv('LC_ALL=' . $lang);
        putenv('LANG=' . $lang);
        putenv('LANGUAGE=' . $lang);
        setlocale(LC_ALL, $lang);
        bindtextdomain('amp', $amp_conf['AMPWEBROOT'] . '/admin/i18n');
        bind_textdomain_codeset('amp', 'utf8');
        textdomain('amp');
        return $lang;
    }
    $nt->add_warning('core', 'GETTEXT', _("Gettext is not installed"), _("Please install gettext so that the PBX can properly translate itself"), 'https://www.gnu.org/software/gettext/');
    return 'en_US';
}
Esempio n. 19
0
/**
 * ------------------------------------------------------------------------- *
 * This library is free software; you can redistribute it and/or             *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * This library is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with this library; if not, write to the Free Software       *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
 * ------------------------------------------------------------------------- *
 *
 * @package smarty-gettext
 * @link https://github.com/smarty-gettext/smarty-gettext/
 * @author Karlheinz Toni <*****@*****.**>
 * @author Boleslaw Tekielski <*****@*****.**>
 * @author Elan Ruusamäe <*****@*****.**>
 * @copyright 2012 Karlheinz Toni
 * @copyright 2015 Boleslaw Tekielski
 * @copyright 2015 Elan Ruusamäe
 */
function smarty_function_locale($params, &$smarty)
{
    static $stack;
    // init stack as array
    if ($stack === null) {
        $stack = array();
    }
    $path = $smarty->template_dir . $params['path'];
    $domain = isset($params['domain']) ? $params['domain'] : 'messages';
    $stack_operation = isset($params['stack']) ? $params['stack'] : 'push';
    if (!$path && $stack_operation != 'pop') {
        trigger_error("static (file {$smarty->template}): missing 'path' parameter.", E_USER_ERROR);
    }
    if ($stack_operation == 'push') {
        $stack[] = array($domain, $path);
    } elseif ($stack_operation == 'pop') {
        if (count($stack) > 1) {
            array_pop($stack);
        }
        list($domain, $path) = end($stack);
    } else {
        trigger_error("Unknown stack operation '{$stack_operation}'", E_USER_ERROR);
    }
    bind_textdomain_codeset($domain, 'UTF-8');
    bindtextdomain($domain, $path);
    textdomain($domain);
}
Esempio n. 20
0
function before($route)
{
    $lang_mapping = array('fr' => 'fr_FR');
    if (!isset($_SESSION['locale'])) {
        $locale = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $_SESSION['locale'] = strtolower(substr(chop($locale[0]), 0, 2));
    }
    $lang = $_SESSION['locale'];
    // Convert simple language code into full language code
    if (array_key_exists($lang, $lang_mapping)) {
        $lang = $lang_mapping[$lang];
    }
    $lang = "{$lang}.utf8";
    $textdomain = "localization";
    putenv("LANGUAGE={$lang}");
    putenv("LANG={$lang}");
    putenv("LC_ALL={$lang}");
    putenv("LC_MESSAGES={$lang}");
    setlocale(LC_ALL, $lang);
    setlocale(LC_CTYPE, $lang);
    $locales_dir = dirname(__FILE__) . '/i18n';
    bindtextdomain($textdomain, $locales_dir);
    bind_textdomain_codeset($textdomain, 'UTF-8');
    textdomain($textdomain);
    set('locale', $lang);
}
function locale($params, &$smarty)
{
    global $stack;
    $path = isset($params['path']) ? str_replace(array("'", '"'), '', $params['path']) : null;
    $domain = isset($params['domain']) ? str_replace(array("'", '"'), '', $params['domain']) : 'messages';
    $stack_operation = isset($params['stack']) ? str_replace(array("'", '"'), '', strtolower($params['stack'])) : 'push';
    if ($path == null && $stack_operation != 'pop') {
        trigger_error("static (file {$smarty->_current_file}): missing 'path' parameter.", E_USER_ERROR);
    }
    if ($stack_operation == 'push') {
        $stack[] = array($domain, $path);
    } else {
        if ($stack_operation == 'pop') {
            if (count($stack) > 1) {
                array_pop($stack);
            }
            $definition = end($stack);
            $domain = $definition[0];
            $path = $definition[1];
        }
    }
    bind_textdomain_codeset($domain, 'UTF-8');
    bindtextdomain($domain, $path);
    textdomain($domain);
}
Esempio n. 22
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);
     }
 }
Esempio n. 23
0
 public function addDomain($domain, $path = './locale/')
 {
     bindtextdomain($domain, $path);
     if ($this->_encoding) {
         bind_textdomain_codeset($domain, $this->_encoding);
     }
     $this->useDomain($domain);
 }
Esempio n. 24
0
 /**
  * @param string $locale
  * @codeCoverageIgnore
  */
 public function setLocale(string $locale)
 {
     putenv(sprintf('LANG=%s.UTF-8', $locale));
     setlocale(LC_MESSAGES, sprintf('%s.UTF-8', $locale));
     bindtextdomain(self::DOMAIN, self::LANG_DIR);
     bind_textdomain_codeset(self::DOMAIN, 'UTF-8');
     textdomain(self::DOMAIN);
 }
Esempio n. 25
0
 public function init()
 {
     putenv('LANGUAGE=' . $this->lang);
     setlocale(LC_ALL, "C.UTF-8");
     bindtextdomain('messages', $this->app['BASE_DIR'] . '/i18n');
     bind_textdomain_codeset('messages', 'UTF-8');
     textdomain('messages');
 }
/**
 * Run GNU Gettext
 */
function gettext_rocks($lang = 'it_IT', $domain = 'fuel.reyboz.it', $folder = 'l10n', $encoding = 'UTF-8')
{
    putenv("LANG={$lang}.{$encoding}");
    setlocale(LC_MESSAGES, "{$lang}.{$encoding}");
    bindtextdomain($domain, $folder);
    textdomain($domain);
    bind_textdomain_codeset($domain, $encoding);
}
Esempio n. 27
0
 public static function setupGettext()
 {
     $path = '@DATA-DIR@/Deliverance/locale';
     if (substr($path, 0, 1) === '@') {
         $path = dirname(__FILE__) . '/../locale';
     }
     bindtextdomain(Deliverance::GETTEXT_DOMAIN, $path);
     bind_textdomain_codeset(Deliverance::GETTEXT_DOMAIN, 'UTF-8');
 }
Esempio n. 28
0
 /**
  * Prepares the testing environment.
  */
 protected function setUp()
 {
     bind_textdomain_codeset('messages', 'UTF-8');
     bindtextdomain('messages', DIR_FILES . '/time');
     textdomain('messages');
     putenv('LANG=cs_CZ.UTF-8');
     putenv('LANGUAGE=cs_CZ.UTF-8');
     @setlocale(LC_MESSAGES, 'cs_CZ.UTF-8');
 }
Esempio n. 29
0
 /**
  * Loads a gettext domain.
  *
  * @param string $domain
  * @param string $path
  * @param bool   $default
  *
  * @return self
  */
 public function loadDomain($domain, $path = null, $default = true)
 {
     bindtextdomain($domain, $path);
     bind_textdomain_codeset($domain, 'UTF-8');
     if ($default) {
         textdomain($domain);
     }
     return $this;
 }
Esempio n. 30
0
 public function __construct(ymcI18nSystemLocale $locale)
 {
     $this->locale = $locale;
     if (!$locale->systemLocale) {
         $this->doNotTranslate = TRUE;
     }
     self::initCountries();
     bind_textdomain_codeset(self::DOMAIN, 'UTF-8');
 }