本文整理汇总了PHP中JApplicationCms::loadLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP JApplicationCms::loadLanguage方法的具体用法?PHP JApplicationCms::loadLanguage怎么用?PHP JApplicationCms::loadLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JApplicationCms
的用法示例。
在下文中一共展示了JApplicationCms::loadLanguage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseRule
//.........这里部分代码省略.........
// that we have in our system, its the default language and we "found" the right language
if ($this->params->get('remove_default_prefix', 0) && !isset($this->sefs[$sef])) {
$found = true;
$lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
} else {
// If the language prefix should always be present or it is indeed , we can now look it up in our array
if (isset($this->sefs[$sef])) {
// We found our language
$found = true;
$lang_code = $this->sefs[$sef]->lang_code;
}
// If we found our language, but its the default language and we don't want a prefix for that, we are on a wrong URL
if ($this->params->get('remove_default_prefix', 0) && $lang_code == JComponentHelper::getParams('com_languages')->get('site', 'en-GB')) {
$found = false;
array_shift($parts);
$path = implode('/', $parts);
}
// We have found our language and the first part of our URL is the language prefix
if ($found) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
}
} else {
// We are not in SEF mode
$lang = $uri->getVar('lang');
if (isset($this->sefs[$lang])) {
// We found our language
$found = true;
$lang_code = $this->sefs[$lang]->lang_code;
}
}
// We are called via POST. We don't care about the language
// and simply set the default language as our current language.
if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
$found = true;
$lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'));
if ($this->params->get('detect_browser', 1) && !$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
}
}
// We have not found the language and thus need to redirect
if (!$found) {
// Lets find the default language for this user
if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
$lang_code = false;
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = false;
}
}
if (!$lang_code) {
$lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
}
// Either we detected the language via the browser or we got it from the cookie. In worst case
// we fall back to the application setting
$lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'), $lang_code);
}
if ($this->mode_sef) {
// Use the current language sef or the default one.
if (!$this->params->get('remove_default_prefix', 0) || $lang_code != JComponentHelper::getParams('com_languages')->get('site', 'en-GB')) {
$path = $this->lang_codes[$lang_code]->sef . '/' . $path;
}
$uri->setPath($path);
if (!$this->app->get('sef_rewrite')) {
$uri->setPath('index.php/' . $uri->getPath());
}
$this->app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
$this->app->redirect($uri->base() . 'index.php?' . $uri->getQuery());
}
}
// We have found our language and now need to set the cookie and the language value in our system
$array = array('lang' => $lang_code);
$this->default_lang = $lang_code;
// Set the request var.
$this->app->input->set('language', $lang_code);
$this->app->set('language', $lang_code);
$language = JFactory::getLanguage();
if ($language->getTag() != $lang_code) {
$newLang = JLanguage::getInstance($lang_code);
foreach ($language->getPaths() as $extension => $files) {
$newLang->load($extension);
}
JFactory::$language = $newLang;
$this->app->loadLanguage($newLang);
}
// Create a cookie.
if ($this->app->input->cookie->getString(JApplicationHelper::getHash('language')) != $lang_code) {
$cookie_domain = $this->app->get('cookie_domain');
$cookie_path = $this->app->get('cookie_path', $uri->base(true));
$this->app->input->cookie->set(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
}
return $array;
}
示例2: parseRule
//.........这里部分代码省略.........
}
} else {
// We found our language
$found = true;
$lang_code = $this->sefs[$sef]->lang_code;
// If we found our language, but its the default language and we don't want a prefix for that, we are on a wrong URL.
// Or we try to change the language back to the default language. We need a redirect to the proper URL for the default language.
if ($this->params->get('remove_default_prefix', 0) && $lang_code == $this->default_lang) {
// Create a cookie.
$this->setLanguageCookie($lang_code);
$found = false;
array_shift($parts);
$path = implode('/', $parts);
}
// We have found our language and the first part of our URL is the language prefix
if ($found) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
}
} else {
$lang_code = $this->getLanguageCookie();
if ($this->params->get('detect_browser', 1) && !$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = $this->default_lang;
}
}
$lang = $uri->getVar('lang', $lang_code);
if (isset($this->sefs[$lang])) {
// We found our language
$found = true;
$lang_code = $this->sefs[$lang]->lang_code;
}
// We are called via POST. We don't care about the language
// and simply set the default language as our current language.
if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
$found = true;
if (!isset($lang_code)) {
$lang_code = $this->getLanguageCookie();
}
if ($this->params->get('detect_browser', 1) && !$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = $this->default_lang;
}
}
// We have not found the language and thus need to redirect
if (!$found) {
// Lets find the default language for this user
if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
$lang_code = false;
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = false;
}
}
if (!$lang_code) {
$lang_code = $this->default_lang;
}
}
if ($this->mode_sef) {
// Use the current language sef or the default one.
if (!$this->params->get('remove_default_prefix', 0) || $lang_code != $this->default_lang) {
$path = $this->lang_codes[$lang_code]->sef . '/' . $path;
}
$uri->setPath($path);
if (!$this->app->get('sef_rewrite')) {
$uri->setPath('index.php/' . $uri->getPath());
}
$this->app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')), 301);
} else {
$uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
$this->app->redirect($uri->base() . 'index.php?' . $uri->getQuery(), 301);
}
}
// We have found our language and now need to set the cookie and the language value in our system
$array = array('lang' => $lang_code);
$this->current_lang = $lang_code;
// Set the request var.
$this->app->input->set('language', $lang_code);
$this->app->set('language', $lang_code);
$language = JFactory::getLanguage();
if ($language->getTag() != $lang_code) {
$newLang = JLanguage::getInstance($lang_code);
foreach ($language->getPaths() as $extension => $files) {
$newLang->load($extension);
}
JFactory::$language = $newLang;
$this->app->loadLanguage($newLang);
}
// Create a cookie.
if ($this->getLanguageCookie() != $lang_code) {
$this->setLanguageCookie($lang_code);
}
return $array;
}
示例3: parseRule
//.........这里部分代码省略.........
// We have found our language and the first part of our URL is the language prefix
if ($found) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
}
} else {
$lang_code = $this->getLanguageCookie();
if ($this->params->get('detect_browser', 1) && !$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = $this->default_lang;
}
}
$lang = $uri->getVar('lang', $lang_code);
if (isset($this->sefs[$lang])) {
// We found our language
$found = true;
$lang_code = $this->sefs[$lang]->lang_code;
}
// We are called via POST. We don't care about the language
// and simply set the default language as our current language.
if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
$found = true;
if (!isset($lang_code)) {
$lang_code = $this->getLanguageCookie();
}
if ($this->params->get('detect_browser', 1) && !$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = $this->default_lang;
}
}
// We have not found the language and thus need to redirect
if (!$found) {
// Lets find the default language for this user
if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
$lang_code = false;
if ($this->params->get('detect_browser', 1)) {
$lang_code = JLanguageHelper::detectLanguage();
if (!isset($this->lang_codes[$lang_code])) {
$lang_code = false;
}
}
if (!$lang_code) {
$lang_code = $this->default_lang;
}
}
if ($this->mode_sef) {
// Use the current language sef or the default one.
if (!$this->params->get('remove_default_prefix', 0) || $lang_code != $this->default_lang) {
$path = $this->lang_codes[$lang_code]->sef . '/' . $path;
}
$uri->setPath($path);
if (!$this->app->get('sef_rewrite')) {
$uri->setPath('index.php/' . $uri->getPath());
}
$redirectUri = $uri->base() . $uri->toString(array('path', 'query', 'fragment'));
} else {
$uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
$redirectUri = $uri->base() . 'index.php?' . $uri->getQuery();
}
// Set redirect HTTP code to "302 Found".
$redirectHttpCode = 302;
// If selected language is the default language redirect code is "301 Moved Permanently".
if ($lang_code === $this->default_lang) {
$redirectHttpCode = 301;
// We cannot cache this redirect in browser. 301 is cachable by default so we need to force to not cache it in browsers.
$this->app->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
$this->app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
$this->app->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
$this->app->setHeader('Pragma', 'no-cache');
$this->app->sendHeaders();
}
// Redirect to language.
$this->app->redirect($redirectUri, $redirectHttpCode);
}
// We have found our language and now need to set the cookie and the language value in our system
$array = array('lang' => $lang_code);
$this->current_lang = $lang_code;
// Set the request var.
$this->app->input->set('language', $lang_code);
$this->app->set('language', $lang_code);
$language = JFactory::getLanguage();
if ($language->getTag() != $lang_code) {
$newLang = JLanguage::getInstance($lang_code);
foreach ($language->getPaths() as $extension => $files) {
$newLang->load($extension);
}
JFactory::$language = $newLang;
$this->app->loadLanguage($newLang);
}
// Create a cookie.
if ($this->getLanguageCookie() != $lang_code) {
$this->setLanguageCookie($lang_code);
}
return $array;
}