Get language part of a Locale string (fr_FR => fr).
public static getLanguageFromLocale ( $locale ) : string | ||
$locale | ||
리턴 | string |
/** * Transform fr_FR to fr to fit the list of supported locales. * * @param $locale * * @return mixed */ protected function fixLocale($locale) { if (in_array($locale, $this->supportedLocales)) { return $locale; } if (($short = Fixer::getLanguageFromLocale($locale)) !== $locale) { if (in_array($short, $this->supportedLocales)) { return $short; } } // If no better locale found... return $locale; }
/** * Default configuration for supported lang. * * @param string $locale */ public function setLocale($locale) { // Handle from locale + country switch (strtolower($locale)) { // “…” case 'pt-br': $this->opening = Fixer::LDQUO; $this->openingSuffix = ''; $this->closing = Fixer::RDQUO; $this->closingPrefix = ''; return; } // Handle from locale only $short = Fixer::getLanguageFromLocale($locale); switch ($short) { // « … » case 'fr': $this->opening = Fixer::LAQUO; $this->openingSuffix = Fixer::NO_BREAK_SPACE; $this->closing = Fixer::RAQUO; $this->closingPrefix = Fixer::NO_BREAK_SPACE; break; // «…» // «…» case 'hy': case 'az': case 'hz': case 'eu': case 'be': case 'ca': case 'el': case 'it': case 'no': case 'fa': case 'lv': case 'pt': case 'ru': case 'es': case 'uk': $this->opening = Fixer::LAQUO; $this->openingSuffix = ''; $this->closing = Fixer::RAQUO; $this->closingPrefix = ''; break; // „…“ // „…“ case 'de': case 'ka': case 'cs': case 'et': case 'is': case 'lt': case 'mk': case 'ro': case 'sk': case 'sl': case 'wen': $this->opening = Fixer::BDQUO; $this->openingSuffix = ''; $this->closing = Fixer::LDQUO; $this->closingPrefix = ''; break; // “…” // “…” case 'en': case 'us': case 'gb': case 'af': case 'ar': case 'eo': case 'id': case 'ga': case 'ko': case 'br': case 'th': case 'tr': case 'vi': $this->opening = Fixer::LDQUO; $this->openingSuffix = ''; $this->closing = Fixer::RDQUO; $this->closingPrefix = ''; break; // ”…” // ”…” case 'fi': case 'sv': case 'bs': $this->opening = Fixer::RDQUO; $this->openingSuffix = ''; $this->closing = Fixer::RDQUO; $this->closingPrefix = ''; break; } }