public
Description: Demo for Rails 2.2 internationalization & localization features
Homepage: http://www.karmi.cz
Clone URL: git://github.com/karmi/rails_i18n_demo_app.git
name age message
file .gitignore Loading commit data...
file README.rdoc Tue Mar 03 08:24:36 -0800 2009 Fixed typos. "Internalization" really has nothi... [karmi]
file README_FOR_RAILS Tue Aug 12 14:03:13 -0700 2008 Initial commit (working application) * http://... [karmi]
file Rakefile Tue Aug 12 14:03:13 -0700 2008 Initial commit (working application) * http://... [karmi]
directory app/ Fri May 01 09:44:42 -0700 2009 Err, fixing stupid code written in haste [karmi]
directory config/
directory db/ Tue Aug 12 14:03:13 -0700 2008 Initial commit (working application) * http://... [karmi]
directory doc/ Sat Nov 22 04:59:00 -0800 2008 More RDoc formatting; README_FOR_APP as symlink [karmi]
directory log/ Thu Aug 28 01:38:19 -0700 2008 Fixed .gitignore in log/ and /tmp [karmi]
directory public/
directory script/
directory test/
directory tmp/ Thu Aug 28 01:38:19 -0700 2008 Fixed .gitignore in log/ and /tmp [karmi]
directory vendor/ Thu Aug 28 01:38:19 -0700 2008 Fixed .gitignore in log/ and /tmp [karmi]
README.rdoc

Demo application for Rails internationalization API

Simple & minimal Rails application to test the internationalization and localization features of Rails 2.2 and later. I keep this application up-to-date with my current contract, so you can follow the commits for (possible) API changes and gotchas.

It shows how you can override Rails default locale/language (‘en’) in views, in ActiveRecord validation messages, etc. It shows you how to test internationalization features.

Tries to set some reasonable pattern to load translation files and set locale either from request domain (.com, .de, etc) or request params. Do not ever set locale to cookie or session, as it breaks basic assumptions about web. Read this discussion for context: groups.google.com/group/rails-i18n/browse_thread/thread/de73dbd1309ae640/

The application includes translation file for Czech language so you can easily roll your own Spanish, German, Polish, etc version just by duplicating the file, renaming it and changing the translation strings. After server restart you should see your language in language bar at the top of the page.

Installation & Requirements

  • Download & unpack archive or git clone from Github [github.com/karmi/rails_i18n_demo_app]
  • The application requires Rails version 2.2 or later. Either upgrade your Rails gem by running
      $ sudo gem update rails
    
  • or just download and freeze Rails into vendor/rails
      $ rake rails:freeze:edge RELEASE=2.2.2
    
  • Run migrations (to be able to test ActiveRecord message localizations) by rake db:migrate
  • Run script/server and point your browser at localhost:3000

About setting the locale from the request domain

Usually the most sane approach to setting locale/language version of the application is from the domain: application.com loads English, application.es Spanish. This works best for content heavy websites and search engines love it.

The ApplicationController#extract_locale_from_tld sets locale from the top-level domain (ie. the "es" in example.es loads Spanish version). To test this locally, you have to edit your /etc/hosts file by inserting lines like:

  127.0.0.1 application.com
  127.0.0.1 application.cz

Then just load your application as usual at application.cz:3000 or application.com:3000 and you should see the locale being switched.

About Rails i18n

See guide at guides.rails.info/i18n.html See www.rails-i18n.org for more info and get in touch at groups.google.com/group/rails-i18n