ruby-on-railsinternationalizationrubygemsrails-i18ncountries

RAILS - How to fix I18n NoTranslationAvailable when using ISO3166::Country


I'm using https://rubygems.org/gems/countries in a project and trying to get all countries names using a locale string for translations.

The locale 'DE', 'NO' or others are coming from the Google OCR API. The gem also has a method: ISO3166::Country.translations, which will return all the locale strings and the matching country, like: "AL"=>"Albania".

In this list, there is also featured the translation "NO"=>"Norway", but when using ISO3166::Country.all_translated('NO'), an error is thrown: I18nData::NoTranslationAvailable: I18nData::NoTranslationAvailable -- countries-NO.

Is there any workaround or fix to use all languages and get all translations? Or at least how is Norway not in the locales? The gem I think uses I18n as it's mentioned in the error, and the :no locale is not valid into I18n:

I18n.locale = :no => I18n::InvalidLocale: :no is not a valid locale

I18n.locale = :de => :de


Solution

  • Norwegian i18n locales are :nn (Nynorsk) and :nb (Bokmål), not :no.

    i18n uses countries-NN.txt and countries-NB.txt

    So need to use ISO3166::Country.all_translated('NN') and ISO3166::Country.all_translated('NB')