Skip to content

Commit

Permalink
Merge pull request #131 from phptek/issue/130
Browse files Browse the repository at this point in the history
FIX: Fixes #135 Increased range of native lang strings.
  • Loading branch information
Damian Mooyman committed Jul 20, 2015
2 parents 32778f8 + 8faf636 commit 4a69d19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions code/Fluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ public static function locale_names() {
}
return $locales;
}

/**
*
* 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.
*
* @param string $locale 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 '';
}

/**
* Determine if the website is in domain segmentation mode
Expand Down
2 changes: 1 addition & 1 deletion code/extensions/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function LocaleInformation($locale = null) {
'LocaleRFC1766' => i18n::convert_rfc1766($locale),
'Alias' => Fluent::alias($locale),
'Title' => i18n::get_locale_name($locale),
'LanguageNative' => i18n::get_language_name(i18n::get_lang_from_locale($locale), true),
'LanguageNative' => Fluent::locale_native_name($locale),
'Link' => $link,
'AbsoluteLink' => $link ? Director::absoluteURL($link) : null,
'LinkingMode' => $linkingMode
Expand Down

0 comments on commit 4a69d19

Please sign in to comment.