How to internationalize a a ruby gem?
-
09-02-2021 - |
Question
What is the best way to ship a gem with default i18n translations for strings used by it?
Solution
There are a couple of things you need to do :
- include
i18n
as a dependency - internationalize your gem by replacing strings with
I18n.t
calls - create a translation YAML file and add it to I18n's
load_path
(e.g.I18n.load_path += 'path/to/your/en.yml'
)
That's pretty much it, you can also set up a public project on Locale to crowdsource translations in other locales if you're so inclined.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow