SlideShare uma empresa Scribd logo
1 de 18
Internationalizing &
Localizing Your Modern
Javascript App
$ whoami
I’m Johnathan. I work at Airware on the cloud
platform for managing fleets of drones. Before that,
I worked at LinkedIn.
github.com/jleppert, blog @ stuffzies.com
i18n and translating apps is a reoccurring project
for me.
It can be painful, or fun.
Overview
• Why?
• STANDARDS@@@!! Review of the current state
• Strings/Messages: Example App & Code
Why should we translate our
apps?
• More users….? Quicker time to market than competitors.
• Enforce good design principles from day one
• It’s really hard and tedious after you have a lot of code
that didn’t care about it or consider it
• Bolted on i18n usually looks half-baked and janky —
you’ll have to make compromises
• Today’s apps are conversational. More than just about
button labels.
Goals
• Clean, simple workflows: developer first. Shouldn’t
“get in the way”
• Works on server/client with same idioms/API and, if
possible, code
• Shared messages resources for your translators or
translations provider
• Output is cacheable, strings sent down in javascript
bundles
Isn’t there a standard for
this? Kind of…
• ECMA-402 (2012)
• INTL object — available in the latest browsers, and,
now, node (v0.12 mainline — only en_US. Other
locales need a compile option). CLDR data is big.
• INTL.DateTimeFormat - Date formatting
• INTL.NumberFormat - Number formatting
• INTL.Collator (sorting)
ECMA-402: Locale
• Accept-Language standard: IETF (en_US)
• Scripts (zh-Hans, zh-Hant, sr-Cyrl, sr-Latn, etc)
• Unicode extensions: ja-JP-u-ca-japanese
How to use INTL
Step 0: Getting the user’s locale
Sadly, there is no defined API. navigator.language
(chrome/FF) and navigator.browserLanguage in IE,
or read the Accept-Language header.
I prefer to make an intelligent guess, then ask the
user — have it preselected. Store locale (string, e.g.
“en_US”) a cookie that is independent of your
session cookie.
Localizing Dates
new Intl.DateTimeFormat(“es”,
{month:"long"}).format(d)
'Febrero'
new Intl.DateTimeFormat("es",
{month:"long",day:"numeric"}).format(d)
'11 de febrero’
** Use an empty array as the first argument to use the user’s default (browser) locale. May
not be correct, however.
Numbers!!
> new Intl.NumberFormat(“en-US").format(1234.5678);
'1,234.568'
> new Intl.NumberFormat("de").format(1234.5678);
'1.234,568'
> new Intl.NumberFormat("fr").format(1234.5678);
'1 234,568'
> new Intl.NumberFormat("en-US",{style:"percent"})
.format(.023);
'2.3%'
Collation
var coll = new Intl.Collator(['en'], { sensitivity: 'base',
ignorePunctuation: true });
base = a = á, etc.
coll.compare('Bluebird', ‘bluebird') === 0, case is ignored.
coll.compare(‘blackbird’, ‘black-bird’) === 0, punctuation ignored
coll.compare('bluebird', ‘blackbird') === 1, (“u” is after “a”)
What about strings?
Something old, something new: gettext
• It works
• Handles pluralization and positional interpolation
• Use the existing ecosystem of tools, translation
providers
• Template-system, framework agnostic
An example app
• https://github.com/jleppert/rosetajs/
• Using Dust, Jed, po2json, browserify
• Same workflow client or server
• Same message format, code, helpers.
Developer API
• The @i18n template helper.
• {@i18n singular="Hello, {first_name}, you have
one message." plural="Hello, {first_name}, you
have {message_count} messages!"
value=“{message_count}"/}
• API: i18n.translate(‘Hello, {first_name}, you have
a new message!!.’, { first_name: ‘johnathan’});
How does it work?
• Template files and javascript source are read, an AST is
constructed and the @i18n helper calls/API are used to
create a .po file.
• xgettext - extracts translatable strings. I wrote a version that
understands javascript and dust templates, but you can do
so for most any language.
• po files are sent to translators, where they translate the
messages/re-arrange placeholders, etc.
• The right po file is selected based upon the user’s selected
locate and used during template helper/translation API
Let’s see it work
http://localhost:8000
Considerations
• Organize templates by feature (hopefully…)
• Automated tar of po files, send to translators via CI system
• Translate by feature: “this feature is available in english, french,
and spanish will be launched 6/10”
• Suffix files by locale for easy organization and co-locate them
• Check files into some source control project: receive translations
out of order from deployment
• Consider adopting a pirate-speak locale — getttext project has
many such manglers for po files
Thanks, and here’s some
More info
• Mailing List: http://jsi18n.com
• Gettext Overview: https://developer.mozilla.org/en-
US/docs/gettext
• PO/POT Format:
http://pology.nedohodnik.net/doc/user/en_US/ch-
poformat.html
• JS Gettext Implementation:
http://slexaxton.github.io/Jed/
• po2json: https://github.com/mikeedwards/po2json

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Php
PhpPhp
Php
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Create Your Own Language
Create Your Own LanguageCreate Your Own Language
Create Your Own Language
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Sending emails through PHP
Sending emails through PHPSending emails through PHP
Sending emails through PHP
 
Presentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStackPresentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStack
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
LIL Presentation
LIL PresentationLIL Presentation
LIL Presentation
 
Compiler lecture 02
Compiler lecture 02Compiler lecture 02
Compiler lecture 02
 
Python
PythonPython
Python
 
PHP
PHPPHP
PHP
 
javascript 1
javascript 1javascript 1
javascript 1
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Introduction About PHP
 Introduction About PHP Introduction About PHP
Introduction About PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP Syntax & Comments
PHP Syntax & CommentsPHP Syntax & Comments
PHP Syntax & Comments
 
PHP
PHPPHP
PHP
 

Destaque

Seo by jamal
Seo by jamalSeo by jamal
Seo by jamal
Magsnet
 
мп стратегия достижения вашего успеха
мп стратегия достижения вашего успехамп стратегия достижения вашего успеха
мп стратегия достижения вашего успеха
sherif
 
Art Salon @ SENI
Art Salon @ SENIArt Salon @ SENI
Art Salon @ SENI
KC Y
 
บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5
ปวริศา
 

Destaque (19)

การโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickrการโพสต์รูปในเว็บFlickr
การโพสต์รูปในเว็บFlickr
 
Seo by jamal
Seo by jamalSeo by jamal
Seo by jamal
 
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.se
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.seLea PåLsson Knm08 Slutprojekt adhdkvinnor.se
Lea PåLsson Knm08 Slutprojekt adhdkvinnor.se
 
DE VINS
DE VINSDE VINS
DE VINS
 
мп стратегия достижения вашего успеха
мп стратегия достижения вашего успехамп стратегия достижения вашего успеха
мп стратегия достижения вашего успеха
 
Lazy Loading Because I'm Lazy
Lazy Loading Because I'm LazyLazy Loading Because I'm Lazy
Lazy Loading Because I'm Lazy
 
Art Salon @ SENI
Art Salon @ SENIArt Salon @ SENI
Art Salon @ SENI
 
Ministry Presentation
Ministry PresentationMinistry Presentation
Ministry Presentation
 
EQUUSTUR
EQUUSTUR EQUUSTUR
EQUUSTUR
 
SALTRA BANDA
SALTRA BANDASALTRA BANDA
SALTRA BANDA
 
¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demanda¿Qué es la ley de la oferta y la demanda
¿Qué es la ley de la oferta y la demanda
 
Mp ru 2012
Mp ru 2012Mp ru 2012
Mp ru 2012
 
UX Psychology 1st Track.
UX Psychology 1st Track.UX Psychology 1st Track.
UX Psychology 1st Track.
 
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätetJenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
Jenny Ekmark En förstudie hur Skogrand skyltdesign kan positionera sig på nätet
 
Bilaga 1 3 Adhdkvinnor
Bilaga 1 3 AdhdkvinnorBilaga 1 3 Adhdkvinnor
Bilaga 1 3 Adhdkvinnor
 
UX Psychology 2nd Track.
UX Psychology 2nd Track.UX Psychology 2nd Track.
UX Psychology 2nd Track.
 
เทคโนโลยี Web 2
เทคโนโลยี Web 2เทคโนโลยี Web 2
เทคโนโลยี Web 2
 
Fpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging DefinitivaFpt Tesi Scavenging Definitiva
Fpt Tesi Scavenging Definitiva
 
บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5บทเรียน เรื่อง คำกริยา ป.5
บทเรียน เรื่อง คำกริยา ป.5
 

Semelhante a I18n

Chapter-introduction about java programming
Chapter-introduction about java programmingChapter-introduction about java programming
Chapter-introduction about java programming
DrRajeshkumarPPatel
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
Tim Burks
 

Semelhante a I18n (20)

Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
computer languages
computer languagescomputer languages
computer languages
 
Desktop Apps with PHP and Titanium
Desktop Apps with PHP and TitaniumDesktop Apps with PHP and Titanium
Desktop Apps with PHP and Titanium
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
 
Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Chapter-introduction about java programming
Chapter-introduction about java programmingChapter-introduction about java programming
Chapter-introduction about java programming
 
Mini-Training: TypeScript
Mini-Training: TypeScriptMini-Training: TypeScript
Mini-Training: TypeScript
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Introduction to Python Programming Basics
Introduction  to  Python  Programming BasicsIntroduction  to  Python  Programming Basics
Introduction to Python Programming Basics
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

I18n

  • 1. Internationalizing & Localizing Your Modern Javascript App
  • 2. $ whoami I’m Johnathan. I work at Airware on the cloud platform for managing fleets of drones. Before that, I worked at LinkedIn. github.com/jleppert, blog @ stuffzies.com i18n and translating apps is a reoccurring project for me. It can be painful, or fun.
  • 3. Overview • Why? • STANDARDS@@@!! Review of the current state • Strings/Messages: Example App & Code
  • 4. Why should we translate our apps? • More users….? Quicker time to market than competitors. • Enforce good design principles from day one • It’s really hard and tedious after you have a lot of code that didn’t care about it or consider it • Bolted on i18n usually looks half-baked and janky — you’ll have to make compromises • Today’s apps are conversational. More than just about button labels.
  • 5. Goals • Clean, simple workflows: developer first. Shouldn’t “get in the way” • Works on server/client with same idioms/API and, if possible, code • Shared messages resources for your translators or translations provider • Output is cacheable, strings sent down in javascript bundles
  • 6. Isn’t there a standard for this? Kind of… • ECMA-402 (2012) • INTL object — available in the latest browsers, and, now, node (v0.12 mainline — only en_US. Other locales need a compile option). CLDR data is big. • INTL.DateTimeFormat - Date formatting • INTL.NumberFormat - Number formatting • INTL.Collator (sorting)
  • 7. ECMA-402: Locale • Accept-Language standard: IETF (en_US) • Scripts (zh-Hans, zh-Hant, sr-Cyrl, sr-Latn, etc) • Unicode extensions: ja-JP-u-ca-japanese
  • 8. How to use INTL Step 0: Getting the user’s locale Sadly, there is no defined API. navigator.language (chrome/FF) and navigator.browserLanguage in IE, or read the Accept-Language header. I prefer to make an intelligent guess, then ask the user — have it preselected. Store locale (string, e.g. “en_US”) a cookie that is independent of your session cookie.
  • 9. Localizing Dates new Intl.DateTimeFormat(“es”, {month:"long"}).format(d) 'Febrero' new Intl.DateTimeFormat("es", {month:"long",day:"numeric"}).format(d) '11 de febrero’ ** Use an empty array as the first argument to use the user’s default (browser) locale. May not be correct, however.
  • 10. Numbers!! > new Intl.NumberFormat(“en-US").format(1234.5678); '1,234.568' > new Intl.NumberFormat("de").format(1234.5678); '1.234,568' > new Intl.NumberFormat("fr").format(1234.5678); '1 234,568' > new Intl.NumberFormat("en-US",{style:"percent"}) .format(.023); '2.3%'
  • 11. Collation var coll = new Intl.Collator(['en'], { sensitivity: 'base', ignorePunctuation: true }); base = a = á, etc. coll.compare('Bluebird', ‘bluebird') === 0, case is ignored. coll.compare(‘blackbird’, ‘black-bird’) === 0, punctuation ignored coll.compare('bluebird', ‘blackbird') === 1, (“u” is after “a”)
  • 12. What about strings? Something old, something new: gettext • It works • Handles pluralization and positional interpolation • Use the existing ecosystem of tools, translation providers • Template-system, framework agnostic
  • 13. An example app • https://github.com/jleppert/rosetajs/ • Using Dust, Jed, po2json, browserify • Same workflow client or server • Same message format, code, helpers.
  • 14. Developer API • The @i18n template helper. • {@i18n singular="Hello, {first_name}, you have one message." plural="Hello, {first_name}, you have {message_count} messages!" value=“{message_count}"/} • API: i18n.translate(‘Hello, {first_name}, you have a new message!!.’, { first_name: ‘johnathan’});
  • 15. How does it work? • Template files and javascript source are read, an AST is constructed and the @i18n helper calls/API are used to create a .po file. • xgettext - extracts translatable strings. I wrote a version that understands javascript and dust templates, but you can do so for most any language. • po files are sent to translators, where they translate the messages/re-arrange placeholders, etc. • The right po file is selected based upon the user’s selected locate and used during template helper/translation API
  • 16. Let’s see it work http://localhost:8000
  • 17. Considerations • Organize templates by feature (hopefully…) • Automated tar of po files, send to translators via CI system • Translate by feature: “this feature is available in english, french, and spanish will be launched 6/10” • Suffix files by locale for easy organization and co-locate them • Check files into some source control project: receive translations out of order from deployment • Consider adopting a pirate-speak locale — getttext project has many such manglers for po files
  • 18. Thanks, and here’s some More info • Mailing List: http://jsi18n.com • Gettext Overview: https://developer.mozilla.org/en- US/docs/gettext • PO/POT Format: http://pology.nedohodnik.net/doc/user/en_US/ch- poformat.html • JS Gettext Implementation: http://slexaxton.github.io/Jed/ • po2json: https://github.com/mikeedwards/po2json

Notas do Editor

  1. solving this problem many times isn’t a sexy problem, but very important for the company developer systems, processes: good, bad and ugly calltech to teleperformance, traffic increases as more people can actually read and interact with the app in their language: step 0 in personalization airware, drones aren’t legal in us, so the app needs to be international from the start rethinking things to ease roll-out, new languages, process, translation quality.
  2. everybody loves standards, when they do……come INTL standards Example app, can use everything as is, or just use the concepts
  3. more users is obvious, more users === more money for most people german: “my profile” = 32 characters. tabs will fall off the page airplane analogy
  4. lots of people use keys. keys. LONG keys. short keys. bad keys. positional? what’s that? plural? we only got one.
  5. started work in 2012. embarrassing. CLDR - big tech companies unite. lots of data. locale data.
  6. locale, region
  7. they forgot this part of the standard. step 0. yeah.
  8. translators may need to re-arrange placeholders it’s a PROCESS
  9. buzzword alert: isomorphic. i love that word. why i like dust: streams, compiling, fast. AST.
  10. introducing
  11. demo poedit change stuff, see if it works