Globalite - usage example
Written by matt on July 2nd, 2007
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:

Here is the code to display a select box so the user can choose the publication 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:

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

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.
Enjoy
p.s: thanks josh knowles for the skitch invite, it's awesome!
Comments
-
Since your blog reposted all its articles again to RSS :) I saw this article again. It definitely looks nice. Might be cool for someone to write some refactoring tools for TextMate etc to click on existing strings, "Extract to en.yml" and they'd be replaced by a symbol. That'd help with migration of existing code.
-
Very good point, thanks! I'm also planning on creating some aliases so you could easily port your project from Globalize to globalite. :)
-
Im trying to add a new language called "marathi" i have created an mr.yml file for that its showing me all the things in marathi but only when i click on new page its giving me the error can't convert Symbol into String for <%= f.date_select :published_date %>
-
Kedar, you also need to translate the rails core localization file (see vendor/plugins/globalite/lang/rails/en-UK.yml ) and add your translated file called mr.yml or mr-IN.yml in the vendor/plugins/globalite/lang/rails/ folder. Matt
-
Thanks Sir now its working properly
-
Actually, in Spain we use exactly the same format for euros as in France. Where did you get the idea that we put the euro symbol in front?
-
arg, can you submit a proper spanish file? I got the info form Ikea site: http://www.ikea.com/es/es/catalog/categories/rooms/living_room/10382/
arg, I also need to fix this stupid comment box :(


