Slide 1

Slide 1 text

How to translate your Rails app into over 20 languages Chris Fung - SF Ruby Meetup - November 2024 And why you should! Source: Photo by Isaac Chou on Unsplash

Slide 2

Slide 2 text

• Chris Fung • 🦋 @aergonaut.com • 🐘 @[email protected] • Rubyist for 10 + years • Staff Software Engineer @ Binti Who am I?

Slide 3

Slide 3 text

• We believe every child deserves a loving family! • Foster agencies using Binti approve 40% more families per year, and see a 18% reduction in cycle time, and 40% in time spent for social workers! • 500 + agencies, 34 states (plus DC ) , 150,000 + children in care! What is Binti? 💙

Slide 4

Slide 4 text

Why should you care about localization?

Slide 5

Slide 5 text

What do all these words mean? • l10n - Localization. To adapt content from one locale into another • text: “hello ” -> “óla ” (translation) • dates: 8/24/2024 ( USA ) -> 24/8/2024 ( UK ) • Locale - an identifier representing a language with region and/or script • en; pt-BR; zh-Hant-HK • i18n - Internationalization. To adapt software so it can easily support many languages, scripts, regions, and cultures.

Slide 6

Slide 6 text

Isn ’ t English good enough?

Slide 7

Slide 7 text

😒 Well…

Slide 8

Slide 8 text

Who speaks English as a second language?

Slide 9

Slide 9 text

Who knows someone who speaks ESL?

Slide 10

Slide 10 text

1.5 billion / 8B Worldwide English speakers / total 🌍 population Source: https://www.statista.com/chart/26884/languages-on-the-internet/

Slide 11

Slide 11 text

21.7% US residents speak a language other than English at home Source: https://www.census.gov/acs/www/about/why-we-ask-each-question/language/

Slide 12

Slide 12 text

8.2% US residents speak English less than very well Source: https://www.census.gov/acs/www/about/why-we-ask-each-question/language/

Slide 13

Slide 13 text

🙅 English is not enough!

Slide 14

Slide 14 text

So you want to localize…

Slide 15

Slide 15 text

Roadmap 1. Externalize all your text 2. Choose target locales 3. Translate! 4. Commit and push! 5. Profit!

Slide 16

Slide 16 text

Step 1 - Externalize! • Look for hardcoded text anywhere in your app: • Views:

Edit user

• Controllers: flash[:success] = "Save successful" • Models: errors.add(:title, "cannot be blank")

Slide 17

Slide 17 text

Step 1 - Externalize! • Give each message a key and put it in en.y m l en: users: edit: title: Edit user flash: save: Successfully saved

Slide 18

Slide 18 text

Step 1 - Externalize! • Replace the hardcoded text with I18n.t • Views:

<%= t("users.edit.title") %>

• Controllers: flash[:success] = I18n.t("flash.save") • Models: errors.add(:title, :blank)

Slide 19

Slide 19 text

Step 2 - Choose your target locales • What are your company ’ s goals? • What are your company ’ s most important markets? • Who is your company trying to reach?

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

2.1 - Choose locale codes • Use online tools to find appropriate codes for each language • https://r12a.github.io/app-subtags/index.html • Follow a standard format for your locale codes • IETF language tag: en, pt-BR • GNU language code: pt_BR

Slide 23

Slide 23 text

Step 3 - Translate! • Bigger enterprises might contract with a language services provider ( LSP ) to obtain professional translations. • If you ’ re smaller, consider AI-powered machine translation ( MT ) . • DIY : i18n-tasks gem integrates with OpenAI, Google, DeepL, etc. • Localization platforms such as Crowdin, Phrase

Slide 24

Slide 24 text

3.1 - Setup up i18n-tasks • Add gem 'i18n-tasks', group: :development • Choose a translation provider, e.g. Google Translate • Put your Google Translate API key in GOOGLE _T RANSLA TE _API_KEY • Run i18n-tasks translate- m i ssing -f en -l

Slide 25

Slide 25 text

Step 4 - Commit and push! • Locale files can be very large! • Watch out for: • GitHub may reject pushes that are too big 🙅 • File bloat 📂 • Increased memory usage 💽 • Increased asset size 📦

Slide 26

Slide 26 text

🎉 Congrats! 🎉 Your app is translated!

Slide 27

Slide 27 text

• Localized formatting • dates/numbers/calendars • Plural rules • N applications were updated. • Continuous localization • Automate all the things! Just the beginning! Source: Photo by Ben Neale on Unsplash

Slide 28

Slide 28 text

Binti’s Story

Slide 29

Slide 29 text

From 2 to 21 languages! • Started with English and manually translated Spanish. • Used US Census data on languages spoken at home to identify 19 new languages, covering 65% of “less than ‘very well ’ ” English speakers: • Bangla, German, Greek, French, Canadian French, Gujarati, Croatian, Haitian, Armenian, Italian, Korean, Polish, Portuguese, Brazilian Portuguese, Russian, Tagalog, Ukrainian, Vietnamese, Mandarin Chinese • Translated using i18n-tasks and the Google Translate API ✨ • We learned a lot about multilingual text and UIs!

Slide 30

Slide 30 text

• Browsers fallback to a system font when a script is not supported by the current font. • Minimally: be consistent with either serif or sans-serif as the base of your font stack. • Better to choose a font that supports Latin, Cyrillic, Greek. Multilingual fonts Source: https://rsms.me/inter/

Slide 31

Slide 31 text

• Some scripts, like Arabic, flow right-to-left ( RTL ) . • Many UI elements are mirrored: • Button order ( 3 ) • Checkboxes & icons ( 4 ) • Progress bars fill RTL ( 7 ) • RTL is more than just text! Bidirectional text Source: https://m2.material.io/design/usability/bidirectionality.html

Slide 32

Slide 32 text

• Languages have different preferred formats: • en - ‘Canadian French ’ • de - ‘Französisch ( Kanada) ’ • Don ’ t machine translate! • Source standardized data from Unicode Common Locale Data Repository ( CLDR ) Locale names

Slide 33

Slide 33 text

Source: Photo by Alex Knight on Unsplash Thank you! Good luck on your localization journey!