හਁ, ᨵ૰, ෭๗ᳵ໒ୗ • ܔ֖ഘ I18n and L10n • Searching and Sorting • Upper, lower, title case • Bi-directional text • Injecting translated text • Formatting of numbers, currency, date, time • Unit conversion
ଚӧᥝਁᒧԀᶳฎ୭Ӟ۸ݸጱ String Model • Always UTF-8 • Same model for source code as for text handling! • No random access • No meta data (except for byte length) or string “object” • Strings not in canonical form
transform.String(encoder, "֦অ") ݶय़᮱ړկ۱׀ԧොጱᤰ s := encoder.String("֦অ") w := norm.NFC.Writer(w) • A transform is typically used with one of the helpers functions. • Most packages provide convenience wrappers Using Transformers
ᒵհਁᒧғå 㱻 aaҁԄἈ҂҅ ß 㱻 ssҁ҂ • ᯿ഭଧғZ < ÅҁԄἈ҂ • ّᒵհғK (U+004B) 㱻 K (U+212A) • ݍଧഭڜے೭य़ဩӾଃᶪ᧣ጱਁᒧ Multilingual Search and Sort • Accented characters: e < é < f • Multi-letter characters: "ch" in Spanish • Equivalences: å 㱻 aa in Danish ß 㱻 ss in German • Reordering: Z < Å in Danish • Compatibility equivalence: K (U+004B) 㱻 K (U+212A) • Reverse sorting of accents in Canadian French
1. “We went to a cafe.” 2. “We went to a café.” 3. “We went to a cafe/u0301.” • ᒫӣӻֺݙጱᕮຎ: “We went to many cafes/u0301.” ҖNFC 㱺 “We went to many cafeś.” ᓌܔጱܔਁᜓᔱ๊ഘଚӧᭇአѺ Search and Replace Simple byte-oriented search and replace will not work!
m.IndexString(text, s) match := s[start:end] SEARCH TEXT MATCH aarhus Århus a\u0303\u031b Århus a a\u0303\u031b a\u031b\u0303 a\u0303\u031b search Example
๚ᦇښጱғ • ᰒᇙਧጱړۆ • ཻᬨᛔᐒ܄ጱଆۗ Segmentation Support • Planned: • API for segmentation • Supported by Unicode: • word, line, sentence, paragraph • Not planned: • Language-specific segmentation • Community support welcome
gsw • cmnฎฦ᭗ᦾ҅zhๅଉአ • hr ܃ᯈ sr-Latn ࣁx/text/language᯾ጱmatcherᚆᥴ٬ᬯӻᳯ᷌ Matching is Non-Trivial • Swiss German speakers usually understand German gsw 㱺 de • The converse is not often true! de ≯ gsw • cmn is Mandarin Chinese, zh is more commonly used • hr matches sr-Latn The Matcher in x/text/language solves this problem
your application var matcher = language.NewMatcher([]language.Tag{ language.SimplifiedChinese, // zh-Hans language.AmericanEnglish, // en-US }) func handle(w http.ResponseWriter, r *http.Request) { prefs, _, _ := language.ParseAcceptLanguage(r.Header.Get(“Accept-Language”)) tag, _, _ := matcher.Match(prefs…) // use tag; it includes carried over user preference } Language Matching in Go
य़ੜٟ॒ቘ • ᕮຎຽᓋӾ൭ଃํአಁጱᦡᗝ Language Matching Recap • Find best supported language for list of user- preferred languages • Use matched tag to select language-specific resources • translations • sort order • case operations • Resulting tag has carried over user settings
Text • Mark text within your code To Be Translated • Extract the text from your code • Send to translators • Insert translated messages back into your code
fmt.Printf(“%[1]s went to %[2]s.”, person, city) import ”golang.org/x/text/message” p := message.NewPrinter(userLang) // Report that person visited a city. p.Printf(“%[1]s went to %[2]s.”, person, city) ԏڹғ ԏݸғ Mark Text “To Be Translated”
golang.org/design/12750-localization Planned extensions • Go tooling: automate extraction and insertion • Planned: • number formatting • selection based on plurals, gender, etc. •golang.org/design/12750-localization