/** * Convert a locale designation to a normal form ll_Ssss_CC, where * ll is language code * Ssss is the script code, if specified * CC is the country code, if specified * * @param string $locale locale code * @param string $separator string to use to join locale parts * @param bool $withScript include script if specified, always remove if false * * @return string normalized locale, or empty string on error */ public static function normalizeLocale($locale, $separator = '_', $withScript = true) { try { $keys = Data::explodeLocale($locale); $key = strtolower($keys['language']); $key .= empty($keys['script']) || false === $withScript ? '' : $separator . ucfirst(strtolower($keys['script'])); $key .= empty($keys['territory']) ? '' : $separator . strtoupper($keys['territory']); } catch (InvalidLocale $e) { $key = ''; } return $key; }