SlideShare una empresa de Scribd logo
1 de 20
Rails
                     Internationalization


Wednesday, March 11, 2009
Slides at:

                      http://graysky.org/public/rails_i18n_talk.pdf




Wednesday, March 11, 2009
Can Rails Scale?




Wednesday, March 11, 2009
Can Rails Scale?

               ... to Multiple Languages?



Wednesday, March 11, 2009
Agenda
                   • Who is Mike?
                   • Internationalization (i18n) Overview
                   • Rails Support for i18n
                   • Pitfalls
                   • Translator plugin
                   • Further Reading

Wednesday, March 11, 2009
Mike Champion
                   •        Speaks English and Spanish very poorly
                   •        Heading to RailsConf - see you in Las Vegas?
                   •        The Usual URIs
                            •   graysky.org
                            •   twitter.com/graysky
                            •   github.com/graysky
                   •        Developer at SnapMyLife
                            •   Mobile photo sharing
                            •   Global user base

Wednesday, March 11, 2009
Iñtërnâtiônàlizætiøn
                   •        Level 0: App handles utf-8 data

                            •   Database & database.yml configuration

                            •   Multi-byte string handling (since Rails 1.2 / Ruby 1.9)

                                •   Ruby 1.8: “café”.length => 5

                                •   Rails MB: “café”.mb_chars.length          4
                                                                         =>


                   •        Level 1: App is internationalized

                            •   Strings extracted, dates, etc. (support in Rails 2.2)

                   •        Level 2: App is localized

                            •   Strings translated / tested (on your own - good luck!)
Wednesday, March 11, 2009
I18n Concerns
                   •        Strings
                            •   Concatenation is evil when used to form sentences
                   •        Sorting & Searching
                            • Swedish: z < ö while in German: ö < z
                   •        Dates/Times & Timezones
                            •   12/4/09 vs. 4/12/09
                   •        Units, Addresses & Currency
                            •   Miles vs. kilometers, 5-digit zip codes
                   •        Cultural
                            •   Surname & given name
                            •   Icons, colors, etc.


Wednesday, March 11, 2009
¡Dios mío!
                              (Lo Siento)




Wednesday, March 11, 2009
I18n Module
                   •        I18n library in ActiveSupport for 2.2

                            •   Locale files in   config/locale

                                •   I18n.load_path += File.join(“more.yml”)

                   •        Simple backend uses YAML (and Ruby) files:
                                en:
                                  say_hello: 'Hello World'
                                  date:
                                    short: “%Y-%m-%d”

                                I18n.translate('say_hello')
                                I18n.localize(Time.now,
                                              :format => :short)
Wednesday, March 11, 2009
I18n Module, cont.
                   • Variable interpolation
                            say_hello: 'Hello {{name}} World'

                            I18n.t('say_hello', :name =>'Ruby')

                    • Pluralization (only supports some languages)
                            minutes_ago:
                              one: '1 minute ago'
                              other: '{{count}} minutes ago'

                            I18n.t('minutes_ago', :count => 2)
Wednesday, March 11, 2009
Rails I18n
                   •        Internationalized ActiveSupport for:

                            •   Numbers - number_with_delimiter,   etc.


                            •   Datetime - distance_of_time_in_words,   etc.


                            •   Currency - number_to_currency

                   •        Localized views -   index.de.erb.html (Rails 2.3)

                            •   Useful if translating to one other language



Wednesday, March 11, 2009
International Models*
            •      Map model name & attributes to human-readable strings
                   using I18n lookup

                 • User.human_name() => “Customer”
                 • User.human_attribute_name(‘pin’)                                         =>
                            “Password”

                 •          Useful to easily change user-visible column names

            •      Translate ActiveRecord validation errors
                 •          validates_presence_of :pin

                 •          activerecord.errors.messages.models.user.attributes.pin.blank:
                            “Password can’t be blank, yo”

                                                               * Not the Exciting Kind...
Wednesday, March 11, 2009
Sorting (aka Collation)
                   •        Example: Germans, French and Swedes sort the
                            same characters differently

                   •        MySQL supports different collation algorithms

                            •   utf8_general_ci - faster, less correct

                            •   utf8_unicode_ci - slightly slower, better

                                •   implements Unicode Collation Algorithm

                                    •   http://www.unicode.org/reports/tr10/

                   •        Haven’t seen a Ruby implementation


