SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Internationalization in Rails 2.2
Nicolas Jacobeus - Belighted sprl
FOSDEM ’09 - Ruby and Rails Developer Room
February 8th 2009
Summary
What is internationalization?
Internationalization before Rails 2.2
The Rails i18n framework
Short demo
Globalize2
Resources
What we are talking about

Internationalization (i18n): “designing a software
application so that it can be adapted to various
languages and regions without engineering changes”
Localization (L10n): “the process of adapting
software for a specific region or language by adding
locale-specific components and translating text”
What it means

This emcompasses
  Language

  Culture

  Writing conventions

Why does it matter?
  Not everybody speaks english, even on the web

  In Europe: dozens of cultures and languages
Rails i18n before 2.2

 English was hardcoded in the codebase




 Rails was a framework localized to English (en-US)
Rails i18n before 2.2
 i18n plugins had to monkey-patch Rails everywhere
   Remove english defaults
   Enhance business logic so that it handles translation
The Rails i18n framework

Started in Sep ’07 by several i18n plugin developers
Aim:
  eliminate the need to monkey-patch Rails for i18n
  implement a minimal, common API for all solutions
The Rails i18n framework
A gem by Sven Fuchs and other contributors
http://github.com/svenfuchs/i18n

Shipped with Rails since 2.2 (ActiveSupport vendor dir)
2 parts:
  An API
  A minimal “Simple” backend implementing the API
The Rails i18n framework

The API is now used by Rails instead of hardcoded
strings
The Simple Backend implements the API to re-localize
Rails back to en-US
Rails is still a framework localized to English, but it’s
now globalized too
Doesn’t remove the need for plugins!
The Rails i18n framework


Advantages?
  The backend can easily be swapped
  No monkey-patching anymore!
The i18n module in details

 Defines #translate / #t and #localize / #l
 Stores the current locale in Thread.current
 Store a default locale
 Stores a backend
 Stores an exception handler
So how do I translate?

 Put your translations in config/locales (YAML or Ruby),
 or use I18n.backend.store_translations in the console:
 I18n.backend.store_translations :en, :hi => “Hi!”
 I18n.backend.store_translations :fr, :hi => “Salut!”

 Set the current locale:
 I18n.locale = :fr

 Keys can be strings or symbols:
 I18n.t :message
 I18n.t 'message'
Scopes / namespaces



I18n.translate :exclusion,
               :scope => [:activerecord, :errors, :messages]

I18n.translate “activerecord.errors.messages.exclusion”

I18n.translate “messages.exclusion”,
               :scope => “activerecord.errors”
Defaults

 I18n.t :missing, :default => 'Not here'
 # => 'Not here'

 Default value can itself be a key and get translated!
 Chaining defaults:
 I18n.t :missing,
        :default => [:also_missing, 'Not here']
 # => 'Not here'
Interpolation

 All other options will be interpolated




 I18n.translate :hello, :name => “Nicolas”
 # => ‘Salut Nicolas !’
Pluralization



 I18n.translate :inbox, :count => 2
 # => '2 messages'
 Pluralization rules defined by CLDR:
 [ :zero, :one, :two, :few, :many, :other ]
Localizing dates and times
I18n.l Time.now, :locale => :en
quot;Sun, 08 Feb 2009 15:42:42 +0100quot;
I18n.l Time.now, :locale => :fr
=> quot;08 février 2009 15:42quot;
I18n.l Date.today, :locale => :fr, :format => :short
=> quot;8 févquot;

You have to provide the localizations!
Short demo

Basic “hello world” app:
  Configure the i18n module
  Set the locale in each request
  Internationalize the application
Shortcomings

The simple backend is... simple
  Pluralization is basic (singular and plural)
  Storage only in YAML or Ruby files
No model translations
Globalize2

http://github.com/joshmh/globalize2
Like Globalize but sits on top of the Rails i18n API
Adds model translations
Provides a new backend
Provides a new exception handler
Model translations

 #translates specifies
 which fields you want to be
 translatable
 The accessor will return the
 localized version
 transparently
Model translations

 The translations are stored
 in a separate table for each
 model
 Shortcut:
 Post.create_translation_table!
         :title => :string,
         :text => :text
