Rails on the Run

Rails experiments by Matt Aimonetti

Browsing Posts tagged globalite

I recently received quite a lot of love because of Globalite. Even though I tried to write some documentation about the plugin, I know that there’s not much. I also know that there’s a difference between showing how to set a locale and how to actually use that code in a real application.

To fill this gap I wrote a very simple and rough Rails sample application with a fully localized User Interface:

UI Localization sample app

Looking at the code you will find out how to:

  • use a different css per locale (language/country)
  • use a different picture per locale
  • set a default css/picture if the translator doesn’t specify one
  • UI localization
  • rails core localization examples
  • create a select box of available UI translations
  • get/set the locale only a specific user so other users start by seeing the default translation
  • use a translation with many dynamic arguments
  • nested translation

note: I froze Edge for this sample app (it wasn’t required, Globalite works well with older version of Rails).

To install and run the app, just do the following:

$ svn checkout http://globalite.googlecode.com/svn/sample/ui globalite-sample-app

edit config/database.example and rename it config/database.yml

$ rake db:create

$ rake db:migrate

$ ruby script/server

Don’t hesitate to leave a comment, submit a Rails core localization file in your language or submit a bug

Today I updated Globalite, refactoring the code and fixing some issues.

I added a bunch of aliases since I was tired of typing:

Globalite.current_language = :fr

I shortened it to

Globalite.language = :fr

But the old method is still available so it won’t break your code ;)

The major change with this update is a better support for locales. Let’s say that in our application we setup the language to :fr (French) but we didn’t specify a country. Remember that Globalite lets you have specific translations/localizations per country so you can display dates, prices properly.

Previously, if my locale was set to :fr-* then Globalite would try to load the fr.yml files and not fr-FR.yml.

If you decided to use a fr.yml file for your UI localization, you might have noticed that all the Rails core messages weren’t translated(now you know why). This update deals with this issue and if a translation isn’t found in your locale, it will look for translations in your language but from a different country and pick a random one.

I’m expecting Rails core translations in Japanese, Korean and Chinese. Feel free to email me your own file and let me know on what project you used Globalite.

Globalite contributor: Marcus Derencius just submitted a Portuguese translation for Rails.

Your application can now speak Portuguese thanks to Globalite and Marcus :)