Wednesday, March 11, 2009
Pitfalls
                   • Gems & plugins may not be i18n’d
                   • Embedded links/markup are painful
                            •   “You <span>must</span> out my <%=
                                link_to(“awesome blog”, ‘http://foo’) %> today!”

                            •   Prefer label : value when possible

                            •   Text verbosity will change layouts.

                   • Duplicate keys shadow each other in yml
                   • MY_ERROR_MSG                = t(‘bad_password’)

                   • Careful with fragment/action caching
Wednesday, March 11, 2009
Translator
                   •        I18n integration could be more Rails-y

                   •        Automatically determines scoping using a convention

                            •   Adds “t” method to views, models, controllers, mailers

                            •   t(‘title’) in blog_posts/show.erb            will fetch
                                t(‘blog_posts.show.title’)

                   •        Test helper to any catch missing translations

                   •        Pseudo-translation (ex. “[My Blog]”) to find missing
                            extractions
                            •   Useful for testing layouts when text expands in other language

                   •        Locale fallback to default_locale if cannot find string

                   •        Plugin at: http://github.com/graysky/translator

Wednesday, March 11, 2009
Translator Key Convention
                            en:
                              # controller
                              blog_posts:
                                # typical actions
                                index:
                                  title: quot;My Blog Postsquot;

                                # footer partial (non-shared)
                                footer:
                                  copyright: quot;Copyright 2009quot;

                              # Layouts
                              layouts:
                                blog_layout:
                                  blog_title: quot;The Blog of Rickyquot;

                              # ActionMailers
                              blog_comment_mailer:
                                comment_notification:
                                  subject: quot;New Comment Notificationquot;

                              # ActiveRecord (note singular)
                              blog_posts:
                                byline: quot;Written by {{author}}quot;


Wednesday, March 11, 2009
Determining Locale
                   •        Locale more than just Language

                   •        User Preference

                   •        Domain name - foo.com vs. foo.de

                   •        Path prefix - foo.com/de/blog_posts

                   •        HTTP Accept-Language Header
                            •   zh-Hans (simplified Chinese) => “zh”

                   •        IP Geolocation

                            •   GeoIP Lite Country database

Wednesday, March 11, 2009
Further Reading
                   •        Rails I18n Guide
                            •   http://guides.rubyonrails.org/i18n.html
                   •        i18n_demo_app
                            •   http://github.com/clemens/i18n_demo_app
                   •        Rails i18n Group
                            •   http://groups.google.com/group/rails-i18n
                   •        Translate - web ui for yml translatations
                            •   http://github.com/newsdesk/translate
                   •        Unicode Common Locale Data Repository (CLDR)
                            •   http://www.unicode.org/cldr/
                   •        “Survival Guide to i18n” (not Rails specific)
                            •   http://www.intertwingly.net/stories/2004/04/14/i18n.html
Wednesday, March 11, 2009
Questions?



Wednesday, March 11, 2009

Más contenido relacionado

Similar a Rails Internationalization

Rails hosting
Rails hostingRails hosting
Rails hostingwonko
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPPStoyan Zhekov
 
Sqlpo Presentation
Sqlpo PresentationSqlpo Presentation
Sqlpo Presentationsandook
 
Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)Ivo Jansch
 
GUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email ClientGUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email Clientdjcb
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUGMatt Aimonetti
 
ruote stockholm 2008
ruote stockholm 2008ruote stockholm 2008
ruote stockholm 2008John Mettraux
 
Internationalization in Rails 2.2
Internationalization in Rails 2.2Internationalization in Rails 2.2
Internationalization in Rails 2.2Belighted
 
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
 
Oğuz Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...
Oğuz	Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...Oğuz	Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...
Oğuz Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...360|Conferences
 
090309 Rgam Presentatie Evernote And Tarpipe Final
090309   Rgam   Presentatie Evernote And Tarpipe Final090309   Rgam   Presentatie Evernote And Tarpipe Final
090309 Rgam Presentatie Evernote And Tarpipe Finalgebbetje
 
What is Ruby on Rails?
What is Ruby on Rails?What is Ruby on Rails?
What is Ruby on Rails?Karmen Blake
 
Building Ruby in Smalltalk
Building Ruby in SmalltalkBuilding Ruby in Smalltalk
Building Ruby in SmalltalkESUG
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The EnterpriseMatt Aimonetti
 
Shipping your product overseas!
Shipping your product overseas!Shipping your product overseas!
Shipping your product overseas!Diogo Busanello
 

Similar a Rails Internationalization (20)

Till Vollmer Presentation
Till Vollmer PresentationTill Vollmer Presentation
Till Vollmer Presentation
 
Rails hosting
Rails hostingRails hosting
Rails hosting
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPP
 
