Wednesday, February 18, 2009

internationalization


...since I'm going to have to speak Spanish in Alhambra, CA during the AT&T work stoppage... I might as well incorporate that into my web applications and "make lemonade" as the saying goes.

That's just a positive spin on having to go there. We coincidentally have homework due next week related to internationalization.

Been writing the Depot app via the PragProg book in Rails, but am doing so via Test Driven Development (slightly different from the book, per the awesome teaching of @tenderlove in the UWRails class -- this is the 2nd time I've taken this 3 month Rails class, and learning a ton more about Rails 2.2 and especially TDD)... am getting to the part where I'm incorporating internationalization.

I like this i18n features built into Rails, so I figured I'd blog about it, in case anyone else was interested: so certain items have translations. E.g. headers, titles, shopping carts, buttons, links -- not the data in the database, but all the labels and text that would help a user navigate through the application.

The translations are handled in a YAML file, which lets you call out the translation that matches it's hierarchy -- as shown below (Spanish, "es" shown here, there is an accompanying translation file for English, or "en"... could continue on as many languages as you wanted):


http://gist.github.com/66782

So the user sets their language preference via the dropdown (English is default, but they can choose whatever they want), then voila all labels that have a translation appear in that language selected! How does that work? Inside the code for all the pages, it just effectively says "give me whatever language is selected for layout.side.home, etc., and looks it up in the YAML file for that language above, grabs the matching value in that hierarchy, and out pops the word or phrase. For example, the markup for the sidebar links for "store", "questions", "news", "contact" look like this:

http://gist.github.com/66788

This is a common example, and almost identical to the example in the PragProg Agile Rails version 3 book -- maybe armed with this knowledge, I'll internationalize EyeOnMajors and Golfap as soon as it is riding on the Rails... :)

Giddyup.
Holts

2 comments:

SEO Services Consultants said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Web Design Company

rocky case said...

Stephen Stapinski

Really your blog is very interesting.... it contains great and unique information. I enjoyed to visiting your blog. It's just amazing.... Thanks very much for the share.