Localized Frontend

gitorious.org/projects/localized-frontend/ github.com/leethal/localized-frontend/

Localizing the front-end of single language Rails apps.

The localizations are stored in YAML files. Create a spanish.yml file, call LocalizedFrontend.in :spanish somewhere in your app (probably in environment.rb or an initializer), and rejoice!

It localizes inflectors (pluralize, singularize etc), Active Record error messages, month and day names, form labels (<%= f.label :foo %>) and Array#to_sentence.

To contributors

Feel free to submit your own translations and localizations! You can mail me patches on [email protected], or you can fork the Git repository on github.com/leethal/localized-frontend/ and send a pull request. Or write it down on paper and mail it to me. Your call!

Keep in mind that the YAML file is whiny - certain keys and values are required in order to avoid errors being raised. At the moment, the tests are hardcoded in Norwegian. That should probably change, so that one can set the language in an environment variable and run the tests in whatever language one might prefer.

Also, the code is fairly hard to grok, as it’s mostly monkey patches. Feel free to improve the readability of the code!

What it does

Here’s a short list of features (examples are in norwegian)

Localizing %b, %B, %a and %A in Time#strftime, Date#strftime and DateTime#strftime

  • Time.now.strftime(‘%b’) => okt

  • Time.now.strftime(‘%b’) => oktober

  • Time.now.strftime(‘%a’) => søn

  • Time.now.strftime(‘%A’) => søndag

Localized inflections. “bil”.pluralize => “biler”

Localizing attribute names in ActiveRecord.

class Question < ActiveRecord::Base
  localized_fields :question => "Spørsmål", :answer => "Svar"
end

TODO

  • Make tests runnable in any language. In other words, don’t let tests be hardcoded in Norwegian.

Copyright © 2008 August Lilleaas, released under the MIT license