No release in over 3 years
country/language names and 2-letter-code pairs, in 85 languages
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme
  • Present users coutries/languages in their language
  • Convert a country/language-name to its 2-letter-code
  • List of 2-letter-code/name pairs for all countries/languages in all languages

Translations

Through pkg-isocodes:

  • 185 Language codes (iso 639 - 2 letter) in 68 Languages
  • 246 Country codes (iso 3166 - 2 letter) in 86 Languages

Install

gem install i18n_data

Usage

require 'i18n_data'
...
I18nData.languages           # {"DE"=>"German",...}
I18nData.languages('DE')     # {"DE"=>"Deutsch",...}
I18nData.languages('FR')     # {"DE"=>"Allemand",...}
I18nData.languages('ZH-CN')  # {"DE"=>"德语",...}
...

I18nData.countries           # {"DE"=>"Germany",...}
I18nData.countries('DE')     # {"DE"=>"Deutschland",...}
I18nData.countries('ZH-CN')  # {"DE"=>"德国",...}
...

I18nData.language_code('German')       # DE
I18nData.language_code('Deutsch')      # DE
I18nData.language_code('Allemand')     # DE
..

I18nData.country_code('Germany')       # DE
I18nData.country_code('Deutschland')   # DE
..

Language Variants

While translations to language variants like ZH-CN are provided, translations of the names of those variants are not. In other words, while I18nData.languages('ZH_CN')['DE'] will give you the Chinese (as written in China) name of the German language ("德国"), the German name of the Chinese (as written in China) language is not provided.

Where the variant represents a country, you are able to combine the translations of the names of languages and countries (e.g. "#{I18nData.languages('DE')['ZH']} (#{I18nData.countries('DE')['CN']})" gives "Chinesisch (China)"), but there is no guarantee this will be correct gramatically or conceptionally in that language.

Data Providers

  • FileDataProvider: FAST (default) (loading data from cache-files)
  • LiveDataProvider: SLOW (fetching up-to-date data from svn repos)

Development

  • update FileDataProvider caches after each code-change to make changes available to users rake write_cache_for_file_data_provider
  • FileDataProvider tests might fail if caches are not updates

Alphabetical localized sorting

If you would like to have the countries list sorted alphabetically in different languages there is a gem called sort_alphabetical for that.

TODO

  • include other language/country code formats (3-letter codes...) ?
  • parse list of files on isocodes for write_cache instead of hardcoding country-specific ones
  • rake task that checks that the readme is updated with language/country counters

Authors

Michael Grosser
michael@grosser.it
License: MIT
CI