4. i18n l10n- wtf?
internationalisation is the process of preparing your
application for localisation
localisation is the process of providing locale / language
specific content within your internationalised application
you internationalise so that you can localise
7. Where the magic happens
Rails automatically loads any .rb or .yml files in config/
locales and makes them available to the i18n and l10n APIs.
rails-i18n gem will give you locale files for a fair few
languages including translations of Active Record’s error
messages, saving you effort
9. Boilerplate
#in config/routes.rb
Example::Application.routes.draw do
root :to => ‘example#greet`
end
#in app/controller/example_controller
class ExampleController < ApplicationController
def greet
render :text => t(:good_afternoon)
end
end
10. What’s that given us?
Three different locales, each with a localised value for the
internationalised key ‘:good_afternoon’
A controller which will serve up this localised value when
someone visits it
The default locale is ‘en’ so the user will see ‘good
afternoon’
11. Make them go
#in app/controller/example_controller
class ExampleController < ApplicationController
def greet
I18n.locale = params[:locale] || ‘en’
render :text => t(:good_afternoon)
end
end
12. Make them go
#in app/controller/example_controller
class ExampleController < ApplicationController
def greet
I18n.locale = params[:locale] || ‘en’
render :text => t(:good_afternoon)
end
end
17. Whys and Whatfors
more people don’t speak English than do - why limit your
audience?
being forced to think about how information will be
presented in various locales is a fun-fun challenge
it forces you to move view-level detail out into dictionaries
and away from your models and such - this is good!
18. Whys and Whatfors
it’s hard work to internationalise everything but really
rewarding if you have the need to do it
you’ll know yourself if the project you’re working with needs
to be i18n’d
personally, I always default to i18ning everything, but that’s
because I’m a masochist