/** * ------------------------------------------------------------------------- * * 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); }
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'; }
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); }
/** * * {@inheritDoc} * * @see \Thunderhawk\API\Component\Translator\TranslatorInterface::setDomainName() */ public function setDomain($domain) { if (in_array($domain, $this->_domains)) { $this->_activeDomain = $domain; textdomain($this->_activeDomain); } }
/** * 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; } } }
/** * Set the default domain. * * @param string|null $domain * @return string */ public function textDomain($domain = null) { if ($this->driver->hasLocaleAndFunction('textdomain')) { return textdomain($domain); } return $this->driver->textDomain($domain); }
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'); } } } }
function __construct() { $CI =& get_instance(); $CI->load->library('form_validation'); $CI->load->library('session'); $CI->form_validation->set_rules('lang_select', 'lang_select', 'exact_length[2]'); $this->lang_default = 'en'; if ($CI->input->post('lang_select')) { if ($CI->form_validation->run() == TRUE) { $this->lang = $CI->input->post('lang_select'); } else { $this->lang = $this->lang_default; } $CI->session->set_userdata(array('lang' => $this->lang, 'lang_txt' => $this->lang_allowed[$this->lang])); } else { if (!$CI->session->userdata('lang')) { $this->lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if (array_key_exists($this->lang, $this->lang_allowed)) { $CI->session->set_userdata(array('lang' => $this->lang, 'lang_txt' => $this->lang_allowed[$this->lang])); } else { $CI->session->set_userdata(array('lang' => $this->lang_default, 'lang_txt' => $this->lang_allowed[$this->lang_default])); } } } $del = array($CI->session->userdata('lang') => $CI->session->userdata('lang_txt')); $CI->session->set_userdata('lang_allowed', array_diff($this->lang_allowed, $del)); setlocale(LC_ALL, $CI->session->userdata('lang') . '_' . strtoupper($CI->session->userdata('lang')) . '.UTF-8'); setlocale(LC_NUMERIC, $CI->session->userdata('lang') . '_' . strtoupper($CI->session->userdata('lang')) . '.UTF-8'); bindtextdomain(strtolower($this->domain), APPPATH . '/language/locales/'); textdomain(strtolower($this->domain)); }
public static function setlocale_twoletter($locale) { putenv("LANG={$locale}"); setlocale(LC_MESSAGES, $locale); bindtextdomain(self::DOMAIN, self::LOCALEDIR); textdomain(self::DOMAIN); }
static function package($name, $path = null) { if ($path !== null) { bindtextdomain($name, $GLOBALS['_lang']->path . $path); } textdomain($name); }
function alternc_changepass_optpage_register_block() { global $optpage_blocks; textdomain("alternc-changepass"); $optpage_blocks[] = array('name' => _("Change Password"), 'url' => '../plugins/alternc_changepass/change.php', 'desc' => _("Change the password of your email account."), 'js' => false); textdomain("squirrelmail"); }
/** * Build a new reporter html render */ protected function __construct() { putenv('LC_ALL=' . self::$lang); setlocale(LC_ALL, self::$lang); bindtextdomain($this->domain, self::$i18nPath); textdomain($this->domain); }
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); } }
protected function setUp() { // override bootstrap settings bindtextdomain("default", E7_PATH . "/tests/i18n"); textdomain("default"); bind_textdomain_codeset("default", 'UTF-8'); }
/** * 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" />'); }
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); }
function PluginVotex() { // static static $CONF = array(); $this->CONF =& $CONF; if (empty($this->CONF)) { $this->CONF['RECENT_PAGE'] = 'RecentVotes'; $this->CONF['RECENT_LOG'] = CACHE_DIR . 'recentvotes.dat'; $this->CONF['RECENT_LIMIT'] = 100; $this->CONF['COOKIE_EXPIRED'] = 60 * 60 * 24 * 3; $this->CONF['BARCHART_LIB_FILE'] = LIB_DIR . 'barchart.cls.php'; $this->CONF['BARCHART_COLOR_BAR'] = ' #0000cc'; $this->CONF['BARCHART_COLOR_BG'] = 'transparent'; $this->CONF['BARCHART_COLOR_BORDER'] = 'transparent'; } static $default_options = array(); $this->default_options =& $default_options; if (empty($this->default_options)) { $this->default_options['readonly'] = FALSE; $this->default_options['addchoice'] = FALSE; $this->default_options['barchart'] = FALSE; } // init $this->options = $this->default_options; if (function_exists('textdomain')) { textdomain('vote'); // use i18n msgs of vote.inc.php } }
function initLocalize($argLanguage = null) { $language = 'en_US'; // 適用言語判定 if (null === $argLanguage && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // 指定がなければHTTP_ACCEPT_LANGUAGEから判定する $argLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } if (false !== strpos($argLanguage, "ja") || false !== strpos(strtolower($argLanguage), "jp")) { // 強制日本語 $argLanguage = 'ja_JP'; } if (false !== strpos($argLanguage, "zh") || false !== strpos(strtolower($argLanguage), "cn") || false !== strpos(strtolower($argLanguage), "tw")) { // 強制中国語(簡体) $argLanguage = 'zh_CN'; } if (false !== strpos($argLanguage, "ja_JP") || false !== strpos($argLanguage, "zh_CN")) { // 言語を決定 $language = $argLanguage . ".UTF-8"; } debug("lng=" . $language); // 言語処理 putenv("LANG={$language}"); setlocale(LC_ALL, $language); $domain = "messages"; bindtextdomain($domain, dirname(__FILE__)); textdomain($domain); return $language; }
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"); }
/** * Restore the text domain active before the last call to * set_textdomain(). */ private function restore_textdomain() { $old_td = array_pop($this->_td_stack); if ($old_td) { textdomain($old_td); } }
/** * 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 __construct($options) { putenv("LC_ALL=" . $options['locale']); setlocale(LC_ALL, $options['locale']); bindtextdomain($options['file'], $options['directory']); textdomain($options['file']); }
function postfixadmin_optpage_register_block() { // Gets added to the user's OPTIONS page. global $optpage_blocks; global $AllowVacation; global $AllowChangePass; // if ( !soupNazi() ) { bindtextdomain('postfixadmin', SM_PATH . 'plugins/postfixadmin/locale'); textdomain('postfixadmin'); $optpage_blocks[] = array('name' => _("Forwarding"), 'url' => '../plugins/postfixadmin/postfixadmin_forward.php', 'desc' => _("Here you can create and edit E-Mail forwards."), 'js' => FALSE); bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain('squirrelmail'); bindtextdomain('postfixadmin', SM_PATH . 'plugins/postfixadmin/locale'); textdomain('postfixadmin'); if ($AllowVacation) { $optpage_blocks[] = array('name' => _("Auto Response"), 'url' => '../plugins/postfixadmin/postfixadmin_vacation.php', 'desc' => _("Set an OUT OF OFFICE message or auto responder for your mail."), 'js' => false); bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain('squirrelmail'); } bindtextdomain('postfixadmin', SM_PATH . 'plugins/postfixadmin/locale'); textdomain('postfixadmin'); if ($AllowChangePass) { $optpage_blocks[] = array('name' => _("Change Password"), 'url' => '../plugins/postfixadmin/postfixadmin_changepass.php', 'desc' => _("Change your mailbox password."), 'js' => false); bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain('squirrelmail'); } }
/** * Configures the gettext translations */ public function __construct(array $vars = null) { if (defined('THEME')) { $dir = SITE_HOME . '/Themes/' . THEME; if (is_dir($dir)) { $this->theme = $dir; $config_file = $dir . '/theme_config.inc'; if (is_file($config_file)) { $this->theme_config = (require $config_file); } } } if (count($vars)) { foreach ($vars as $name => $value) { $this->vars[$name] = $value; } } $locale = LOCALE . '.utf8'; putenv("LC_ALL={$locale}"); setlocale(LC_ALL, $locale); bindtextdomain('labels', APPLICATION_HOME . '/language'); bindtextdomain('messages', APPLICATION_HOME . '/language'); bindtextdomain('errors', APPLICATION_HOME . '/language'); textdomain('labels'); }
/** * ------------------------------------------------------------------------- * * 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); }
/** * Prints a translated text * * @param string $message Message * @param string $parameter Message * * @return string */ public function sprintf($message, $parameter = "") { \textdomain($this->_domain); $arguments = \func_get_args(); \array_shift($arguments); return \vsprintf(_($message), $arguments); }
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'); }
public function useDomain($domain) { $old = $this->_currentDomain; $this->_currentDomain = $domain; textdomain($domain); return $old; }
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; }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function buildContent() { $actionRows = $this->getActionRows(); $harmoni = Harmoni::instance(); // Set our textdomain $defaultTextDomain = textdomain("polyphony"); ob_start(); $harmoni->request->startNamespace("harmoni-authentication"); $action = $harmoni->history->getReturnURL("polyphony/authentication"); $usernameField = $harmoni->request->getName("username"); $passwordField = $harmoni->request->getName("password"); $usernameText = _("Username/Email"); $passwordText = _("Password"); $submitLabel = _('Log In'); print <<<END \t\t \t\t<center><form name='login' action='{$action}' method='post'> \t\t\t{$usernameText}: <input type='text' name='{$usernameField}' /> \t\t\t<br />{$passwordText}: <input type='password' name='{$passwordField}' /> \t\t\t<br /><input type='submit' value='{$submitLabel}'/> \t\t</form></center> \t\t END; $actionRows->add(new Block(ob_get_contents(), 2), "100%", null, CENTER, CENTER); ob_end_clean(); $harmoni->request->endNamespace(); // go back to the default text domain textdomain($defaultTextDomain); }