rambling on rails’ i18n
  décousue discussion à propos de rails i18n
SRC 2012 Reject Conf
          Starring Alan Gardner


TICKETS AVAILABLE NOW!
  http://j.mp/scotruby-reject
rambling on rails’ i18n
  décousue discussion à propos de rails i18n
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
Internationalisation in Rails

baked in, which is great!
easy to get started with
plenty of documentation
Contrived Overview!
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
Boilerplate
     #in config/locales/en.yml

     en:
       good_afternoon: good afternoon


     #in config/locales/fr.yml

     fr:
       good_afternoon: bonjour


     #in config/locales/ja.yml

     ja:
       good_afternoon: こにちわ
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
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’
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
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
So now what?

http://localhost:3000/?locale=fr would see “bonjour”
http://localhost:3000/?locale=jp would see “こにちわ”

Anyone else would see “good afternoon”
So that’s the basics
It’s actually quite hard
Here’s the fluffy bit
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!
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
Further Reading

Rails i18n guide: http://guides.rubyonrails.org/i18n.html
Rails i18n locales repository https://github.com/svenfuchs/
rails-i18n
Ruby i18n wiki: http://ruby-i18n.org/wiki
Got any questions?
I’ve not covered a lot, ask about specifics!
ありがとう!

@ryanstenhouse on Twitter
@HHRy on GitHub
http://ryanstenhouse.eu

More Related Content

PDF
Internationalization in Rails 2.2
PPTX
Shipping your product overseas!
PDF
Concurrency, Robustness & Elixir SoCraTes 2015
PDF
I18n in Rails2.2
PDF
Elixir and OTP
PDF
Persian A1- Book1 lesson 2
PDF
Concurrency in Elixir with OTP
PDF
Building A Great API - Evan Cooke, Cloudstock, December 2010
Internationalization in Rails 2.2
Shipping your product overseas!
Concurrency, Robustness & Elixir SoCraTes 2015
I18n in Rails2.2
Elixir and OTP
Persian A1- Book1 lesson 2
Concurrency in Elixir with OTP
Building A Great API - Evan Cooke, Cloudstock, December 2010

Viewers also liked (18)

PPS
Diriodeumco
PPT
Testing Equipment
PPTX
My visit to nepal
PDF
50 million missing women
PPS
Double vision
PPT
Sarifna Blogspot
PDF
Systems Technology Forum Construction Documents
PPTX
Presentacion en power point
PPTX
Portable metal hardness testers
PDF
Dossier de production
PDF
Testing/Manufacture/Hepa Filter Packaging Tester
PPT
asd Practicepowerpoint
PDF
Testing/Manufacture/Footwear Testing Equipments
PPT
PPTX
Anticonceptivos
PDF
Testing/Manufacture/PlasticTesting Equipmetns
PDF
Testing/Manufacture/Closed and open cells content
PDF
Testing/Manufacture/Paper Testing Equipments
Diriodeumco
Testing Equipment
My visit to nepal
50 million missing women
Double vision
Sarifna Blogspot
Systems Technology Forum Construction Documents
Presentacion en power point
Portable metal hardness testers
Dossier de production
Testing/Manufacture/Hepa Filter Packaging Tester
asd Practicepowerpoint
Testing/Manufacture/Footwear Testing Equipments
Anticonceptivos
Testing/Manufacture/PlasticTesting Equipmetns
Testing/Manufacture/Closed and open cells content
Testing/Manufacture/Paper Testing Equipments
Ad

Similar to Rails i18n (20)

