diff options
author | Marcel van Lohuizen <mpvl@golang.org> | 2015-12-16 18:57:55 +0100 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2016-02-09 16:02:48 +0000 |
commit | 4282e9305930d2c778f2bde6d4803b2690d51aaa (patch) | |
tree | dbfcbedcf1fb35c1f5025cdc246bd633ca2d7e6f /content/matchlang | |
parent | 669e5ee757fe572d557eac0d89e0107c8d4ae1a4 (diff) |
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 <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'content/matchlang')
-rw-r--r-- | content/matchlang/complete.go | 32 | ||||
-rw-r--r-- | content/matchlang/display.go | 29 | ||||
-rw-r--r-- | content/matchlang/tags.html | 46 |
3 files changed, 107 insertions, 0 deletions
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 @@ +<style> + .padtable td, .padtable th { padding-right: 10px; } + .tag { font-family: courier; } +</style> +<table class="padtable"> +<tr> + <th>Tag</th> + <th>Description</th> +</tr> +<tr> + <td class="tag">en</td> + <td>English</td> +</tr> +<tr> + <td class="tag">en-US</td> + <td>American English</td> +</tr> +<tr> + <td class="tag">cmn</td> + <td>Mandarin Chinese</td> +</tr> +<tr> + <td class="tag">zh</td> + <td>Chinese, typically Mandarin</td> +</tr> +<tr> + <td class="tag">nl</td> + <td>Dutch</td> +</tr> +<tr> + <td class="tag">nl-BE</td> + <td>Flemish</td> +</tr> +<tr> + <td class="tag">es-419</td> + <td>Latin American Spanish</td> +</tr> +<tr> + <td class="tag">az, az-Latn</td> + <td>both Azerbaijani written in Latin script</td> +</tr> +<tr> + <td class="tag">az-Arab</td> + <td>Azerbaijani written in Arabic</td> +</tr> +</table>
\ No newline at end of file |