From 4282e9305930d2c778f2bde6d4803b2690d51aaa Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 16 Dec 2015 18:57:55 +0100 Subject: go.blog/matchlang: new blog on language and locale matching in Go Change-Id: Ibad519a792885b05e1e0c13a7021bdd7c2280735 Reviewed-on: https://go-review.googlesource.com/17806 Reviewed-by: Russ Cox Run-TryBot: Russ Cox --- content/matchlang/complete.go | 32 ++++++++++++++++++++++++++++++ content/matchlang/display.go | 29 +++++++++++++++++++++++++++ content/matchlang/tags.html | 46 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 content/matchlang/complete.go create mode 100644 content/matchlang/display.go create mode 100644 content/matchlang/tags.html (limited to 'content/matchlang') diff --git a/content/matchlang/complete.go b/content/matchlang/complete.go new file mode 100644 index 0000000..a986ef6 --- /dev/null +++ b/content/matchlang/complete.go @@ -0,0 +1,32 @@ +// +build OMIT + +package main + +import ( + "fmt" + + "golang.org/x/text/language" + "golang.org/x/text/language/display" +) + +var userPrefs = []language.Tag{ + language.Make("gsw"), // Swiss German + language.Make("fr"), // French +} + +var serverLangs = []language.Tag{ + language.AmericanEnglish, // en-US fallback + language.German, // de +} + +var matcher = language.NewMatcher(serverLangs) + +func main() { + tag, index, confidence := matcher.Match(userPrefs...) + + fmt.Printf("best match: %s (%s) index=%d confidence=%v\n", + display.English.Tags().Name(tag), + display.Self.Name(tag), + index, confidence) + // best match: German (Deutsch) index=1 confidence=High +} diff --git a/content/matchlang/display.go b/content/matchlang/display.go new file mode 100644 index 0000000..0b84e94 --- /dev/null +++ b/content/matchlang/display.go @@ -0,0 +1,29 @@ +// +build OMIT + +package main + +import ( + "fmt" + + "golang.org/x/text/language" + "golang.org/x/text/language/display" +) + +func main() { + // START OMIT + var supported = []language.Tag{ + language.English, // en + language.French, // fr + language.Dutch, // nl + language.Make("nl-BE"), // nl-BE + language.SimplifiedChinese, // zh-Hans + language.TraditionalChinese, // zh-Hant + language.Russian, // ru + } + + en := display.English.Tags() + for _, t := range supported { + fmt.Printf("%-20s (%s)\n", en.Name(t), display.Self.Name(t)) + } + // END OMIT +} diff --git a/content/matchlang/tags.html b/content/matchlang/tags.html new file mode 100644 index 0000000..bd1d543 --- /dev/null +++ b/content/matchlang/tags.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TagDescription
enEnglish
en-USAmerican English
cmnMandarin Chinese
zhChinese, typically Mandarin
nlDutch
nl-BEFlemish
es-419Latin American Spanish
az, az-Latnboth Azerbaijani written in Latin script
az-ArabAzerbaijani written in Arabic
\ No newline at end of file -- cgit v1.2.3