Globalize::Backend::Static


 Builds on the Simple backend
 Locale fallbacks
 Allows custom pluralization logic
Locale fallbacks
 Allows you to set fallbacks when a translation is not
 available in a particular locale
   I18n.fallbacks[:quot;es-MXquot;]
   # => [:quot;es-MXquot;, :es, :quot;en-USquot;, :en]

 You can edit fallback chains
   I18n.fallbacks.map :ca => :quot;es-ESquot;
   I18n.fallbacks[:ca]
   # => [:ca, :quot;es-ESquot;, :es, :quot;en-USquot;, :en]
Custom pluralization logic

 For languages not behaving like English
 Globalize2’s pluralization logic is not hardcoded
 New rules can by added with lambdas
 @backend.add_pluralizer :cz, lambda { |c|
   c == 1 ? :one : (2..4).include?(c) ? :few : :other
 }
Missing translations log
handler

 Will log all missing translations in a file
 require 'globalize/i18n/missing_translations_log_handler’
 logger = Logger.new(quot;#{RAILS_ROOT}/log/missing_trans.logquot;)
 I18n.missing_translations_logger = logger
 I18n.exception_handler = :missing_translations_log_handler

 Pretty useful to quickly find what’s missing
Resources


Some additional resources to help you start localizing
your applications
For a comprehensive list see:
http://rails-i18n.org/wiki
The Translate plugin
 Adds a translation UI to
 your app in seconds
 Allows you or your
 translators to easily
 translate all your strings
 Available on Github:
 http://github.com/
 newsdesk/translate/
99translations.com
Hosted webservice for
sharing and maintaining
translations
Meeting place for
developers and translators
Admin interface, version
control, API
Relevant Git repositories

 http://github.com/svenfuchs/i18n
 http://github.com/svenfuchs/rails-i18n
 http://github.com/joshmh/globalize2
 http://github.com/rails/rails
Thank you !

Weitere ähnliche Inhalte

Andere mochten auch

Bank Account Of Life
Bank Account Of LifeBank Account Of Life
Bank Account Of LifeNafass
 
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from JavaPycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Javajbellis
 
Stc 2014 unraveling the mysteries of localization kits
Stc 2014 unraveling the mysteries of localization kitsStc 2014 unraveling the mysteries of localization kits
Stc 2014 unraveling the mysteries of localization kitsDavid Sommer
 
Strategies for Friendly English and Successful Localization
Strategies for Friendly English and Successful LocalizationStrategies for Friendly English and Successful Localization
Strategies for Friendly English and Successful LocalizationJohn Collins
 
Building Quality Experiences for Users in Any Language
Building Quality Experiences for Users in Any LanguageBuilding Quality Experiences for Users in Any Language
Building Quality Experiences for Users in Any LanguageJohn Collins
 
Linguistic Potluck: Crowdsourcing localization with Rails
Linguistic Potluck: Crowdsourcing localization with RailsLinguistic Potluck: Crowdsourcing localization with Rails
Linguistic Potluck: Crowdsourcing localization with RailsHeatherRivers
 
2008 Fourth Quarter Real Estate Commentary
2008 Fourth Quarter Real Estate Commentary2008 Fourth Quarter Real Estate Commentary
2008 Fourth Quarter Real Estate Commentaryalghanim
 
My Valentine Gift - YOU Decide
My Valentine Gift - YOU DecideMy Valentine Gift - YOU Decide
My Valentine Gift - YOU DecideSizzlynRose
 
Sample email submission
Sample email submissionSample email submission
Sample email submissionDavid Sommer
 
Designing for Multiple Mobile Platforms
Designing for Multiple Mobile PlatformsDesigning for Multiple Mobile Platforms
Designing for Multiple Mobile PlatformsRobert Douglas
 
Sample of instructions
Sample of instructionsSample of instructions
Sample of instructionsDavid Sommer
 
Putting Out Fires with Content Strategy (STC Academic SIG)
Putting Out Fires with Content Strategy (STC Academic SIG)Putting Out Fires with Content Strategy (STC Academic SIG)
Putting Out Fires with Content Strategy (STC Academic SIG)John Collins
 
mobile development platforms
mobile development platformsmobile development platforms
mobile development platformsguestfa9375
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThoughtWorks
 
Pycon 2012 Apache Cassandra
Pycon 2012 Apache CassandraPycon 2012 Apache Cassandra
Pycon 2012 Apache Cassandrajeremiahdjordan
 
Tricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationTricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationSimon Willison
 
Building a Localization Kit
Building a Localization KitBuilding a Localization Kit
Building a Localization KitLuigi Muzii
 

Andere mochten auch (20)

Bank Account Of Life
Bank Account Of LifeBank Account Of Life
Bank Account Of Life
 
Pycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from JavaPycon 2012 What Python can learn from Java
Pycon 2012 What Python can learn from Java
 
Glossary
GlossaryGlossary
Glossary
 
Stc 2014 unraveling the mysteries of localization kits
Stc 2014 unraveling the mysteries of localization kitsStc 2014 unraveling the mysteries of localization kits
Stc 2014 unraveling the mysteries of localization kits
 
Strategies for Friendly English and Successful Localization
Strategies for Friendly English and Successful LocalizationStrategies for Friendly English and Successful Localization
Strategies for Friendly English and Successful Localization
 
Building Quality Experiences for Users in Any Language
Building Quality Experiences for Users in Any LanguageBuilding Quality Experiences for Users in Any Language
Building Quality Experiences for Users in Any Language
 
Linguistic Potluck: Crowdsourcing localization with Rails
Linguistic Potluck: Crowdsourcing localization with RailsLinguistic Potluck: Crowdsourcing localization with Rails
Linguistic Potluck: Crowdsourcing localization with Rails
 
2008 Fourth Quarter Real Estate Commentary
2008 Fourth Quarter Real Estate Commentary2008 Fourth Quarter Real Estate Commentary
2008 Fourth Quarter Real Estate Commentary
 
Silmeyiniz
SilmeyinizSilmeyiniz
Silmeyiniz
 
My Valentine Gift - YOU Decide
My Valentine Gift - YOU DecideMy Valentine Gift - YOU Decide
My Valentine Gift - YOU Decide
 
Sample email submission
Sample email submissionSample email submission
Sample email submission
 
Designing for Multiple Mobile Platforms
Designing for Multiple Mobile PlatformsDesigning for Multiple Mobile Platforms
Designing for Multiple Mobile Platforms
 
Sample of instructions
Sample of instructionsSample of instructions
Sample of instructions
 
Shrunken Head
 Shrunken Head  Shrunken Head
Shrunken Head
 
Putting Out Fires with Content Strategy (STC Academic SIG)
Putting Out Fires with Content Strategy (STC Academic SIG)Putting Out Fires with Content Strategy (STC Academic SIG)
Putting Out Fires with Content Strategy (STC Academic SIG)
 
mobile development platforms
mobile development platformsmobile development platforms
mobile development platforms
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj Kumar
 
Pycon 2012 Apache Cassandra
Pycon 2012 Apache CassandraPycon 2012 Apache Cassandra
Pycon 2012 Apache Cassandra
 
Tricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationTricks & challenges developing a large Django application
Tricks & challenges developing a large Django application
 
Building a Localization Kit
Building a Localization KitBuilding a Localization Kit
Building a Localization Kit
 

Ähnlich wie Internationalization in Rails 2.2

Internationalization in Rails 2.2
Internationalization in Rails 2.2Internationalization in Rails 2.2
Internationalization in Rails 2.2Belighted
 
Ruby i18n - internationalization for ruby
Ruby i18n - internationalization for rubyRuby i18n - internationalization for ruby
Ruby i18n - internationalization for rubyLingoHub
 
Shipping your product overseas!
Shipping your product overseas!Shipping your product overseas!
Shipping your product overseas!Diogo Busanello
 
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 ApiNTT DATA Americas
 
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 ...agileware
 
Developing Multilingual Applications
Developing Multilingual ApplicationsDeveloping Multilingual Applications
Developing Multilingual ApplicationsPriyank Kapadia
 
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
 
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 ApplicationsLars Trieloff
 
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...grosser
 
Plone i18n, LinguaPlone
Plone i18n, LinguaPlonePlone i18n, LinguaPlone
Plone i18n, LinguaPloneQuintagroup
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS - The Language Data Network
 
symfony : I18n And L10n
symfony : I18n And L10nsymfony : I18n And L10n
symfony : I18n And L10nWildan Maulana
 
GUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email ClientGUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email Clientdjcb
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash CourseWill Iverson
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
What's New in Web Development
What's New in Web DevelopmentWhat's New in Web Development
What's New in Web DevelopmentKonstantin Käfer
 
All the language support in Drupal 8 - At Drupalaton 2014
All the language support in Drupal 8 - At Drupalaton 2014All the language support in Drupal 8 - At Drupalaton 2014
All the language support in Drupal 8 - At Drupalaton 2014Gábor Hojtsy
 

Ähnlich wie Internationalization in Rails 2.2 (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
 
Localization in Rails
Localization in RailsLocalization in Rails
Localization in Rails
 
Shipping your product overseas!
Shipping your product overseas!Shipping your product overseas!
Shipping your product overseas!
 
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
 
Till Vollmer Presentation
Till Vollmer PresentationTill Vollmer Presentation
Till Vollmer Presentation
 
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 ...
 
Developing Multilingual Applications
Developing Multilingual ApplicationsDeveloping Multilingual Applications
Developing Multilingual 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...
 
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
 
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
 
Plone i18n, LinguaPlone
Plone i18n, LinguaPlonePlone i18n, LinguaPlone
Plone i18n, LinguaPlone
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memories
 
symfony : I18n And L10n
symfony : I18n And L10nsymfony : I18n And L10n
symfony : I18n And L10n
 
GUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email ClientGUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email Client
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
 
ColdBox i18N
ColdBox i18N ColdBox i18N
ColdBox i18N
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
What's New in Web Development
What's New in Web DevelopmentWhat's New in Web Development
What's New in Web Development
 
All the language support in Drupal 8 - At Drupalaton 2014
All the language support in Drupal 8 - At Drupalaton 2014All the language support in Drupal 8 - At Drupalaton 2014
All the language support in Drupal 8 - At Drupalaton 2014
 

Kürzlich hochgeladen

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 Scriptwesley chun
 
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...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Kürzlich hochgeladen (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Internationalization in Rails 2.2

  • 1. Internationalization in Rails 2.2 Nicolas Jacobeus - Belighted sprl FOSDEM ’09 - Ruby and Rails Developer Room February 8th 2009
  • 2. Summary What is internationalization? Internationalization before Rails 2.2 The Rails i18n framework Short demo Globalize2 Resources
  • 3. What we are talking about Internationalization (i18n): “designing a software application so that it can be adapted to various languages and regions without engineering changes” Localization (L10n): “the process of adapting software for a specific region or language by adding locale-specific components and translating text”
  • 4. What it means This emcompasses Language Culture Writing conventions Why does it matter? Not everybody speaks english, even on the web In Europe: dozens of cultures and languages
  • 5. Rails i18n before 2.2 English was hardcoded in the codebase Rails was a framework localized to English (en-US)
  • 6. Rails i18n before 2.2 i18n plugins had to monkey-patch Rails everywhere Remove english defaults Enhance business logic so that it handles translation
  • 7. The Rails i18n framework Started in Sep ’07 by several i18n plugin developers Aim: eliminate the need to monkey-patch Rails for i18n implement a minimal, common API for all solutions
  • 8. The Rails i18n framework A gem by Sven Fuchs and other contributors http://github.com/svenfuchs/i18n Shipped with Rails since 2.2 (ActiveSupport vendor dir) 2 parts: An API A minimal “Simple” backend implementing the API
  • 9. The Rails i18n framework The API is now used by Rails instead of hardcoded strings The Simple Backend implements the API to re-localize Rails back to en-US Rails is still a framework localized to English, but it’s now globalized too Doesn’t remove the need for plugins!
  • 10. The Rails i18n framework Advantages? The backend can easily be swapped No monkey-patching anymore!
  • 11. The i18n module in details Defines #translate / #t and #localize / #l Stores the current locale in Thread.current Store a default locale Stores a backend Stores an exception handler
  • 12. So how do I translate? Put your translations in config/locales (YAML or Ruby), or use I18n.backend.store_translations in the console: I18n.backend.store_translations :en, :hi => “Hi!” I18n.backend.store_translations :fr, :hi => “Salut!” Set the current locale: I18n.locale = :fr Keys can be strings or symbols: I18n.t :message I18n.t 'message'
  • 13. Scopes / namespaces I18n.translate :exclusion, :scope => [:activerecord, :errors, :messages] I18n.translate “activerecord.errors.messages.exclusion” I18n.translate “messages.exclusion”, :scope => “activerecord.errors”
  • 14. Defaults I18n.t :missing, :default => 'Not here' # => 'Not here' Default value can itself be a key and get translated! Chaining defaults: I18n.t :missing, :default => [:also_missing, 'Not here'] # => 'Not here'
  • 15. Interpolation All other options will be interpolated I18n.translate :hello, :name => “Nicolas” # => ‘Salut Nicolas !’
  • 16. Pluralization I18n.translate :inbox, :count => 2 # => '2 messages' Pluralization rules defined by CLDR: [ :zero, :one, :two, :few, :many, :other ]
  • 17. Localizing dates and times I18n.l Time.now, :locale => :en quot;Sun, 08 Feb 2009 15:42:42 +0100quot; I18n.l Time.now, :locale => :fr => quot;08 février 2009 15:42quot; I18n.l Date.today, :locale => :fr, :format => :short => quot;8 févquot; You have to provide the localizations!
  • 18. Short demo Basic “hello world” app: Configure the i18n module Set the locale in each request Internationalize the application
  • 19. Shortcomings The simple backend is... simple Pluralization is basic (singular and plural) Storage only in YAML or Ruby files No model translations
  • 20. Globalize2 http://github.com/joshmh/globalize2 Like Globalize but sits on top of the Rails i18n API Adds model translations Provides a new backend Provides a new exception handler
  • 21. Model translations #translates specifies which fields you want to be translatable The accessor will return the localized version transparently
  • 22. Model translations The translations are stored in a separate table for each model Shortcut: Post.create_translation_table! :title => :string, :text => :text
  • 23. Globalize::Backend::Static Builds on the Simple backend Locale fallbacks Allows custom pluralization logic
  • 24. Locale fallbacks Allows you to set fallbacks when a translation is not available in a particular locale I18n.fallbacks[:quot;es-MXquot;] # => [:quot;es-MXquot;, :es, :quot;en-USquot;, :en] You can edit fallback chains I18n.fallbacks.map :ca => :quot;es-ESquot; I18n.fallbacks[:ca] # => [:ca, :quot;es-ESquot;, :es, :quot;en-USquot;, :en]
  • 25. Custom pluralization logic For languages not behaving like English Globalize2’s pluralization logic is not hardcoded New rules can by added with lambdas @backend.add_pluralizer :cz, lambda { |c| c == 1 ? :one : (2..4).include?(c) ? :few : :other }
  • 26. Missing translations log handler Will log all missing translations in a file require 'globalize/i18n/missing_translations_log_handler’ logger = Logger.new(quot;#{RAILS_ROOT}/log/missing_trans.logquot;) I18n.missing_translations_logger = logger I18n.exception_handler = :missing_translations_log_handler Pretty useful to quickly find what’s missing
  • 27. Resources Some additional resources to help you start localizing your applications For a comprehensive list see: http://rails-i18n.org/wiki
  • 28. The Translate plugin Adds a translation UI to your app in seconds Allows you or your translators to easily translate all your strings Available on Github: http://github.com/ newsdesk/translate/
  • 29. 99translations.com Hosted webservice for sharing and maintaining translations Meeting place for developers and translators Admin interface, version control, API
  • 30. Relevant Git repositories http://github.com/svenfuchs/i18n http://github.com/svenfuchs/rails-i18n http://github.com/joshmh/globalize2 http://github.com/rails/rails