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"); }
function load(k_Context $context) { require_once 'PEAR.php'; require_once 'HTTP.php'; if ($context->query('lang') == 'da') { return new DanishLanguage(); } else { if ($context->query('lang') == 'fr') { return new FrenchLanguage(); } else { if ($context->query('lang') == 'de') { return new GermanLanguage(); } else { if ($context->query('lang') == 'hi') { return new HindiLanguage(); } else { if ($context->query('lang')) { return new DanishLanguage(); } } } } } $supported = array("da" => true, "en-US" => true); $language = HTTP::negotiateLanguage($supported); if (PEAR::isError($language)) { // fallback language in case of unable to negotiate return new DanishLanguage(); } if ($language == 'en-US') { return new EnglishLanguage(); } return new DanishLanguage(); }
/* * reads config file */ $blocks = array(); $data = array(); $conf = new Config('IniFile'); $conf->parseInput('rubbercity.ini'); $blocks = $conf->getBlocks("/"); foreach ($blocks as $block) { $cfg[$block] = $conf->getValues("/" . $block); } /* * Sets the language according to browser settings */ $langSupported = array("de" => true, "en" => true); define("LC_LANG", HTTP::negotiateLanguage($langSupported, 'en')); $langSelected = 'rc_' . LC_LANG; include_once $cfg['path']['i18n'] . LC_LANG . ".php"; $lang = new $langSelected(); $heute = date("Ymd", time()); // current date /* * Template */ function tpl_translate($args) { global $lang; return $lang->translate($args[0]); } $_tplset = 'screen'; $tpl = new IntegratedTemplateExtension($cfg['path']['template']);
function initTranslator() { $langSupported = array("de" => true, "en" => true); include_once 'HTTP.php'; define("LC_LANG", HTTP::negotiateLanguage($langSupported, $this->cfg['i18n']['default'])); $langSelected = 'rc_' . LC_LANG; include_once $this->cfg['i18n']['directory'] . LC_LANG . ".php"; $this->lang = new $langSelected(); }