Module: TwitterCldr::Shared::Territories
- Defined in:
- lib/twitter_cldr/shared/territories.rb
Class Method Summary collapse
- .all ⇒ Object
- .all_for(code) ⇒ Object
- .from_territory_code(territory_code) ⇒ Object
-
.from_territory_code_for_locale(territory_code, locale = TwitterCldr.locale) ⇒ Object
Returns how to say a given territory in a given locale.
-
.translate_territory(territory_name, source_locale = :en, dest_locale = TwitterCldr.locale) ⇒ Object
Translates territory_name from source_locale to dest_locale.
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/twitter_cldr/shared/territories.rb', line 12 def all all_for(TwitterCldr.locale) end |
.all_for(code) ⇒ Object
16 17 18 19 20 |
# File 'lib/twitter_cldr/shared/territories.rb', line 16 def all_for(code) get_resource(code)[:territories] rescue {} end |
.from_territory_code(territory_code) ⇒ Object
22 23 24 |
# File 'lib/twitter_cldr/shared/territories.rb', line 22 def from_territory_code(territory_code) from_territory_code_for_locale(territory_code, TwitterCldr.locale) end |
.from_territory_code_for_locale(territory_code, locale = TwitterCldr.locale) ⇒ Object
Returns how to say a given territory in a given locale.
This method does not work for three-digit United Nation “area codes” (UN M.49; for example, 014 for Eastern Africa and 419 for Latin America).
31 32 33 34 35 |
# File 'lib/twitter_cldr/shared/territories.rb', line 31 def from_territory_code_for_locale(territory_code, locale = TwitterCldr.locale) get_resource(locale)[:territories][TwitterCldr::Utils::Territories.normalize_territory_code(territory_code)] rescue nil end |
.translate_territory(territory_name, source_locale = :en, dest_locale = TwitterCldr.locale) ⇒ Object
Translates territory_name from source_locale to dest_locale.
This method does not work for three-digit United Nation “area codes” (UN M.49; for example, 014 for Eastern Africa and 419 for Latin America).
42 43 44 45 46 47 48 49 |
# File 'lib/twitter_cldr/shared/territories.rb', line 42 def translate_territory(territory_name, source_locale = :en, dest_locale = TwitterCldr.locale) territory_code, _ = get_resource(source_locale)[:territories].find do |_, other_territory_name| other_territory_name.downcase == territory_name.downcase end get_resource(dest_locale)[:territories][territory_code] if territory_code rescue nil end |