Pimcore\Tool::getLanguageFlagFile PHP Method

getLanguageFlagFile() public static method

public static getLanguageFlagFile ( $language ) : string
$language
return string
    public static function getLanguageFlagFile($language)
    {
        $iconBasePath = PIMCORE_PATH . '/static6/img/flags';
        $code = strtolower($language);
        $code = str_replace("_", "-", $code);
        $countryCode = null;
        $fallbackLanguageCode = null;
        $parts = explode("-", $code);
        if (count($parts) > 1) {
            $countryCode = array_pop($parts);
            $fallbackLanguageCode = $parts[0];
        }
        $languagePath = $iconBasePath . "/languages/" . $code . ".svg";
        $countryPath = $iconBasePath . "/countries/" . $countryCode . ".svg";
        $fallbackLanguagePath = $iconBasePath . "/languages/" . $fallbackLanguageCode . ".svg";
        $iconPath = $iconBasePath . "/countries/_unknown.svg";
        $languageCountryMapping = ["aa" => "er", "af" => "za", "am" => "et", "as" => "in", "ast" => "es", "asa" => "tz", "az" => "az", "bas" => "cm", "eu" => "es", "be" => "by", "bem" => "zm", "bez" => "tz", "bg" => "bg", "bm" => "ml", "bn" => "bd", "br" => "fr", "brx" => "in", "bs" => "ba", "cs" => "cz", "da" => "dk", "de" => "de", "dz" => "bt", "el" => "gr", "en" => "gb", "es" => "es", "et" => "ee", "fi" => "fi", "fo" => "fo", "fr" => "fr", "ga" => "ie", "gv" => "im", "he" => "il", "hi" => "in", "hr" => "hr", "hu" => "hu", "hy" => "am", "id" => "id", "ig" => "ng", "is" => "is", "it" => "it", "ja" => "ja", "ka" => "ge", "os" => "ge", "kea" => "cv", "kk" => "kz", "kl" => "gl", "km" => "kh", "ko" => "kr", "lg" => "ug", "lo" => "la", "lt" => "lv", "mg" => "mg", "mk" => "mk", "mn" => "mn", "ms" => "my", "mt" => "mt", "my" => "mm", "nb" => "no", "ne" => "np", "nl" => "nl", "nn" => "no", "pl" => "pl", "pt" => "pt", "ro" => "ro", "ru" => "ru", "sg" => "cf", "sk" => "sk", "sl" => "si", "sq" => "al", "sr" => "rs", "sv" => "se", "swc" => "cd", "th" => "th", "to" => "to", "tr" => "tr", "tzm" => "ma", "uk" => "ua", "uz" => "uz", "vi" => "vn", "zh" => "cn", "gd" => "gb-sct", "gd-gb" => "gb-sct", "cy" => "gb-wls", "cy-gb" => "gb-wls", "fy" => "nl", "xh" => "za", "yo" => "bj", "zu" => "za", "ta" => "lk", "te" => "in", "ss" => "za", "sw" => "ke", "so" => "so", "si" => "lk", "ii" => "cn", "zh-hans" => "cn", "sn" => "zw", "rm" => "ch", "pa" => "in", "fa" => "ir", "lv" => "lv", "gl" => "es", "fil" => "ph"];
        if (array_key_exists($code, $languageCountryMapping)) {
            $iconPath = $iconBasePath . "/countries/" . $languageCountryMapping[$code] . ".svg";
        } elseif (file_exists($languagePath)) {
            $iconPath = $languagePath;
        } elseif ($countryCode && file_exists($countryPath)) {
            $iconPath = $countryPath;
        } elseif ($fallbackLanguageCode && file_exists($fallbackLanguagePath)) {
            $iconPath = $fallbackLanguagePath;
        }
        return $iconPath;
    }

Usage Example

コード例 #1
0
ファイル: MiscController.php プロジェクト: pimcore/pimcore
 public function getLanguageFlagAction()
 {
     $iconPath = Tool::getLanguageFlagFile($this->getParam("language"));
     if (Tool\Admin::isExtJS6()) {
         header("Content-Type: image/svg+xml");
     } else {
         header("Content-Type: image/png");
     }
     echo file_get_contents($iconPath);
     exit;
 }
All Usage Examples Of Pimcore\Tool::getLanguageFlagFile