Fluent::locale_native_name PHP Method

locale_native_name() public static method

Fetch a native language string from the i18n class via a passed locale in the format "XX_xx". In the event a match cannot be found in any framework resource, an empty string is returned.
public static locale_native_name ( string $locale ) : string
$locale string e.g. "pt_BR"
return string The native language string for that locale e.g. "português (Brazil)"
    public static function locale_native_name($locale)
    {
        // Attempts to fetch the native language string via the `i18n::$common_languages` array
        if ($native = i18n::get_language_name(i18n::get_lang_from_locale($locale), true)) {
            return $native;
        }
        // Attempts to fetch the native language string via the `i18n::$common_locales` array
        $commonLocales = i18n::get_common_locales(true);
        if (!empty($commonLocales[$locale])) {
            return $commonLocales[$locale];
        }
        // Nothing else to go on, so return an empty string for a consistent API
        return '';
    }

Usage Example

 /**
  * Retrieves information about this object in the specified locale
  *
  * @param string $locale The locale information to request, or null to use the default locale
  * @return ArrayData Mapped list of locale properties
  */
 public function LocaleInformation($locale = null)
 {
     // Check locale
     if (empty($locale)) {
         $locale = Fluent::default_locale();
     }
     // Check linking mode
     $linkingMode = 'link';
     if ($this->owner->hasMethod('canViewInLocale') && !$this->owner->canViewInLocale($locale)) {
         $linkingMode = 'invalid';
     } elseif ($locale === Fluent::current_locale()) {
         $linkingMode = 'current';
     }
     // Check link
     $link = $this->owner->LocaleLink($locale);
     // Store basic locale information
     $data = array('Locale' => $locale, 'LocaleRFC1766' => i18n::convert_rfc1766($locale), 'Alias' => Fluent::alias($locale), 'Title' => i18n::get_locale_name($locale), 'LanguageNative' => Fluent::locale_native_name($locale), 'Link' => $link, 'AbsoluteLink' => $link ? Director::absoluteURL($link) : null, 'LinkingMode' => $linkingMode);
     return new ArrayData($data);
 }