Ruby on Rails Internationalization Best Practices, i18n SFRAILS

18
March 22nd 2016 by @frederikvollert

Transcript of Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Page 1: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

March 22nd 2016by @frederikvollert

Page 2: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Internationalization"i18n"

Page 3: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Internationalization"i#{'nternationalizatio'.length}n"

Page 4: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

i18n: Preparing code for international audience"Hello!" can become "¡Hola!"

Uber becomes Über, or �berASCII or UTF-8 ?

.de or /de, Accept-Header

03/22/16 2pm PSTor 14:00h 22.03.2016 CET

Anybody got an IBAN or EC-Card?

Copy & Templates

Encoding

Routing & Language detection

Date & Time

Currency & Payment

Page 5: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Tips and Tricks

Prepare early! Use keys in templates from the start; Use constants and symbols instead of string values for e.g. <select> options

UI: Allow 20% stretching space for captions (Even more on buttons)

Every time should be stored as UTC

Money should be stored as integer amounts in smallest unit of currency (No float) with currency name

Make sure you use UTF-8 as encoding

Page 6: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Localization"l10n"

Page 7: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

l10n: Adapting software to a specific locale

Translation of locale file (string file)

Support for local currency

Are your graphics, references and name culturally adequate?

Is your service legal in China? Tax?

pt-BR:welcome: "Oi!"

Does your PSP handle ¥ or € ?

Wix.com, Mitsubishi Pajero

Page 8: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

"Salud" != "Oi"

br != pt-BR

Language code-Country code

Locale codes are well-defined(ISO 3166, ISO 639, RFC 5646)

en-GB, en-US, de-DE, pt-BR, pt-PT

Page 9: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Rails i18n support

I18n.t(:welcome, default: "Hello!", scope: [:home, :index])

Partial in path "app/views/home/index"

<h1>t(".welcome")</h1><h1>t("home.index.welcome")</h1>

I18n.l(@user.created_at, format: :long)Localized time and date notations

Pro-Tip: I18n.with_locale(temporary_locale) do … end

Page 10: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Placeholders

Pluralization

html-suffix

Rails i18n features

greeting: "Hello, %{name}!"

t(:greeting, name: "Frederik")

item:one: "%{count} item"other: "%{count} items"

t(:item, count: @items.length)

body_html: "<b>Statement!</b>"

Page 11: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Language detection

request.env["HTTP_ACCEPT_LANGUAGE"]

I18n.default_locale = :en

Routing param

(Store in cookie)config/routes.rb:

scope "/(:language)", language: /(en|de|fr)/ do get "features" => "home#features"end

Page 12: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Joining translated chunks is a bad idea (as are elaborate placeholders and YAML’s :<< )

SEOTop-level domain brand.de > brand.com/de or de.brand.comHowever, Page authority vs. Domain authority, Google vs. Facebook

Gettext as rails-i18n alternative: https://github.com/grosser/gettext_i18n_rails

Excel spreadsheet-driven processes will not work forever

Additional things to consider

Page 13: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Useful links & gems

Rails i18n guide

https://github.com/enriclluelles/route_translatorI18n routes: /en/cars becomes /de/autos

https://github.com/phrase/slimkeyfyExtract string file from .slim templates easily (Contributions welcome!)

https://github.com/phrase/phraseapp-in-context-editor-rubyIn-context editor for Rails applications

Page 14: Ruby on Rails Internationalization Best Practices, i18n SFRAILS
Page 15: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

<5 minutesvia API

<12 hourswith 1-click

export

PhraseApp Translation Platform

Page 16: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Translate and edit copy inside your Rails app.

PhraseApp Rails In-Context Editor

Page 17: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

FAMILO achieved 400% global user growth;surpassed 1 million users.

"PhraseApp helped us streamline our localization and become an industry leader."

Hauke Windmueller CEO, FAMILO

Page 18: Ruby on Rails Internationalization Best Practices, i18n SFRAILS

Thank you!

Frederik Vollert@frederikvollert+1 (650) [email protected]

PhraseApp720 University AvePalo Alto