Rails on the Run

Rails experiments by Matt Aimonetti

Browsing Posts tagged globalite

I’m glad to announce a major update of Globalite.

First off I’d like to thank all the translators who helped with this release.

  • Globalite now support its first Asian language: Chinese!
    Ivan Chang did an awesome job creating a localization file in Chinese for Taiwan, Hong Kong and Main Land China. I’m really glad thinking that Globalite will make the Rails experience much nicer for a lot of Chinese people.

  • Ivan also pushed me to add a new feature that people had asked about: a better ActiveRecord error message support.

You know how Rails has a nice way of displaying your Model errors:


Well, now that’s automatically translated in your locale. (as long as the new localization files are up to date. Feel free to contact me if you want to improve the locale file in your own language)

  • I also added support for pluralization directly in the translation file. (pluralization doesn’t always make sense in some languages) I’m planning on adding a better Inflector support later on.

for now, in your translation file simply use:

horse_count: we have pluralize{{count}, horse} in the ranch

In your view use the localization with arguments to pass the count:

<%= :horse_count.l_with_args({:count => @horse.count}) %>

See the wiki for more information about pluralization.

  • Finally the demo app has been updated with an example of how to grab the acceptable locale from the header. (thanks to Emmanuel Bouton)

I’m almost ready to update Globalite with 2 major changes:

  • Support for Chinese (Taiwan, Hong Kong and main land China) thanks to Ivan Chang
  • Better support for Active Record error messages in forms (based on contribution from Ivan)

I’m writing more tests and updating the sample app before releasing the updated version. It should be out in the next few days.

[Globalite page @ Google Code](http://code.google.com/p/globalite/

If you haven’t check out the Globalite sample app yet, here are some screenshots.

Here is the French yml file used for the UI translation/localization:

create a yml file with the translation

Here is the code to display a select box so the user can choose the publication date:

write some code to let the user choose a published date

So you know,

<%= :published_date.l %>

is the same as

<%= :published_date.localize %>

Globalite will try to load the translation of the :published_date key using the locale you set. (if you didn’t set a locale, it will try in English. If there was no English translation available, a warning message would be displayed instead of the translation. We could have also done the following:

<%= :published_date.l('Published Date') %>

If you pass a string to the localization function, Globalite will display it in the case where it doesn’t find a translation.

Here is the default view in English:

let's look at the view in English (default locale)

Change the locale to French ( Locale.code = ‘fr-*’ or use the select box in the demo app).
Let’s display the same page:

same date select box in French

Note that in French, the date is different, on top of having translated month names, the order is different. American English format is year/month/day while the French format is day/month/year.

You get all of that for free and even more.

Just for the fun, here is another example of localization: currency. you might know it, but each country, on top of having a different currency display numbers differently.

In the England, it would look like that:


Note that the currency is before the amount and that there’s a separator for the thousands and a delimiter for the pence.

In France, it would look like that:


The currency is after the amount and the French separator is actually the British delimiter and vice versa!

Spain also uses the Euro as currency but they don’t display the same amount in the same way:


The code to display the amount for each locale is the following:

<%= number_to_currency(9999.99) %>

Pretty cool and simple, isn’t it? Check out the sample app for more advance used.


p.s: thanks josh knowles for the skitch invite, it’s awesome!