SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
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 !

Contenu connexe

En vedette

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
 

En vedette (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
 

Similaire à Rails Internationalization with I18n and Globalize2

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
 

Similaire à Rails Internationalization with I18n and Globalize2 (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
 

Dernier

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Dernier (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Rails Internationalization with I18n and Globalize2

  • 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