Rails i18n

581 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
581
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Rails i18n

    1. 1. rambling on rails’ i18n décousue discussion à propos de rails i18n
    2. 2. SRC 2012 Reject Conf Starring Alan GardnerTICKETS AVAILABLE NOW! http://j.mp/scotruby-reject
    3. 3. rambling on rails’ i18n décousue discussion à propos de rails i18n
    4. 4. i18n l10n- wtf?internationalisation is the process of preparing yourapplication for localisationlocalisation is the process of providing locale / languagespecific content within your internationalised applicationyou internationalise so that you can localise
    5. 5. Internationalisation in Railsbaked in, which is great!easy to get started withplenty of documentation
    6. 6. Contrived Overview!
    7. 7. Where the magic happensRails 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 fewlanguages including translations of Active Record’s errormessages, saving you effort
    8. 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. 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. 10. What’s that given us?Three different locales, each with a localised value for theinternationalised key ‘:good_afternoon’A controller which will serve up this localised value whensomeone visits itThe default locale is ‘en’ so the user will see ‘goodafternoon’
    11. 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. 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. 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. 14. So that’s the basics
    15. 15. It’s actually quite hard
    16. 16. Here’s the fluffy bit
    17. 17. Whys and Whatforsmore people don’t speak English than do - why limit youraudience?being forced to think about how information will bepresented in various locales is a fun-fun challengeit forces you to move view-level detail out into dictionariesand away from your models and such - this is good!
    18. 18. Whys and Whatforsit’s hard work to internationalise everything but reallyrewarding if you have the need to do ityou’ll know yourself if the project you’re working with needsto be i18n’dpersonally, I always default to i18ning everything, but that’sbecause I’m a masochist
    19. 19. Further ReadingRails i18n guide: http://guides.rubyonrails.org/i18n.htmlRails i18n locales repository https://github.com/svenfuchs/rails-i18nRuby i18n wiki: http://ruby-i18n.org/wiki
    20. 20. Got any questions?I’ve not covered a lot, ask about specifics!
    21. 21. ありがとう!@ryanstenhouse on Twitter@HHRy on GitHubhttp://ryanstenhouse.eu

    ×