I searched the Internet in vain for examples of using the Ruby i18n gem outside of Rails apps.
Below is a minimal example: the aim is (as usual) to produce a greeting - this time in English and Italian.
$ gem install i18n
The most common use of i18n is via
I18n.translate which has an abbreviated alias
These translations can be accessed as follows: I18n.t( ‘hello world’ )
That will use the current locale setting. You can change it as follows: I18n.locale = :it
After loading the
i18n gem, set up
I18n.load_path before attempting to retrieve any transaltions.
1 2 3 4 5 6 7 8 9 10 11 12
$ ruby salutation.rb In English... Hello World! In Italian... Ciao Mondo!