JoliTypo\Fixer::getLanguageFromLocale PHP Method

getLanguageFromLocale() public static method

Get language part of a Locale string (fr_FR => fr).
public static getLanguageFromLocale ( $locale ) : string
$locale
return string
    public static function getLanguageFromLocale($locale)
    {
        if (strpos($locale, '_')) {
            $parts = explode('_', $locale);
            return strtolower($parts[0]);
        }
        return $locale;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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;
 }
All Usage Examples Of JoliTypo\Fixer::getLanguageFromLocale