Low commit activity in last 3 years
A long-lived project that still receives updates
The purpose of this gem is to simply provide country translations. The gem is intended to be easy to combine with other gems that require i18n country translations so we can have common i18n country translation gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 0.1, >= 0.1.1
>= 7.2, < 9
~> 0.22

Runtime

>= 0.9.3, < 3
>= 7.2, < 9
 Project Readme

I18n Country Translations

Gem Version CI License: MIT

Country name translations for Rails and the i18n gem. If you're doing anything with country names and translations, there's no need to reinvent the wheel — just use this gem and skip the hassle of managing translations for each locale yourself.

Requirements

  • Ruby >= 3.1
  • Rails >= 7.2 (or railties >= 7.2)

Installation

Add to your Gemfile:

gem 'i18n-country-translations'

Translation data is provided by the i18n-country-translations-data gem, which is installed automatically as a dependency.

Usage

I18n.t(:US, scope: :countries)
# => "United States"

I18n.locale = :de
I18n.t(:US, scope: :countries)
# => "Vereinigte Staaten"

I18n.locale = :ja
I18n.t(:JP, scope: :countries)
# => "日本"

Or in Rails views:

t(:US, scope: :countries)

Supported Locales

168 locales sourced from Unicode CLDR, including all ISO 639-1 languages plus additional CLDR-supported locales.

Supported Country Codes

257 territory codes following ISO 3166-1 alpha-2 (all 248 officially assigned codes), plus these additional territory codes from Unicode CLDR: AC, CP, DG, EA, EU, IC, QO, TA, UM, XK.

How It Works

This gem uses a Railtie to automatically load translations after Rails initializes. Translations are loaded from the i18n-country-translations-data gem via I18n.backend.store_translations, scoped under countries:.

If your app sets config.i18n.available_locales, only the matching locales will be loaded.

Contributing

Translation data lives in the i18n-country-translations-data repo. To add or fix translations, submit a pull request there.

Running tests

bundle install
bundle exec rspec

Also Available for JavaScript

Related

License

MIT or GPL-3.0

Special Thanks