SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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

Weitere ähnliche Inhalte

Andere mochten auch

50 million missing women
50 million missing women50 million missing women
50 million missing women
Mitu Khosla
 
Sarifna Blogspot
Sarifna BlogspotSarifna Blogspot
Sarifna Blogspot
Sarifna
 
Presentacion en power point
Presentacion en power pointPresentacion en power point
Presentacion en power point
fvalarezo03
 
asd Practicepowerpoint
asd Practicepowerpointasd Practicepowerpoint
asd Practicepowerpoint
Kinjal Gor
 
Anticonceptivos
AnticonceptivosAnticonceptivos
Anticonceptivos
erikawera
 

Andere mochten auch (18)

Diriodeumco
DiriodeumcoDiriodeumco
Diriodeumco
 
Testing Equipment
Testing EquipmentTesting Equipment
Testing Equipment
 
My visit to nepal
My visit to nepalMy visit to nepal
My visit to nepal
 
50 million missing women
50 million missing women50 million missing women
50 million missing women
 
Double vision
Double visionDouble vision
Double vision
 
Sarifna Blogspot
Sarifna BlogspotSarifna Blogspot
Sarifna Blogspot
 
Systems Technology Forum Construction Documents
Systems Technology Forum Construction DocumentsSystems Technology Forum Construction Documents
Systems Technology Forum Construction Documents
 
Presentacion en power point
Presentacion en power pointPresentacion en power point
Presentacion en power point
 
Portable metal hardness testers
Portable metal hardness testersPortable metal hardness testers
Portable metal hardness testers
 
Dossier de production
Dossier de productionDossier de production
Dossier de production
 
Testing/Manufacture/Hepa Filter Packaging Tester
Testing/Manufacture/Hepa Filter Packaging TesterTesting/Manufacture/Hepa Filter Packaging Tester
Testing/Manufacture/Hepa Filter Packaging Tester
 
asd Practicepowerpoint
asd Practicepowerpointasd Practicepowerpoint
asd Practicepowerpoint
 
Testing/Manufacture/Footwear Testing Equipments
Testing/Manufacture/Footwear Testing EquipmentsTesting/Manufacture/Footwear Testing Equipments
Testing/Manufacture/Footwear Testing Equipments
 
SIS
SISSIS
SIS
 
Anticonceptivos
AnticonceptivosAnticonceptivos
Anticonceptivos
 
Testing/Manufacture/PlasticTesting Equipmetns
Testing/Manufacture/PlasticTesting EquipmetnsTesting/Manufacture/PlasticTesting Equipmetns
Testing/Manufacture/PlasticTesting Equipmetns
 
Testing/Manufacture/Closed and open cells content
Testing/Manufacture/Closed and open cells contentTesting/Manufacture/Closed and open cells content
Testing/Manufacture/Closed and open cells content
 
Testing/Manufacture/Paper Testing Equipments
Testing/Manufacture/Paper Testing EquipmentsTesting/Manufacture/Paper Testing Equipments
Testing/Manufacture/Paper Testing Equipments
 

Ähnlich wie Rails i18n

Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
adunne
 
I18n
I18nI18n
I18n
soon
 
KazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo ScalabilityKazooCon 2014 - Kazoo Scalability
KazooCon 2014 - Kazoo Scalability
2600Hz
 

Ähnlich wie Rails i18n (20)

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

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

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

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n