Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ember, Localization, and You
Search
Colby Ludwig
February 21, 2017
Technology
0
48
Ember, Localization, and You
A guide to love, loss, and localization in Ember.
Presented at a Jobber<>Showbie meetup.
Colby Ludwig
February 21, 2017
Tweet
Share
More Decks by Colby Ludwig
See All by Colby Ludwig
Front-end Testing
cdl
7
280
Putting Mobile First
cdl
4
150
Other Decks in Technology
See All in Technology
Linuxのパッケージ管理とアップデート基礎知識
go_nishimoto
0
690
30代からでも遅くない! 内製開発の世界に飛び込み、最前線で戦うLLMアプリ開発エンジニアになろう
minorun365
PRO
16
4.9k
Azure Maps Visual in PowerBIで分析しよう
nakasho
0
170
OpenLane-V2ベンチマークと代表的な手法
kzykmyzw
0
130
もう難しくない!誰でもカンタンDocker入門 〜30分であなたのPCにアプリを立ち上げる〜
devops_vtj
0
160
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
210
AIエージェント開発手法と業務導入のプラクティス
ykosaka
9
2.5k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
2
410
ドキュメント管理の理想と現実
kazuhe
1
290
Dataverseの検索列について
miyakemito
1
150
PostgreSQL Log File Mastery: Optimizing Database Performance Through Advanced Log Analysis
shiviyer007
PRO
1
140
ビジネスとデザインとエンジニアリングを繋ぐために 一人のエンジニアは何ができるか / What can a single engineer do to connect business, design, and engineering?
kaminashi
2
840
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Typedesign – Prime Four
hannesfritz
41
2.6k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Code Review Best Practice
trishagee
67
18k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
We Have a Design System, Now What?
morganepeng
52
7.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
13
810
BBQ
matthewcrist
88
9.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Transcript
None
Ember, Localization and You A guide to love, loss, and
localization.
None
None
None
Static strings Dynamic strings strings with dynamic content Dynamic, pluralized
strings strings with dynamic content that effects pluralization Doesn’t need to be translated user input, variable data, etc
Static strings Dynamic strings strings with dynamic content Dynamic, pluralized
strings strings with dynamic content that effects pluralization Doesn’t need to be translated user input, straight-up numbers, etc - Class Discussion - no due date - Home - Groups - Students
Dynamic, pluralized strings strings with dynamic content that effects pluralization
Doesn’t need to be translated user input, straight-up numbers, etc - Due February 24 at 4:00PM Dynamic strings strings with dynamic content
Dynamic, pluralized strings strings with dynamic content that effects pluralization
Doesn’t need to be translated user input, straight-up numbers, etc - Due February 24 at 4:00PM Dynamic strings strings with dynamic content
Doesn’t need to be translated user input, straight-up numbers, etc
- 33 posts Dynamic, pluralized strings strings with dynamic content that effects pluralization
Doesn’t need to be translated user input, straight-up numbers, etc
Class Discussion
Class Discussion Ϋϥε σΟεΧογϣϯ
Class Discussion Discussion de classe
Class Discussion Klassdiskussion
How?
How?
ember-i18n ember-intl ember-l10n
ember-i18n ember-intl ember-l10n
cd foobar-app/ ember install ember-i18n
ember-i18n adds a few things… A locale generator ember generate
locale en An i18n service Ember.inject.service(‘i18n’) A {{t}} helper {{t ‘foobar’}}
ember-i18n adds a few things… A locale generator ember generate
locale en An i18n service Ember.inject.service(‘i18n’) A {{t}} helper {{t ‘foobar’}}
ember generate locale en
app/locales/ app/locales/en/ app/locales/en/translations.js app/locales/en/config.js
app/locales/en/config.js app/locales/en/ app/locales/ app/locales/en/translations.js
app/locales/en/translations.js export default { // "some.translation.key": "Text for some.translation.key", //
// "a": { // "nested": { // "key": "Text for a.nested.key" // } // }, // // "key.with.interpolation": "Text with {{anInterpolation}}" };
Static strings? no due date Class Discussion Home Groups Students
app/locales/en/translations.js export default { "Class Discussion": "Class Discussion", "no due
date": "no due date", "Home": "Home", "Groups": "Groups", "Students": "Students" };
some template ... {{#link-to ‘classes.show.discussion’ class}} {{t ‘Class Discussion’}} {{/link-to}}
{{#unless assignment.hasDueDate}} {{t ‘no due date’}} {{/unless}} no due date Class Discussion
Dynamic strings? Due February 24 Hello, Jobber!
app/locales/en/translations.js export default { "Class Discussion": "Class Discussion", "no due
date": "no due date", "Home": "Home", "Groups": "Groups", "Students": “Students”, "Due {{date}}": "Due {{date}}" };
some template ... {{t ‘Due {{date}}’ date=date}} Due February 24
{{! -- pretend ‘date’ is ‘February 24’ --}}
Pluralized, dynamic strings? 27 students 1 post 12 files
1 post
1 post 27 posts
1 post 27 posts one (1) other (2, 10, 20)
count
app/locales/en/translations.js export default { // ... "{{count}} posts": { "one":
"one post", "other": "{{count}} posts" } };
some template ... {{t ‘{{count}} posts’ count=10}} 10 posts {{t
‘{{count}} posts’ count=1}} one post {{t ‘{{count}} posts’ count=0}} 0 posts
some template ... {{t ‘{{count}} posts’ count=10}} 10 posts {{t
‘{{count}} posts’ count=1}} one post {{t ‘{{count}} posts’ count=0}} 0 posts
✅ Static strings ✅ Dynamic strings ✅ Static, pluralized strings
❗ Set up default locale
config/environment.js module.exports = function(environment) { var ENV = { //
... i18n: { defaultLocale: 'en' } }; // ... };
✅ Setting up templates to use t helper ✅ Defining
base strings ✅ Setting up ember-i18n’s default locale ❗Defining the other locales
ember generate locale fr
app/locales/fr/translations.js export default { "Class Discussion": "Discussion de classe", "no
due date": "aucune échéance", "Home": "Accueil", "Groups": "Groupes", "Students": "Élèves", "Due {{date}}": "Dû le {{date}}", "{{count}} posts": { "one": "{{count}} publication", "other": "{{count}} publications" } };
Switch the user to another locale? i18n service! Ember.inject.service(‘i18n’)
app/components/locale-switcher/component.js export default Ember.Component.extend({ i18n: inject.service(), // ... localeChanged(newLocale) {
set(this, 'i18n.locale', newLocale); }) });
So that’s the bulk of it.
✅ Defined translations ✅ Used in templates ✅ Change locale
on the fly
❗But there are a ton of gotchas.
Due {{date}} February 24 ✅ tomorrow? ✅
Inlämningsdatum {{date}} February 24? tomorrow?
computed(function() { return ‘some string’; }) Salut, {{name}} ! Welcome,
<span {{action ‘foo’}}>{{name}}! </span>
None
None
None
None
Right-to-left languages???? Non-English numbers? Date formats?
Lesson one. Localization is hard.
Lesson one. Localization is hard way more complicated than you
expect it to be.
Lesson two. Do your localization from the start. (Or at
least as early as possible.)
None
Lesson three. Don’t reinvent the wheel. Please.
Some tips!
1. Use Moment.js for date formatting. (And everything else when
it comes to dates. It’s so so so good.
2. Don’t concatenate or compose translated strings. Concatenation loses context,
which’ll just frustrate users. 42 students submitted homework
2. Don’t concatenate or compose translated strings. Concatenation loses context,
which’ll just frustrate users. 42 homework students submitted
3. Use a translation service to manage strings! There are
so many out there.
Questions?