Class: Jekyll::L10n::LocaleNameResolver
- Inherits:
-
Object
- Object
- Jekyll::L10n::LocaleNameResolver
- Defined in:
- lib/jekyll-l10n/utils/locale_name_resolver.rb
Overview
Resolves a canonical locale code into a human-readable display name using
ISO 639-1 language names and ISO 3166-1 country names from the locale gem.
Supported input forms:
- Language-only: "es" → "Spanish"
- Language + country subtag (POSIX underscore form): "es_ES" → "Spanish (Spain)", "pt_BR" → "Portuguese (Brazil)"
Falls back to the raw code segment when the locale gem cannot resolve a
language or region code. This is a defensive-only path — every locale that
reaches this class from plugin-managed configuration has already passed
Constants::LOCALE_PATTERN validation, so unknown codes are not expected
in normal operation.
Class Method Summary collapse
-
.resolve(locale) ⇒ String
Resolve a canonical locale code to a human-readable display name.
Class Method Details
.resolve(locale) ⇒ String
Resolve a canonical locale code to a human-readable display name.
41 42 43 44 45 46 47 48 |
# File 'lib/jekyll-l10n/utils/locale_name_resolver.rb', line 41 def self.resolve(locale) language_code, country_code = locale.to_s.split('_', 2) language_name = Locale::Info.get_language(language_code)&.name || language_code return language_name unless country_code country_name = Locale::Info.get_region(country_code)&.name || country_code "#{language_name} (#{country_name})" end |