PDF
Internationalization in Rails 2.2
PDF
Ruby i18n - internationalization for ruby
PPTX
ColdBox i18N
PPTX
Multi Lingual Websites In Umbraco
PDF
Living in a multiligual world: Internationalization for Web 2.0 Applications
PDF
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
ODP
Developing Multilingual Applications
PDF
symfony : I18n And L10n
KEY
I18n
PPT
The Ruby On Rails I18n Core Api
PPTX
KazooCon 2014 - Kazoo Scalability
PDF
Lecture 1 Compiler design , computation
ZIP
Mojolicious
ODP
BIS07 Application Development - I
PPTX
API and Microservices Meetup - To Code or Low Code?
PDF
i18n was the missing piece_ make your apps accessible to 70%+ of the users in...
PDF
How To Build And Launch A Successful Globalized App From Day One Or All The ...
PPT
Internationalisation In Rails
PPTX
Internationalizing Your AngularJS App
Internationalization in Rails 2.2
Ruby i18n - internationalization for ruby
ColdBox i18N
Multi Lingual Websites In Umbraco
Living in a multiligual world: Internationalization for Web 2.0 Applications
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Developing Multilingual Applications
symfony : I18n And L10n
I18n
The Ruby On Rails I18n Core Api
KazooCon 2014 - Kazoo Scalability
Lecture 1 Compiler design , computation
Mojolicious
BIS07 Application Development - I
API and Microservices Meetup - To Code or Low Code?
i18n was the missing piece_ make your apps accessible to 70%+ of the users in...
How To Build And Launch A Successful Globalized App From Day One Or All The ...
Internationalisation In Rails
Internationalizing Your AngularJS App
Ad

Recently uploaded (20)

PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Tartificialntelligence_presentation.pptx
PDF
Hybrid model detection and classification of lung cancer
PPTX
observCloud-Native Containerability and monitoring.pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
CloudStack 4.21: First Look Webinar slides
PPT
Geologic Time for studying geology for geologist
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPT
What is a Computer? Input Devices /output devices
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
The various Industrial Revolutions .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Modernising the Digital Integration Hub
1 - Historical Antecedents, Social Consideration.pdf
A comparative study of natural language inference in Swahili using monolingua...
Tartificialntelligence_presentation.pptx
Hybrid model detection and classification of lung cancer
observCloud-Native Containerability and monitoring.pptx
Module 1.ppt Iot fundamentals and Architecture
DP Operators-handbook-extract for the Mautical Institute
CloudStack 4.21: First Look Webinar slides
Geologic Time for studying geology for geologist
Getting started with AI Agents and Multi-Agent Systems
Final SEM Unit 1 for mit wpu at pune .pptx
Zenith AI: Advanced Artificial Intelligence
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
What is a Computer? Input Devices /output devices
Group 1 Presentation -Planning and Decision Making .pptx
Benefits of Physical activity for teenagers.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
The various Industrial Revolutions .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Modernising the Digital Integration Hub

Rails i18n

  • 1. rambling on rails’ i18n décousue discussion à propos de rails i18n
  • 2. SRC 2012 Reject Conf Starring Alan Gardner TICKETS AVAILABLE NOW! http://j.mp/scotruby-reject
  • 3. rambling on rails’ i18n décousue discussion à propos de rails i18n
  • 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
  • 5. Internationalisation in Rails baked in, which is great! easy to get started with plenty of documentation
  • 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
  • 8. Boilerplate #in config/locales/en.yml en: good_afternoon: good afternoon #in config/locales/fr.yml fr: good_afternoon: bonjour #in config/locales/ja.yml ja: good_afternoon: こにちわ
  • 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
  • 13. So now what? http://localhost:3000/?locale=fr would see “bonjour” http://localhost:3000/?locale=jp would see “こにちわ” Anyone else would see “good afternoon”
  • 14. So that’s the basics
  • 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
  • 19. Further Reading Rails i18n guide: http://guides.rubyonrails.org/i18n.html Rails i18n locales repository https://github.com/svenfuchs/ rails-i18n Ruby i18n wiki: http://ruby-i18n.org/wiki
  • 20. Got any questions? I’ve not covered a lot, ask about specifics!
  • 21. ありがとう! @ryanstenhouse on Twitter @HHRy on GitHub http://ryanstenhouse.eu

Editor's Notes