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
46
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
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.1k
QAEチームが辿った3年 ボクらが改善業務にスクラムを選んだワケ / 20241108_cloudsign_ques23
bengo4com
0
1.4k
Team Dynamicsを目指すウイングアーク1stのQAチーム
sadonosake
1
320
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
160
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
350
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
140
フルカイテン株式会社 採用資料
fullkaiten
0
40k
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
160
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
190
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
340
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
390
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
43
2.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
What's in a price? How to price your products and services
michaelherold
243
12k
Adopting Sorbet at Scale
ufuk
73
9.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
400
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Being A Developer After 40
akosma
86
590k
Automating Front-end Workflow
addyosmani
1366
200k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Practical Orchestrator
shlominoach
186
10k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
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?