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
41
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
From here to resilience - a travel guide
ufried
1
160
Taking Flight with Tailwind CSS
opdavies
0
4.3k
社内での継続的な機械学習勉強会の開催のコツ
yudai00
2
380
Prisma ORMを2年運用して培ったノウハウを共有する
tockn
19
5k
エムスリーマルチデバイスチーム紹介資料 / Introduction of M3 Multi Device Team
m3_engineering
0
150
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
1.7k
多言語化対応における TypeScript の型定義を通して開発のしやすさについて考えた / TSKaigi TypeScript Multilingualization
nabeliwo
2
380
DevRelによる信頼構築とデータ駆動で変わるエンジニア採用 / DevRel Trust Building to Data Driven Engineering Hiring
bobtani
1
130
[2024년 5월 세미나] 생성형 AI와 함께하는 데이터 분석가 커리어
datarian
0
1.2k
スクラムに出会って「できた」を実感できるようになってきた話 / Scrum makes me feel like I can do it
yayoi_dd
2
110
本当のガバクラ基礎
toru_kubota
0
310
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
38k
Featured
See All Featured
The Cult of Friendly URLs
andyhume
74
5.7k
What the flash - Photography Introduction
edds
64
11k
4 Signs Your Business is Dying
shpigford
176
21k
Become a Pro
speakerdeck
PRO
13
4.6k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Designing for Performance
lara
601
67k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
YesSQL, Process and Tooling at Scale
rocio
165
13k
How to train your dragon (web standard)
notwaldorf
75
5.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
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?