summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/text/language/examples_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/language/examples_test.go')
-rw-r--r--vendor/golang.org/x/text/language/examples_test.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/vendor/golang.org/x/text/language/examples_test.go b/vendor/golang.org/x/text/language/examples_test.go
index 05e712d77..d5e8176dc 100644
--- a/vendor/golang.org/x/text/language/examples_test.go
+++ b/vendor/golang.org/x/text/language/examples_test.go
@@ -6,6 +6,7 @@ package language_test
import (
"fmt"
+ "net/http"
"golang.org/x/text/language"
)
@@ -274,7 +275,7 @@ func ExampleMatcher() {
fmt.Println("----")
- // Croatian speakers will likely understand Serbian written in Latin script.
+ // Someone specifying sr-Latn is probably fine with getting Croatian.
fmt.Println(m.Match(language.Make("sr-Latn")))
// We match SimplifiedChinese, but with Low confidence.
@@ -331,11 +332,27 @@ func ExampleMatcher() {
// af 3 High
// ----
// iw 9 Exact
- // iw-IL 8 Exact
+ // he 10 Exact
// ----
// fr-u-cu-frf 2 Exact
// fr-u-cu-frf 2 High
// en-u-co-phonebk 0 No
+
+ // TODO: "he" should be "he-u-rg-IL High"
+}
+
+func ExampleMatchStrings() {
+ // languages supported by this service:
+ matcher := language.NewMatcher([]language.Tag{
+ language.English, language.Dutch, language.German,
+ })
+
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ lang, _ := r.Cookie("lang")
+ tag, _ := language.MatchStrings(matcher, lang.String(), r.Header.Get("Accept-Language"))
+
+ fmt.Println("User language:", tag)
+ })
}
func ExampleComprehends() {