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
"Sun, 08 Feb 2009 15:42:42 +0100"
I18n.l Time.now, :locale => :fr
=> "08 février 2009 15:42"
I18n.l Date.today, :locale => :fr, :format => :short
=> "8 fév"

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[:"es-MX"]
   # => [:"es-MX", :es, :"en-US", :en]

 You can edit fallback chains
   I18n.fallbacks.map :ca => :"es-ES"
   I18n.fallbacks[:ca]
   # => [:ca, :"es-ES", :es, :"en-US", :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("#{RAILS_ROOT}/log/missing_trans.log")
 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

Was ist angesagt?

Future of PERL in IT
Future of PERL in ITFuture of PERL in IT
Future of PERL in ITNexiilabs
 
Computer languages
Computer languagesComputer languages
Computer languagesPrince Arsal
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the HoodC4Media
 
Programming Language Selection
Programming Language SelectionProgramming Language Selection
Programming Language SelectionDhananjay Nene
 
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
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the HoodC4Media
 
The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84Mahmoud Samir Fayed
 
Developing Multilingual Applications
Developing Multilingual ApplicationsDeveloping Multilingual Applications
Developing Multilingual ApplicationsPriyank Kapadia
 
Anton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexAnton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexElixir Club
 
Language translators
Language translatorsLanguage translators
Language translatorsAditya Sharat
 
compiler and their types
compiler and their typescompiler and their types
compiler and their typespatchamounika7
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language TranslatorRanjeet Kumar
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSsonalikharade3
 
Multi-language FBP with flowex
Multi-language FBP with flowexMulti-language FBP with flowex
Multi-language FBP with flowexAnton Mishchuk
 

Was ist angesagt? (20)

Future of PERL in IT
Future of PERL in ITFuture of PERL in IT
Future of PERL in IT
 
SD & D High and low level languages
SD & D High and low level languagesSD & D High and low level languages
SD & D High and low level languages
 
Computer languages
Computer languagesComputer languages
Computer languages
 
Swift - Under the Hood
Swift - Under the HoodSwift - Under the Hood
Swift - Under the Hood
 
Programming Language Selection
Programming Language SelectionProgramming Language Selection
Programming Language Selection
 
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
 
Open Source Swift Under the Hood
Open Source Swift Under the HoodOpen Source Swift Under the Hood
Open Source Swift Under the Hood
 
The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84
 
Developing Multilingual Applications
Developing Multilingual ApplicationsDeveloping Multilingual Applications
Developing Multilingual Applications
 
Anton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexAnton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with Flowex
 
ColdBox i18N
ColdBox i18N ColdBox i18N
ColdBox i18N
 
Language translators
Language translatorsLanguage translators
Language translators
 
Computer languages
Computer languagesComputer languages
Computer languages
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
LIL Presentation
LIL PresentationLIL Presentation
LIL Presentation
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Multi-language FBP with flowex
Multi-language FBP with flowexMulti-language FBP with flowex
Multi-language FBP with flowex
 
Create Your Own Language
Create Your Own LanguageCreate Your Own Language
Create Your Own Language
 

Andere mochten auch

Ruby on Rails Internationalization Best Practices, i18n SFRAILS
Ruby on Rails Internationalization Best Practices, i18n SFRAILSRuby on Rails Internationalization Best Practices, i18n SFRAILS
Ruby on Rails Internationalization Best Practices, i18n SFRAILSPhraseApp
 
Frizzell Winter Associates Portfolio
Frizzell Winter Associates PortfolioFrizzell Winter Associates Portfolio
Frizzell Winter Associates PortfolioEricaFrizzell
 
A rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsA rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsBelighted
 
Pharmekia Presentation 1
Pharmekia Presentation 1Pharmekia Presentation 1
Pharmekia Presentation 1Daddyman007
 
Myanma democratization
Myanma democratizationMyanma democratization
Myanma democratizationMaung Shwe Yee
 

Andere mochten auch (7)

Ruby on Rails Internationalization Best Practices, i18n SFRAILS
Ruby on Rails Internationalization Best Practices, i18n SFRAILSRuby on Rails Internationalization Best Practices, i18n SFRAILS
Ruby on Rails Internationalization Best Practices, i18n SFRAILS
 
Frizzell Winter Associates Portfolio
Frizzell Winter Associates PortfolioFrizzell Winter Associates Portfolio
Frizzell Winter Associates Portfolio
 
Frndz
FrndzFrndz
Frndz
 
A rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkitsA rubyist's naive comparison of some database systems and toolkits
A rubyist's naive comparison of some database systems and toolkits
 
Pharmekia Presentation 1
Pharmekia Presentation 1Pharmekia Presentation 1
Pharmekia Presentation 1
 
Myanma democratization
Myanma democratizationMyanma democratization
Myanma democratization
 
R18n
R18nR18n
R18n
 

Ähnlich wie Internationalization in Rails 2.2

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
 
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
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Rebaz Najeeb
 
Assembly Language In Electronics
Assembly Language In ElectronicsAssembly Language In Electronics
Assembly Language In ElectronicsAsaduzzaman Kanok
 
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
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash CourseWill Iverson
 
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
 
Internationalisation In Rails
Internationalisation In RailsInternationalisation In Rails
Internationalisation In RailsRishav Dixit
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
Internazionalizza le tue applicazioni
Internazionalizza le tue applicazioniInternazionalizza le tue applicazioni
Internazionalizza le tue applicazioniQT-day
 
Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Takayuki Shimizukawa
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldChristian López Espínola
 
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
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computerBATMUNHMUNHZAYA
 

Ähnlich wie Internationalization in Rails 2.2 (20)

I18n in Rails2.2
I18n in Rails2.2I18n in Rails2.2
I18n in Rails2.2
 
Ruby i18n - internationalization for ruby
Ruby i18n - internationalization for rubyRuby i18n - internationalization for ruby
Ruby i18n - internationalization for ruby
 
Shipping your product overseas!
Shipping your product overseas!Shipping your product overseas!
Shipping your product overseas!
 
Localization in Rails
Localization in RailsLocalization in Rails
Localization in Rails
 
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 ...
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation
 
Assembly Language In Electronics
Assembly Language In ElectronicsAssembly Language In Electronics
Assembly Language In Electronics
 
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...
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
 
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
 
Internationalisation In Rails
Internationalisation In RailsInternationalisation In Rails
Internationalisation In Rails
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Internazionalizza le tue applicazioni
Internazionalizza le tue applicazioniInternazionalizza le tue applicazioni
Internazionalizza le tue applicazioni
 
Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015Easy contributable internationalization process with Sphinx @ pyconsg2015
Easy contributable internationalization process with Sphinx @ pyconsg2015
 
I18n
I18nI18n
I18n
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire World
 
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
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computer
 
Creating messages
Creating messagesCreating messages
Creating messages
 

Kürzlich hochgeladen

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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...Martijn de Jong
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Kürzlich hochgeladen (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

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 "Sun, 08 Feb 2009 15:42:42 +0100" I18n.l Time.now, :locale => :fr => "08 février 2009 15:42" I18n.l Date.today, :locale => :fr, :format => :short => "8 fév" 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[:"es-MX"] # => [:"es-MX", :es, :"en-US", :en] You can edit fallback chains I18n.fallbacks.map :ca => :"es-ES" I18n.fallbacks[:ca] # => [:ca, :"es-ES", :es, :"en-US", :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("#{RAILS_ROOT}/log/missing_trans.log") 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