本文整理汇总了PHP中HTTP::negotiateLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::negotiateLanguage方法的具体用法?PHP HTTP::negotiateLanguage怎么用?PHP HTTP::negotiateLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP
的用法示例。
在下文中一共展示了HTTP::negotiateLanguage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: localization_setup
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");
}
示例2: load
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();
}
示例3: array
/*
* 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']);
示例4: initTranslator
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();
}