Slide 1

Slide 1 text

GetText I18N : internationalization

Slide 2

Slide 2 text

$ finger abelar_s • EPITA MTI 2008 • Using Rails since my 1st internship, sept.2006 (that was around rails 1.0) • R&D engineer at Faveod • We develop, market and sell our technology Faveod Designer • Faveod Designer helps you create complex web applications faster • You describe your specs and it just works. Easier, better, faster, stronger http://www.linkedin.com/in/sylvainabelard

Slide 3

Slide 3 text

Meet GetText • Why? • You’ll want to make your app global • GetText is a UNIX standard • How? • Translators’ horror stories • Show me some code! • What? • Tools around GetText • Alternatives GNU GetText: GetText’s Never Useless

Slide 4

Slide 4 text

Rails I18N • Simple • Always has a default • No complex keys • Never get « no translation found » • Never get fuzzy translations shown GNU GetText: GetText’s Never Useless

Slide 5

Slide 5 text

Horror Stories No, really. Did you try? • One word, one translation? • Grammar: number, gender, case • Number looks simple enough: car/cars, but child/children and person/people • Many languages have a difference for one, two and more. Some have even more. • Gender is often masculine, feminine or neuter (and rarely intuitive) • Some languages have differences for inanimate and animate (personal or impersonal) • Conjugation: person, tense, mood, voice, aspect • ... ok, let’s not even try this

Slide 6

Slide 6 text

What to use? • github.com/grosser/fast_gettext • Improvements • 3.5x faster, 560x less memory • thread safety • simple, clean namespace • Backends • .mo and .po files • .yml • DB • ... code your own Michael Grosser’s FastGetText!

Slide 7

Slide 7 text

Setup • PO/MO files • These are where you store key / values per language • Many great tools for PO files, including an emacs mode • Setting the locale • You select the locale for each use (in Rails: request-wide, it’s thread-safe) • Setup How to GetText part 1 GetText.locale = "fr" init_gettext "my_app" I18n.supported_locales = ["en", "fr", "de", "ar", "ru"] # better: make it guess from existing files I18n.default_locale = "fr" # en is the default

Slide 8

Slide 8 text

Usage • The « underscore » function • _("string") • Variables, the printf way • _("string with %s") % "arg" • _("string with %s and %s") % ["arg1", "arg2"] • Variables, the right way • _("Could not find this %{obj}") % {:obj => _("stuff")} • Now on to our horror stories How to GetText part II

Slide 9

Slide 9 text

Tricks • Singular / plural • n_("File not found!", "%{n} files not found!", n) % {:n => n} • That’s great, but how about tricky plurals? "Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;\n" • FastGettext.pluralisation_rule = lambda{|count| count > 5 ? 1 : (count > 2 ? 0 : 2)} • Context • s_("File|Open") # ouvrir • s_("Sports|Open") # open • s_("Even|More|Contexts|Open") # only translates ‘open‘ • p_("even more bindinds", "for contexts", "open") # open How to GetText part III

Slide 10

Slide 10 text

PO files • Update your files • rake updatepo • This will flag unused translations as obsolete and try to guess new ones (« fuzzy ») • Edit your files # translator comments #. extracted comments #: reference #, flag msgid "One file removed" msgid_plural "%d files removed" msgstr[0] "%d slika uklonjenih" msgstr[1] "%d slika uklonjenih" msgstr[2] "%d slika uklonjenih" • Update your translations • rake makemo Don’t do this manually, use tools.

Slide 11

Slide 11 text

Questions? Also, we’re hiring, but that’s the next slide http://ruby-i18n.org/wiki http://www.gnu.org/software/gettext/manual/gettext.html