Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby I18n alternatives

Are there in the world any I18n alternatives?

I just do not like the way I18n stores the translation keys. I would like to store and use them just as Magento does - key is simply a string that i want to show using English locale, for example.

So when i want to translate it i just provide the file with the proper locale name (nl_NL.csv) with the simple key-value format, where the key is my English string i want to translate to Dutch (in the case of nl_NL locale) and the value is the Dutch analogue for my phrase. And if Magento does not finds either the translation file or the translation key - it displays the key itself. And whilst the key is the English phrase, my HTMl shall "fall back" to the English locale.

I've seen some ways to override the default I18n behavior (fast-gettext gem or custom I18n backend), but are there no gems as i described above?

like image 603
shybovycha Avatar asked Jun 27 '26 07:06

shybovycha


2 Answers

Ruby i18n provides a bunch of backends out of the box, including a gettext implementation. Should be as simple as.

I18n::Backend::Simple.include(I18n::Backend::Gettext)

If you don't like the default gettext implementation, it should at least provide a starting point to write your own. If you wanted to extend or replace the Simple backend to store keys or perform lookups differently, that should also be doable. The simple backend is in fact quite simple, at under 100 loc.

like image 84
numbers1311407 Avatar answered Jun 28 '26 20:06

numbers1311407


With fast_gettext you can translate like this: _("Hello world!") and it has an optional web interface http://github.com/grosser/translation_db_engine (screenshot: http://renderedtext.com/images/blog/2012-10-02/welcome_translations.png) and supports several backends, so probably it'd be possible to add a .csv backend.

Advanced options:

  • http://tr8n.github.io/ gives some automagic help with plural, etc
  • https://github.com/nijel/weblate integrates with git

Some other ideas are at http://ruby-i18n.org/wiki

like image 42
Simon B. Avatar answered Jun 28 '26 20:06

Simon B.