Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ember, Localization, and You

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

More Decks by Colby Ludwig

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. Doesn’t need to be translated user input, straight-up numbers, etc

    - 33 posts Dynamic, pluralized strings strings with dynamic content that effects pluralization
  6. 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’}}
  7. 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’}}
  8. 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}}" };
  9. app/locales/en/translations.js export default { "Class Discussion": "Class Discussion", "no due

    date": "no due date", "Home": "Home", "Groups": "Groups", "Students": "Students" };
  10. 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
  11. 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}}" };
  12. some template ... {{t ‘Due {{date}}’ date=date}} Due February 24

    {{! -- pretend ‘date’ is ‘February 24’ --}}
  13. some template ... {{t ‘{{count}} posts’ count=10}} 10 posts {{t

    ‘{{count}} posts’ count=1}} one post {{t ‘{{count}} posts’ count=0}} 0 posts
  14. some template ... {{t ‘{{count}} posts’ count=10}} 10 posts {{t

    ‘{{count}} posts’ count=1}} one post {{t ‘{{count}} posts’ count=0}} 0 posts
  15. ✅ Setting up templates to use t helper ✅ Defining

    base strings ✅ Setting up ember-i18n’s default locale ❗Defining the other locales
  16. 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" } };
  17. 1. Use Moment.js for date formatting. (And everything else when

    it comes to dates. It’s so so so good.
  18. 2. Don’t concatenate or compose translated strings. Concatenation loses context,

    which’ll just frustrate users. 42 students submitted homework
  19. 2. Don’t concatenate or compose translated strings. Concatenation loses context,

    which’ll just frustrate users. 42 homework students submitted