如何检测Joomla的当前语言!网站? [英] How to detect the current language of a Joomla! website?
问题描述
我只想生成一个代码,以检测joomla + php中我的网站的当前语言
I just want to generate a code that will detect the current language of my websit in joomla + php
推荐答案
请参见 JFactory中的getLanguage :
$lang = JFactory::getLanguage();
echo 'Current language is: ' . $lang->getName();
有了语言后,您还可以检索语言环境/语言代码(例如en-US
). Joomla!语言可以具有多个语言环境,因此您将获得一个数组.
Once you have the language, you can also retrieve the locale/language code (e.g. en-US
). Joomla! languages can have multiple locales, so you'll get an array.
$lang = JFactory::getLanguage();
foreach($lang->getLocale() as $locale) {
echo 'This language supports the locale: ' . $locale;
}
如果由于某种原因,您只对第一个语言环境感兴趣,则可以简单地获取第一个元素.您可能需要一个数组,如下所示:
If for some reason, you are only interested in the first locale, you can simply grab the first element. You will probably need an array, like this:
$lang = JFactory::getLanguage();
$locales = $lang->getLocale();
echo 'This language\'s first locale is: ' . $locales[0];
如果您只想获取所选的语言标签(例如pt-PT),则可以使用getTag()
If you just want to get the selected language tag (e.g. pt-PT) you can use getTag()
$lang = JFactory::getLanguage();
echo 'Current language is: ' . $lang->getTag();
这篇关于如何检测Joomla的当前语言!网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!