Sqlpo Presentation
Sqlpo PresentationSqlpo Presentation
Sqlpo Presentation
 
Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)
 
GUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email ClientGUADEC2007: A Modest Email Client
GUADEC2007: A Modest Email Client
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUG
 
ruote stockholm 2008
ruote stockholm 2008ruote stockholm 2008
ruote stockholm 2008
 
Internationalization in Rails 2.2
Internationalization in Rails 2.2Internationalization in Rails 2.2
Internationalization in Rails 2.2
 
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...
 
Jvm Language Summit Rose 20081016
Jvm Language Summit Rose 20081016Jvm Language Summit Rose 20081016
Jvm Language Summit Rose 20081016
 
Intro To Grails
Intro To GrailsIntro To Grails
Intro To Grails
 
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
 
Oğuz Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...
Oğuz	Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...Oğuz	Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...
Oğuz Demirkapı - Hands On Training: Creating Our First i18N Flex Application ...
 
090309 Rgam Presentatie Evernote And Tarpipe Final
090309   Rgam   Presentatie Evernote And Tarpipe Final090309   Rgam   Presentatie Evernote And Tarpipe Final
090309 Rgam Presentatie Evernote And Tarpipe Final
 
What is Ruby on Rails?
What is Ruby on Rails?What is Ruby on Rails?
What is Ruby on Rails?
 
Building Ruby in Smalltalk
Building Ruby in SmalltalkBuilding Ruby in Smalltalk
Building Ruby in Smalltalk
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The Enterprise
 
Shipping your product overseas!
Shipping your product overseas!Shipping your product overseas!
Shipping your product overseas!
 

