aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/golang.org/x/text/cmd/gotext/examples/extract_http
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/text/cmd/gotext/examples/extract_http')
-rwxr-xr-xvendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/de/out.gotext.json39
-rwxr-xr-xvendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/en-US/out.gotext.json39
-rwxr-xr-xvendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/zh/out.gotext.json39
-rw-r--r--vendor/golang.org/x/text/cmd/gotext/examples/extract_http/main.go17
-rw-r--r--vendor/golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go25
5 files changed, 159 insertions, 0 deletions
diff --git a/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/de/out.gotext.json b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/de/out.gotext.json
new file mode 100755
index 0000000..d8437c0
--- /dev/null
+++ b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/de/out.gotext.json
@@ -0,0 +1,39 @@
+{
+ "language": "de",
+ "messages": [
+ {
+ "id": "Hello {From}!",
+ "key": "Hello %s!\n",
+ "message": "Hello {From}!",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "From",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"From\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:22:11"
+ },
+ {
+ "id": "Do you like your browser ({User_Agent})?",
+ "key": "Do you like your browser (%s)?\n",
+ "message": "Do you like your browser ({User_Agent})?",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "User_Agent",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"User-Agent\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:24:11"
+ }
+ ]
+} \ No newline at end of file
diff --git a/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/en-US/out.gotext.json b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/en-US/out.gotext.json
new file mode 100755
index 0000000..de59eca
--- /dev/null
+++ b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/en-US/out.gotext.json
@@ -0,0 +1,39 @@
+{
+ "language": "en-US",
+ "messages": [
+ {
+ "id": "Hello {From}!",
+ "key": "Hello %s!\n",
+ "message": "Hello {From}!",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "From",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"From\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:22:11"
+ },
+ {
+ "id": "Do you like your browser ({User_Agent})?",
+ "key": "Do you like your browser (%s)?\n",
+ "message": "Do you like your browser ({User_Agent})?",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "User_Agent",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"User-Agent\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:24:11"
+ }
+ ]
+} \ No newline at end of file
diff --git a/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/zh/out.gotext.json b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/zh/out.gotext.json
new file mode 100755
index 0000000..0bab4a7
--- /dev/null
+++ b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/locales/zh/out.gotext.json
@@ -0,0 +1,39 @@
+{
+ "language": "zh",
+ "messages": [
+ {
+ "id": "Hello {From}!",
+ "key": "Hello %s!\n",
+ "message": "Hello {From}!",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "From",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"From\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:22:11"
+ },
+ {
+ "id": "Do you like your browser ({User_Agent})?",
+ "key": "Do you like your browser (%s)?\n",
+ "message": "Do you like your browser ({User_Agent})?",
+ "translation": "",
+ "placeholders": [
+ {
+ "id": "User_Agent",
+ "string": "%[1]s",
+ "type": "string",
+ "underlyingType": "string",
+ "argNum": 1,
+ "expr": "r.Header.Get(\"User-Agent\")"
+ }
+ ],
+ "position": "golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go:24:11"
+ }
+ ]
+} \ No newline at end of file
diff --git a/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/main.go b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/main.go
new file mode 100644
index 0000000..c1ac449
--- /dev/null
+++ b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/main.go
@@ -0,0 +1,17 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+//go:generate gotext extract --lang=de,zh
+
+import (
+ "net/http"
+
+ "golang.org/x/text/cmd/gotext/examples/extract_http/pkg"
+)
+
+func main() {
+ http.Handle("/generize", http.HandlerFunc(pkg.Generize))
+}
diff --git a/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go
new file mode 100644
index 0000000..7b44634
--- /dev/null
+++ b/vendor/golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go
@@ -0,0 +1,25 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package pkg
+
+import (
+ "net/http"
+
+ "golang.org/x/text/language"
+ "golang.org/x/text/message"
+)
+
+var matcher = language.NewMatcher(message.DefaultCatalog.Languages())
+
+func Generize(w http.ResponseWriter, r *http.Request) {
+ lang, _ := r.Cookie("lang")
+ accept := r.Header.Get("Accept-Language")
+ tag := message.MatchLanguage(lang.String(), accept)
+ p := message.NewPrinter(tag)
+
+ p.Fprintf(w, "Hello %s!\n", r.Header.Get("From"))
+
+ p.Fprintf(w, "Do you like your browser (%s)?\n", r.Header.Get("User-Agent"))
+}