Skip to content
Ruby: country/language names and 2-letter-code pairs, in 85 languages, for country/language i18n
Branch: master
Clone or download
grosser Merge pull request #44 from grosser/grosser/live
make sure file data is updated
Latest commit 71b99c6 Jan 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cache/file_data_provider
example_output some more example output to show the possibilities Jan 10, 2009
lib v0.10.0 Jan 25, 2019
spec fix country code detection Jan 25, 2019
.gitignore
.travis.yml
Gemfile
Gemfile.lock v0.10.0 Jan 25, 2019
Rakefile
Readme.md make sure file data is updated Jan 28, 2019
gem-public_cert.pem
i18n_data.gemspec

Readme.md

  • 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
  • contry specific codes e.g. zh_TW are also available, have a look at the isocodes website for all options

Install

gem install i18n_data

Usage

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

I18nData.countries        # {"DE"=>"Germany",...}
I18nData.countries('DE')  # {"DE"=>"Deutschland",...}
...

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
..

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

Contributors

Michael Grosser
michael@grosser.it
License: MIT
Build Status

You can’t perform that action at this time.