• Like
  • Save
Rails i18n
Upcoming SlideShare
Loading in...5
×
 

Rails i18n

on

  • 564 views

 

Statistics

Views

Total Views
564
Views on SlideShare
558
Embed Views
6

Actions

Likes
0
Downloads
4
Comments
0

1 Embed 6

http://www.linkedin.com 6

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Rails i18n Rails i18n Presentation Transcript

  • rambling on rails’ i18n décousue discussion à propos de rails i18n
  • SRC 2012 Reject Conf Starring Alan GardnerTICKETS 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 yourapplication for localisationlocalisation is the process of providing locale / languagespecific content within your internationalised applicationyou internationalise so that you can localise
  • Internationalisation in Railsbaked in, which is great!easy to get started withplenty of documentation
  • Contrived Overview!
  • 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
  • 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 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’
  • 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 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!
  • 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
  • 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
  • Got any questions?I’ve not covered a lot, ask about specifics!
  • ありがとう!@ryanstenhouse on Twitter@HHRy on GitHubhttp://ryanstenhouse.eu