Slide 1

Slide 1 text

The Localization Of Marco Cecconi @sklivvz [email protected]

Slide 2

Slide 2 text

Who are we?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

561,027,840 pageviews in the last 30 days* (~100% growth year over year) *source: Quantcast

Slide 6

Slide 6 text

Why did we want to do this?

Slide 7

Slide 7 text

Expert programmers Fluent English EN Stack Overflow

Slide 8

Slide 8 text

Expert programmers Fluent English EN Stack Overflow Fluent Portuguese PT Stack Overflow

Slide 9

Slide 9 text

Different languages make Different communities

Slide 10

Slide 10 text

Expert programmers Stack Overflow

Slide 11

Slide 11 text

We want to make the internet a better place for all

Slide 12

Slide 12 text

Architectural Requirements

Slide 13

Slide 13 text

Easy.

Slide 14

Slide 14 text

Easy. Fast.

Slide 15

Slide 15 text

Performance is a feature

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

1. Allocates two objects per translated string 2. Does a lot of lookups

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

1. No allocation (strings are interned) 2. No lookups 3. Not “easy”, not “usable”

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Simplest/easiest possible code

Slide 23

Slide 23 text

Simplest/easiest possible code Implementation

Slide 24

Slide 24 text

Source Code Compile Time Run Time aspnet_compiler Look Up

Slide 25

Slide 25 text

Simplest/easiest possible code Compiled to the equivalent of this

Slide 26

Slide 26 text

Source Code Compile Time Run Time extended aspnet_compiler using Roslyn Look Up

Slide 27

Slide 27 text

Javascript - No GC pressure so we don’t care about interned strings - Can’t really precompile either - We simply create one set of JS files per language, e.g. “stub.en.js” and “stub.pt.js” - For all that follows, the same APIs are available to Javascript

Slide 28

Slide 28 text

Our solution

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

API _s(string value) Meaning “Substitute String” _m(string value) Meaning “Substitute Markdown”

Slide 31

Slide 31 text

Languages are WEIRD (part 1)

Slide 32

Slide 32 text

_s("Hello $name$", new { name = "Marco" }) Hello Marco

Slide 33

Slide 33 text

一隻雞 兩隻雞

Slide 34

Slide 34 text

1 chicken 2 chickens

Slide 35

Slide 35 text

Language Name Code Category Examples Rules Chinese zh other 0-999; 1.2... other → everything English en one 1 one → n is 1; other → everything else other 0, 2-999; 1.2, 2.07...

Slide 36

Slide 36 text

one 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, … i % 10 = 1 and i % 100 != 11 few 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, … i % 10 = 2..4 and i % 100 != 12..14 many 0, 5~19, 100, 1000, 10000, 100000, 1000000, … i % 10 = 0 or i % 10 = 5..9 or i % 100 = 11..14 other 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … other 0~15, 100, 1000, 10000, 100000, 1000000, … Ukranian!

Slide 37

Slide 37 text

Welsh has SIX modes…

Slide 38

Slide 38 text

_s(“#num# chickens", new { num = 3 }) 3 chickens

Slide 39

Slide 39 text

Behind the scenes All combinations are generated for each language and sent to translators:  For Chinese: “$num:other$ chickens” will be sent  For a 2 mode language: “$num:one$ chickens” and “$num:other$ chickens” will be sent Rules have to be evaluated at runtime to choose the correct translation.

Slide 40

Slide 40 text

Languages are WEIRD (part 2)

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

10 classes called Class I to Class X and containing all sorts of arbitrary groupings but often characterised as • people, • long objects, • animals, • miscellaneous objects, • large objects and liquids, • small objects, • languages, • pejoratives, • infinitives, • mass nouns Uganda

Slide 43

Slide 43 text

_s("Active $~posts$") Attivi _s("Active $~questions$") Attive

Slide 44

Slide 44 text

Post Mortem

Slide 45

Slide 45 text

Some numbers 700 views localized 100,000 lines of code A lot of javascript A LOT of refactoring/fixing/tech debt repayed Very little performance impact ~6 months of work (team of ~3)

Slide 46

Slide 46 text

More numbers Portuguese released Dec. 12 4k Questions 7k Answers 8k Users One of the best performing new communities ever

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Lessons learned

Slide 49

Slide 49 text

Never put non-content text data in the DB It’s A Good Thing™ if all the text to be localized is in the views or javascript.

Slide 50

Slide 50 text

Never compose sentences in code n==1? "1 unicorn": n.ToString() + " unicorns"

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Never assume anything about the language 10 genders and 6 plurals? REALLY?

Slide 53

Slide 53 text

Designing a global application is hard

Slide 54

Slide 54 text

Conclusions

Slide 55

Slide 55 text

1. It’s possible to internationalize quickly and cheaply, without performance hits. 2. Localization is a surprisingly rich problem. There are many gotchas that can be painful later, like pluralization “bugs”. Fun! 3. Localization is a very healthy choice for Stack Overflow and we hope to provide more and more users with a native interface some day :-)

Slide 56

Slide 56 text

Questions? Marco Cecconi @sklivvz [email protected]