Último

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Último (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Rails Internationalization

  • 1. Rails Internationalization Wednesday, March 11, 2009
  • 2. Slides at: http://graysky.org/public/rails_i18n_talk.pdf Wednesday, March 11, 2009
  • 4. Can Rails Scale? ... to Multiple Languages? Wednesday, March 11, 2009
  • 5. Agenda • Who is Mike? • Internationalization (i18n) Overview • Rails Support for i18n • Pitfalls • Translator plugin • Further Reading Wednesday, March 11, 2009
  • 6. Mike Champion • Speaks English and Spanish very poorly • Heading to RailsConf - see you in Las Vegas? • The Usual URIs • graysky.org • twitter.com/graysky • github.com/graysky • Developer at SnapMyLife • Mobile photo sharing • Global user base Wednesday, March 11, 2009
  • 7. Iñtërnâtiônàlizætiøn • Level 0: App handles utf-8 data • Database & database.yml configuration • Multi-byte string handling (since Rails 1.2 / Ruby 1.9) • Ruby 1.8: “café”.length => 5 • Rails MB: “café”.mb_chars.length 4 => • Level 1: App is internationalized • Strings extracted, dates, etc. (support in Rails 2.2) • Level 2: App is localized • Strings translated / tested (on your own - good luck!) Wednesday, March 11, 2009
  • 8. I18n Concerns • Strings • Concatenation is evil when used to form sentences • Sorting & Searching • Swedish: z < ö while in German: ö < z • Dates/Times & Timezones • 12/4/09 vs. 4/12/09 • Units, Addresses & Currency • Miles vs. kilometers, 5-digit zip codes • Cultural • Surname & given name • Icons, colors, etc. Wednesday, March 11, 2009
  • 9. ¡Dios mío! (Lo Siento) Wednesday, March 11, 2009
  • 10. I18n Module • I18n library in ActiveSupport for 2.2 • Locale files in config/locale • I18n.load_path += File.join(“more.yml”) • Simple backend uses YAML (and Ruby) files: en: say_hello: 'Hello World' date: short: “%Y-%m-%d” I18n.translate('say_hello') I18n.localize(Time.now, :format => :short) Wednesday, March 11, 2009
  • 11. I18n Module, cont. • Variable interpolation say_hello: 'Hello {{name}} World' I18n.t('say_hello', :name =>'Ruby') • Pluralization (only supports some languages) minutes_ago: one: '1 minute ago' other: '{{count}} minutes ago' I18n.t('minutes_ago', :count => 2) Wednesday, March 11, 2009
  • 12. Rails I18n • Internationalized ActiveSupport for: • Numbers - number_with_delimiter, etc. • Datetime - distance_of_time_in_words, etc. • Currency - number_to_currency • Localized views - index.de.erb.html (Rails 2.3) • Useful if translating to one other language Wednesday, March 11, 2009
  • 13. International Models* • Map model name & attributes to human-readable strings using I18n lookup • User.human_name() => “Customer” • User.human_attribute_name(‘pin’) => “Password” • Useful to easily change user-visible column names • Translate ActiveRecord validation errors • validates_presence_of :pin • activerecord.errors.messages.models.user.attributes.pin.blank: “Password can’t be blank, yo” * Not the Exciting Kind... Wednesday, March 11, 2009
  • 14. Sorting (aka Collation) • Example: Germans, French and Swedes sort the same characters differently • MySQL supports different collation algorithms • utf8_general_ci - faster, less correct • utf8_unicode_ci - slightly slower, better • implements Unicode Collation Algorithm • http://www.unicode.org/reports/tr10/ • Haven’t seen a Ruby implementation Wednesday, March 11, 2009
  • 15. Pitfalls • Gems & plugins may not be i18n’d • Embedded links/markup are painful • “You <span>must</span> out my <%= link_to(“awesome blog”, ‘http://foo’) %> today!” • Prefer label : value when possible • Text verbosity will change layouts. • Duplicate keys shadow each other in yml • MY_ERROR_MSG = t(‘bad_password’) • Careful with fragment/action caching Wednesday, March 11, 2009
  • 16. Translator • I18n integration could be more Rails-y • Automatically determines scoping using a convention • Adds “t” method to views, models, controllers, mailers • t(‘title’) in blog_posts/show.erb will fetch t(‘blog_posts.show.title’) • Test helper to any catch missing translations • Pseudo-translation (ex. “[My Blog]”) to find missing extractions • Useful for testing layouts when text expands in other language • Locale fallback to default_locale if cannot find string • Plugin at: http://github.com/graysky/translator Wednesday, March 11, 2009
  • 17. Translator Key Convention en: # controller blog_posts: # typical actions index: title: quot;My Blog Postsquot; # footer partial (non-shared) footer: copyright: quot;Copyright 2009quot; # Layouts layouts: blog_layout: blog_title: quot;The Blog of Rickyquot; # ActionMailers blog_comment_mailer: comment_notification: subject: quot;New Comment Notificationquot; # ActiveRecord (note singular) blog_posts: byline: quot;Written by {{author}}quot; Wednesday, March 11, 2009
  • 18. Determining Locale • Locale more than just Language • User Preference • Domain name - foo.com vs. foo.de • Path prefix - foo.com/de/blog_posts • HTTP Accept-Language Header • zh-Hans (simplified Chinese) => “zh” • IP Geolocation • GeoIP Lite Country database Wednesday, March 11, 2009
  • 19. Further Reading • Rails I18n Guide • http://guides.rubyonrails.org/i18n.html • i18n_demo_app • http://github.com/clemens/i18n_demo_app • Rails i18n Group • http://groups.google.com/group/rails-i18n • Translate - web ui for yml translatations • http://github.com/newsdesk/translate • Unicode Common Locale Data Repository (CLDR) • http://www.unicode.org/cldr/ • “Survival Guide to i18n” (not Rails specific) • http://www.intertwingly.net/stories/2004/04/14/i18n.html Wednesday, March 11, 2009

Notas del editor

  1. - Turn off Growl / IM / Twitterffic / Gmail notifications
  2. - Quick overview of Rails and i18n. - Long topic -- people write books on this!
  3. - &#x201C;m2e c6n&#x201D; - Better at computer languages than human ones - Not an I18n expert / knowledge welcome - SML has users from every country - Talk comes from our work to i18n our Rails app
  4. - Ask: how many have had pleasure of internationalizing an application? - 0: Rails 1.2 added UTF-8 support for string manipulation. Ruby 1.9 adds real UTF-8 support - 1: DHH (Dane) + Matz (Japanese) == English-only? - 1: Rails core is now i18n&#x2019;d, and only localized to English
  5. - Can affect data model! Address shouldn&#x2019;t expect 5-digit ZIP code - People might not use &#x201C;first name&#x201D; &#x201C;last name&#x201D; - A mailbox icon might not register as &#x201C;email&#x201D;. Images of red traffic light for &#x201C;stop&#x201D;.
  6. - Lots of issues to think about - Sorry for the bad Spanish
  7. - The more languages you see, the more Erlang & Haskell look normal - If you like gory details about diacritic marks, tertiary sorting criteria and standards you&#x2019;ll love this!
  8. - Extraction from what we&#x2019;ve learned at SML - End up having some strings in controllers (flash), mailers (subject lines), models (errors) - Mention scoping backoff for key hierarchy
  9. - British English vs. American English - In Japan, but prefer English