简体   繁体   中英

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?

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM