我只想生成一个代码,它会在joomla + php中检测我的websit的当前语言
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! 语言可以有多个地区,所以你会得到一个数组。
$lang = JFactory::getLanguage(); foreach($lang->getLocale() as $locale) { echo 'This language supports the locale: ' . $locale; }如果由于某种原因,您只对第一个区域感兴趣,您可以简单地抓住第一个区域。 你可能需要一个数组,像这样:
$lang = JFactory::getLanguage(); $locales = $lang->getLocale(); echo 'This language\'s first locale is: ' . $locales[0];如果您只想获取所选的语言标签(例如pt-PT),则可以使用getTag()
$lang = JFactory::getLanguage(); echo 'Current language is: ' . $lang->getTag();See getLanguage in JFactory:
$lang = JFactory::getLanguage(); echo 'Current language is: ' . $lang->getName();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];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();更多推荐
发布评论