本文整理汇总了PHP中JLanguageHelper::detectLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP JLanguageHelper::detectLanguage方法的具体用法?PHP JLanguageHelper::detectLanguage怎么用?PHP JLanguageHelper::detectLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JLanguageHelper
的用法示例。
在下文中一共展示了JLanguageHelper::detectLanguage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
/**
* Method to get the field options.
*
* @return array The field option objects.
* @since 1.6
*/
protected function getOptions()
{
// Initialise variables.
$app = JFactory::getApplication();
// Detect the native language.
$native = JLanguageHelper::detectLanguage();
if (empty($native)) {
$native = 'en-GB';
}
// Get a forced language if it exists.
$forced = $app->getLocalise();
if (!empty($forced['language'])) {
$native = $forced['language'];
}
// If a language is already set in the session, use this instead
$session = JFactory::getSession()->get('setup.options', array());
if (!empty($session['language'])) {
$native = $session['language'];
}
// Get the list of available languages.
$options = JLanguageHelper::createLanguageList($native);
if (!$options || JError::isError($options)) {
$options = array();
}
// Set the default value from the native language.
$this->value = $native;
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
示例2: getOptions
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 1.6
*/
protected function getOptions()
{
$app = JFactory::getApplication();
// Detect the native language.
$native = JLanguageHelper::detectLanguage();
if (empty($native)) {
$native = 'en-GB';
}
// Get a forced language if it exists.
$forced = $app->getLocalise();
if (!empty($forced['language'])) {
$native = $forced['language'];
}
// If a language is already set in the session, use this instead
$model = new InstallationModelSetup();
$options = $model->getOptions();
if (isset($options['language'])) {
$native = $options['language'];
}
// Get the list of available languages.
$options = JLanguageHelper::createLanguageList($native);
if (!$options || $options instanceof Exception) {
$options = array();
} else {
usort($options, array($this, '_sortLanguages'));
}
// Set the default value from the native language.
$this->value = $native;
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
示例3: initialise
/**
* Initialise the application.
*
* @param array
*/
public function initialise($options = array())
{
$config = JFactory::getConfig();
// if a language was specified it has priority
// otherwise use user or default language settings
JPluginHelper::importPlugin('system', 'languagefilter');
if (empty($options['language'])) {
$lang = JRequest::getString('language', null);
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_language_filter && empty($options['language'])) {
// Detect cookie language
jimport('joomla.utilities.utility');
$lang = JRequest::getString(self::getHash('language'), null, 'cookie');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect user language
$lang = JFactory::getUser()->getParam('language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_detect_browser && empty($options['language'])) {
// Detect browser language
$lang = JLanguageHelper::detectLanguage();
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect default language
$params = JComponentHelper::getParams('com_languages');
$client = JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, $config->get('language', 'en-GB'));
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $config->get('language', 'en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
$options['language'] = 'en-GB';
// as a last ditch fail to english
}
}
// Execute the parent initialise method.
parent::initialise($options);
// Load Library language
$lang = JFactory::getLanguage();
// Try the lib_joomla file in the current language (without allowing the loading of the file in the default language)
$lang->load('lib_joomla', JPATH_SITE, null, false, false) || $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('lib_joomla', JPATH_SITE, null, true) || $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, true);
}
示例4: getUri
/**
* Get Uri
*
* @param string $url URL
*
* @return JUri
*/
public function getUri($url = 'SERVER')
{
static $uriArray = array();
if (!array_key_exists($url, $uriArray)) {
// This will enable both SEF and non-SEF URI to be parsed properly
$router = clone JRouter::getInstance('site');
$uri = clone JUri::getInstance($url);
$langCode = JLanguageHelper::detectLanguage();
$lang = $uri->getVar('lang', $langCode);
$uri->setVar('lang', $lang);
$sefs = JLanguageHelper::getLanguages('lang_code');
if (isset($sefs[$lang])) {
$lang = $sefs[$lang]->sef;
$uri->setVar('lang', $lang);
}
$router->setVars(array(), false);
$query = $router->parse($uri);
$query = array_merge($query, $uri->getQuery(true));
$uri->setQuery($query);
// We are removing format because of default value is csv if present and if not set
// and we are never going to remember csv page in a browser history anyway
$uri->delVar('format');
$uriArray[$url] = $uri;
}
return $uriArray[$url];
}
示例5: testDetectLanguage
/**
* Test...
*
* @covers JLanguageHelper::detectLanguage
* @todo Implement testDetectLanguage().
*
* @return void
*/
public function testDetectLanguage()
{
$lang = JLanguageHelper::detectLanguage();
// Since we're running in a CLI context we can only check the defualt value
$this->assertNull(
$lang
);
}
示例6: getCurrentLanguage
/**
* Gets the current language
*
* @param boolean $detectBrowser Flag indicating whether to use the browser language as a fallback.
*
* @return string The language string
*
* @since 3.2
*/
public function getCurrentLanguage($detectBrowser = true)
{
$app = JFactory::getApplication();
$langCode = $app->input->cookie->getString(JApplicationHelper::getHash('language'));
// No cookie - let's try to detect browser language or use site default
if (!$langCode) {
if ($detectBrowser) {
$langCode = JLanguageHelper::detectLanguage();
} else {
$langCode = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
}
}
return $langCode;
}
示例7: getList
public function getList($refresh = false)
{
jimport('joomla.language.helper');
$list = JLanguageHelper::createLanguageList(JLanguageHelper::detectLanguage());
foreach ($list as $l) {
$l['link'] = "index.php?option=com_citruscart&view=emails&task=edit&id=" . $l['value'];
$item = new JObject();
foreach ($l as $k => $v) {
$item->{$k} = $v;
}
$result[] = $item;
}
return $result;
}
示例8: chooseLanguage
/**
* Generate a panel of language choices for the user to select their language
*
* @return boolean True if successful
* @access public
* @since 1.5
*/
function chooseLanguage()
{
global $mainframe;
$vars =& $this->getVars();
jimport('joomla.language.helper');
$native = JLanguageHelper::detectLanguage();
$forced = $mainframe->getLocalise();
if (!empty($forced['lang'])) {
$native = $forced['lang'];
}
$lists = array();
$lists['langs'] = JLanguageHelper::createLanguageList($native);
$this->setData('lists', $lists);
return true;
}
示例9: fetchElement
/**
* Return any options this element may have
*
* @param string $name Name of the field
* @param string $value Value to check against
* @param object $element Data Source Object.
* @param string $control_name Control name (eg, control[fieldname])
* @return string HTML
*/
public function fetchElement($name, $value, &$element, $control_name)
{
if (!$value) {
jimport('joomla.language.helper');
$language = \JLanguageHelper::detectLanguage();
$language = explode('-', $language);
$value = $language[0];
}
$languages = array();
foreach ($this->_codes as $code => $lang) {
$languages[] = \Html::select('option', $code, $lang);
}
array_unshift($languages, \Html::select('option', '', '- ' . Lang::txt('Select Language') . ' -'));
return '<span class="field-wrap">' . \Html::select('genericlist', $languages, $control_name . '[' . $name . ']', 'class="inputbox"', 'value', 'text', $value, $control_name . '-' . $name) . '</span>';
}
示例10: _getOptions
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function _getOptions()
{
// Initialise variables.
$app =& JFactory::getApplication();
// Detect the native language.
jimport('joomla.language.helper');
$native = JLanguageHelper::detectLanguage();
// Get a forced language if it exists.
$forced = $app->getLocalise();
if (!empty($forced['lang'])) {
$native = $forced['lang'];
}
// Get the list of available languages.
$options = JLanguageHelper::createLanguageList($native);
if (!$options || JError::isError($options)) {
$options = array();
}
// Set the default value from the native language.
$this->value = $native;
// Merge in any explicitly listed options from the XML definition.
$options = array_merge(parent::_getOptions(), $options);
return $options;
}
示例11: ReadCountries
function ReadCountries($countries = true, $active_currencies = true, $language = '', $where = '', $resultType = 'Assoc', $firstOnly = false, $orderf = '', $orderdir = 'ASC')
{
if ($resultType == '') {
$resultType = "Assoc";
}
$db =& JFactory::getDBO();
if ($countries) {
if ($orderf == '') {
$orderf = "hits DESC, id";
}
if ($language == '') {
jimport('joomla.language.helper');
$lg = JLanguageHelper::detectLanguage();
$language = substr($lg, 0, 2);
}
$req = "select * from #__jaderp_countries";
$db->setQuery($req);
$row = $db->loadAssoc();
if (!array_key_exists($language, $row)) {
$language = "en";
}
$req = "SELECT id, hits, " . $language . " as country FROM " . $db->nameQuote("#__jaderp_countries") . " " . $where . " ORDER BY " . $orderf . " " . $orderdir;
} else {
if ($orderf == '') {
$orderf = "id";
}
if ($active_currencies) {
if ($where == '') {
$where = ' WHERE active_currency = ' . $db->quote('1');
} else {
$where = ' AND active_currency = ' . $db->quote('1');
}
}
$req = "SELECT id, currency, iso4217, currency_symbol, currency_format, hits FROM " . $db->nameQuote("#__jaderp_countries") . " " . $where . " ORDER BY " . $orderf . " " . $orderdir;
}
$db->setQuery($req);
//echo $req;
switch ($resultType) {
case 'Object':
if ($firstOnly) {
$result = $db->loadObject();
} else {
$result = $db->loadObjectList();
}
break;
case 'Array':
if ($firstOnly) {
$result = $db->loadRow();
} else {
$result = $db->loadRowList();
}
break;
case 'Assoc':
default:
if ($firstOnly) {
$result = $db->loadAssoc();
} else {
$result = $db->loadAssocList();
}
break;
}
if (!$result) {
return false;
} else {
return $result;
}
}
示例12: defined
# Technical Support: Forum - http://www.ijoomla.com.com/forum/index/
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');
$plans = $this->plans;
$guruModelguruEditplans = new guruModelguruEditplans();
$config = $guruModelguruEditplans->getConfigs();
$currency = $config["0"]["currency"];
$character = JTExt::_("GURU_CURRENCY_" . $currency);
$course_id = intval(JRequest::getVar("course_id", "0"));
$action = JRequest::getVar("action", "");
$my = JFactory::getUser();
$user_id = $my->id;
$db = JFactory::getDBO();
$document = JFactory::getDocument();
jimport('joomla.language.helper');
$lang_value = JLanguageHelper::detectLanguage();
$lang = new JLanguage();
$lang->load('com_guru', JPATH_BASE, $lang_value);
$Itemid = JRequest::getVar("Itemid", "0");
?>
<link rel="stylesheet" href="<?php
echo JURI::root() . 'components/com_guru/css/uikit.almost-flat.min.css';
?>
"/>
<div id="g_content" class="gru-content">
<?php
if ($action == "") {
?>
<form action="<?php
示例13: initialiseApp
/**
* Initialise the application.
*
* @param array $options An optional associative array of configuration settings.
*
* @return void
*
* @since 3.2
*/
protected function initialiseApp($options = array())
{
$user = JFactory::getUser();
// If the user is a guest we populate it with the guest user group.
if ($user->guest) {
$guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
$user->groups = array($guestUsergroup);
}
// If a language was specified it has priority, otherwise use user or default language settings
JPluginHelper::importPlugin('system', 'languagefilter');
if (empty($options['language'])) {
// Detect the specified language
$lang = $this->input->getString('language', null);
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_language_filter && empty($options['language'])) {
// Detect cookie language
$lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect user language
$lang = $user->getParam('language');
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if ($this->_detect_browser && empty($options['language'])) {
// Detect browser language
$lang = JLanguageHelper::detectLanguage();
// Make sure that the user's language exists
if ($lang && JLanguage::exists($lang)) {
$options['language'] = $lang;
}
}
if (empty($options['language'])) {
// Detect default language
$params = JComponentHelper::getParams('com_languages');
$options['language'] = $params->get('site', $this->get('language', 'en-GB'));
}
// One last check to make sure we have something
if (!JLanguage::exists($options['language'])) {
$lang = $this->config->get('language', 'en-GB');
if (JLanguage::exists($lang)) {
$options['language'] = $lang;
} else {
// As a last ditch fail to english
$options['language'] = 'en-GB';
}
}
// Finish initialisation
parent::initialiseApp($options);
/*
* Try the lib_joomla file in the current language (without allowing the loading of the file in the default language)
* Fallback to the default language if necessary
*/
$this->getLanguage()->load('lib_joomla', JPATH_SITE, null, false, true) || $this->getLanguage()->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, true);
}
示例14: getLanguages
/**
* Generate a panel of language choices for the user to select their language.
*
* @return boolean True if successful.
*
* @since 3.1
*/
public function getLanguages()
{
/* @var InstallationApplicationWeb $app */
$app = JFactory::getApplication();
// Detect the native language.
$native = JLanguageHelper::detectLanguage();
if (empty($native)) {
$native = 'en-GB';
}
// Get a forced language if it exists.
$forced = $app->getLocalise();
if (!empty($forced['language'])) {
$native = $forced['language'];
}
// Get the list of available languages.
$list = JLanguageHelper::createLanguageList($native);
if (!$list || $list instanceof Exception) {
$list = array();
}
return $list;
}
示例15: parseRule
public function parseRule(&$router, &$uri)
{
$array = array();
$lang_code = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
if (!$lang_code) {
$lang_code = JLanguageHelper::detectLanguage();
}
if (self::$mode_sef) {
$path = $uri->getPath();
$parts = explode('/', $path);
$sef = $parts[0];
if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setPath($sef . '/' . $path);
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
$app = JFactory::getApplication();
if ($app->getCfg('sef_rewrite')) {
$app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
} else {
$app->redirect($uri->base() . 'index.php/' . $uri->toString(array('path', 'query', 'fragment')));
}
}
}
$lang_code = self::$sefs[$sef]->lang_code;
if ($lang_code && JLanguage::exists($lang_code)) {
array_shift($parts);
$uri->setPath(implode('/', $parts));
}
} else {
$sef = $uri->getVar('lang');
if (!isset(self::$sefs[$sef])) {
$sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
$uri->setVar('lang', $sef);
$post = JRequest::get('POST');
if (JRequest::getMethod() != "POST" || count($post) == 0) {
$app = JFactory::getApplication();
$app->redirect(JURI::base(true) . '/index.php?' . $uri->getQuery());
}
}
}
$array = array('lang' => $sef);
return $array;
}