<html class="no-js" xmlns="http://www.w3.org/1999/xhtml" lang="<?=Language::getActive()?>">
<?php
class Language
{
private static $defaultLanguage='ru';
private static $siteLanguages = array('ru','en','tr','de','fr','it','es','pl','ua');
static function getHreflang()
{
$sn=$_SERVER['SERVER_NAME'];
$path=parse_url($_SERVER['REQUEST_URI'])['path'];
$links='';
// $links = "<link rel='alternate' href='https://".(strlen(explode('.',$sn)[0])==2 ? substr($sn,3) : $sn)."' hreflang='x-defaul' /> ";
foreach(self::getList() as $lang){
if($lang=='ua')
{
$lang='uk';
}
$prefix=$lang!='ru'?$lang.'.':'';
$link = $prefix.(strlen(explode('.',$sn)[0])==2 ? substr($sn,3) : $sn);
$links.=" <link rel='alternate' href='https://".$link.$path."' hreflang='".$lang."' /> ";
}
return $links;
}
static function getActive(){
$lang=explode('.',$_SERVER['SERVER_NAME'])[0];
if($lang=='m')
{
$lang=explode('.',$_SERVER['SERVER_NAME'])[1];
}
return in_array($lang, self::$siteLanguages) ? $lang : self::$defaultLanguage;
}
static function getList(){
return self::$siteLanguages;
}
static function getHtmlList($wrapTag = '', $wrapParams = array()){
$wrapParams["class"]="jsLangPick";
foreach(self::getList() as $lang){
$wrapParams["data-lang"]=$lang;
echo ($wrapTag ? CHtml::openTag($wrapTag, $wrapParams) : '')
. L::t($lang)
. ($wrapTag ? CHtml::closeTag($wrapTag, $wrapParams) : '');
}
}
}