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

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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 

Kürzlich hochgeladen (20)

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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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!
 

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