In Ruby I can't find any localization modules. Are there any or should I use some external library? I have found I18n gem but I don't know if I can use it in standalone application (without Rails). Moreover I need some methods to localize floats and I can't see it in I18n gem.
Asked
Active
Viewed 696 times
2 Answers
3
Have you tried r18n?
It also localizes floats:
https://github.com/ai/r18n/blob/master/r18n-core/spec/locale_spec.rb

José Ricardo
- 1,479
- 1
- 14
- 28
2
There is no localization module in the Ruby stdlib. You can use the i18n
gem outside Rails, which is probably most downloaded and popular internationalization plugin for Ruby.
If you're looking for a more lightweight version, I recently released MiniI18n: a simple, flexible and fast Ruby internationalization and localization library. It also supports dates and numbers localization, interpolations, pluralization, fallbacks, nested keys and more. Its API is quite similar to i18n
library. See benchmark here.
Translations examples:
>> MiniI18n.t(:hello)
=> "Hello"
>> MiniI18n.t(:hello_with_name, name: 'John Doe')
=> "Hello John Doe"
>> MiniI18n.t('notifications.unread', count: 0)
=> "no unread notifications"
>> MiniI18n.t([:hello, :bye])
=> ["Hello", "Bye"]
Number localization examples:
>> MiniI18n.l(1000.5)
=> "1,000.5"
>> MiniI18n.l(1000.5, as: :currency)
=> "1,000.5 $"
Date localization examples:
>> MiniI18n.l(Date.new(2018, 8, 15))
=> "Wednesday 15, August, 2018"
>> MiniI18n.l(Date.new(2018, 8, 15), format: :short)
=> "15 Aug 18"

markets
- 6,709
- 1
- 38
- 48