1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Add FeedIcon API call and update dependencies

This commit is contained in:
Frédéric Guillot 2017-12-16 11:25:18 -08:00
parent 231ebf2daa
commit 27196589fb
262 changed files with 83830 additions and 30061 deletions

49
vendor/golang.org/x/text/cmd/gotext/common.go generated vendored Normal file
View file

@ -0,0 +1,49 @@
// 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
import (
"fmt"
"go/build"
"go/parser"
"golang.org/x/tools/go/loader"
)
const (
extractFile = "extracted.gotext.json"
outFile = "out.gotext.json"
gotextSuffix = ".gotext.json"
)
// NOTE: The command line tool already prefixes with "gotext:".
var (
wrap = func(err error, msg string) error {
if err == nil {
return nil
}
return fmt.Errorf("%s: %v", msg, err)
}
errorf = fmt.Errorf
)
// TODO: still used. Remove when possible.
func loadPackages(conf *loader.Config, args []string) (*loader.Program, error) {
if len(args) == 0 {
args = []string{"."}
}
conf.Build = &build.Default
conf.ParserMode = parser.ParseComments
// Use the initial packages from the command line.
args, err := conf.FromArgs(args, false)
if err != nil {
return nil, wrap(err, "loading packages failed")
}
// Load, parse and type-check the whole program.
return conf.Load()
}

View file

@ -1,9 +1,4 @@
// Copyright 2016 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.
// DO NOT EDIT THIS FILE. GENERATED BY go generate.
// Edit the documentation in other files and rerun go generate to generate this one.
// Code generated by go generate. DO NOT EDIT.
// gotext is a tool for managing text in Go source code.
//
@ -13,7 +8,9 @@
//
// The commands are:
//
// extract extract strings to be translated from code
// extract extracts strings to be translated from code
// rewrite rewrites fmt functions to use a message Printer
// generate generates code to insert translated messages
//
// Use "go help [command]" for more information about a command.
//
@ -23,7 +20,7 @@
// Use "gotext help [topic]" for more information about that topic.
//
//
// Extract strings to be translated from code
// Extracts strings to be translated from code
//
// Usage:
//
@ -32,4 +29,25 @@
//
//
//
// Rewrites fmt functions to use a message Printer
//
// Usage:
//
// go rewrite <package>
//
// rewrite is typically done once for a project. It rewrites all usages of
// fmt to use x/text's message package whenever a message.Printer is in scope.
// It rewrites Print and Println calls with constant strings to the equivalent
// using Printf to allow translators to reorder arguments.
//
//
// Generates code to insert translated messages
//
// Usage:
//
// go generate <package>
//
//
//
//
package main

View file

@ -0,0 +1,78 @@
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
"golang.org/x/text/message/catalog"
)
type dictionary struct {
index []uint32
data string
}
func (d *dictionary) Lookup(key string) (data string, ok bool) {
p := messageKeyToIndex[key]
start, end := d.index[p], d.index[p+1]
if start == end {
return "", false
}
return d.data[start:end], true
}
func init() {
dict := map[string]catalog.Dictionary{
"de": &dictionary{index: deIndex, data: deData},
"en_US": &dictionary{index: en_USIndex, data: en_USData},
"zh": &dictionary{index: zhIndex, data: zhData},
}
fallback := language.MustParse("en-US")
cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback))
if err != nil {
panic(err)
}
message.DefaultCatalog = cat
}
var messageKeyToIndex = map[string]int{
"%.2[1]f miles traveled (%[1]f)": 6,
"%[1]s is visiting %[3]s!\n": 3,
"%d more files remaining!": 4,
"%s is out of order!": 5,
"%s is visiting %s!\n": 2,
"Hello %s!\n": 1,
"Hello world!\n": 0,
}
var deIndex = []uint32{ // 8 elements
0x00000000, 0x00000011, 0x00000023, 0x0000003d,
0x00000057, 0x00000076, 0x00000076, 0x00000076,
} // Size: 56 bytes
const deData string = "" + // Size: 118 bytes
"\x04\x00\x01\x0a\x0c\x02Hallo Welt!\x04\x00\x01\x0a\x0d\x02Hallo %[1]s!" +
"\x04\x00\x01\x0a\x15\x02%[1]s besucht %[2]s!\x04\x00\x01\x0a\x15\x02%[1]" +
"s besucht %[3]s!\x02Noch %[1]d Bestände zu gehen!"
var en_USIndex = []uint32{ // 8 elements
0x00000000, 0x00000012, 0x00000024, 0x00000042,
0x00000060, 0x000000a3, 0x000000ba, 0x000000d9,
} // Size: 56 bytes
const en_USData string = "" + // Size: 217 bytes
"\x04\x00\x01\x0a\x0d\x02Hello world!\x04\x00\x01\x0a\x0d\x02Hello %[1]s!" +
"\x04\x00\x01\x0a\x19\x02%[1]s is visiting %[2]s!\x04\x00\x01\x0a\x19\x02" +
"%[1]s is visiting %[3]s!\x14\x01\x81\x01\x00\x02\x14\x02One file remaini" +
"ng!\x00&\x02There are %[1]d more files remaining!\x02%[1]s is out of ord" +
"er!\x02%.2[1]f miles traveled (%[1]f)"
var zhIndex = []uint32{ // 8 elements
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
} // Size: 56 bytes
const zhData string = ""
// Total table size 503 bytes (0KiB); checksum: A968BD6

View file

@ -0,0 +1,186 @@
{
"language": "de",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "Hallo Welt!",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "Hallo {City}!",
"placeholders": [
{
"id": "City",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "city"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:31:10"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "Hallo {Town}!",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:35:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "{Person} besucht {Place}!",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "person",
"comment": "The person of matter."
},
{
"id": "Place",
"string": "%[2]s",
"type": "string",
"underlyingType": "string",
"argNum": 2,
"expr": "place",
"comment": "Place the person is visiting."
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:40:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "{Person} besucht {Place}!",
"comment": "Person visiting a place.",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "pp.Person"
},
{
"id": "Place",
"string": "%[3]s",
"type": "string",
"underlyingType": "string",
"argNum": 3,
"expr": "pp.Place",
"comment": "Place the person is visiting."
},
{
"id": "Extra",
"string": "%[2]v",
"type": "int",
"underlyingType": "int",
"argNum": 2,
"expr": "pp.extra"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:55:10"
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": "Noch {N} Bestände zu gehen!",
"placeholders": [
{
"id": "N",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "n"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:67:10"
},
{
"id": "Use the following code for your discount: {ReferralCode}",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}",
"translation": "",
"placeholders": [
{
"id": "ReferralCode",
"string": "%[1]d",
"type": "golang.org/x/text/cmd/gotext/examples/extract.referralCode",
"underlyingType": "int",
"argNum": 1,
"expr": "c"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:73:10"
},
{
"id": [ "msgOutOfOrder", "{Device} is out of order!" ],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "",
"comment": "FOO\n",
"placeholders": [
{
"id": "Device",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "device"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:81:10"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "",
"placeholders": [
{
"id": "Miles",
"string": "%.2[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
},
{
"id": "Miles_1",
"string": "%[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:85:10"
}
]
}

View file

@ -0,0 +1,206 @@
{
"language": "de",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:28:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "",
"placeholders": [
{
"id": "City",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "city"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:32:10"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:36:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "person",
"comment": "The person of matter."
},
{
"id": "Place",
"string": "%[2]s",
"type": "string",
"underlyingType": "string",
"argNum": 2,
"expr": "place",
"comment": "Place the person is visiting."
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:41:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"comment": "Person visiting a place.",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "pp.Person"
},
{
"id": "Place",
"string": "%[3]s",
"type": "string",
"underlyingType": "string",
"argNum": 3,
"expr": "pp.Place",
"comment": "Place the person is visiting."
},
{
"id": "Extra",
"string": "%[2]v",
"type": "int",
"underlyingType": "int",
"argNum": 2,
"expr": "pp.extra"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:56:10"
},
{
"id": "{2} files remaining!",
"key": "%d files remaining!",
"message": "{2} files remaining!",
"translation": "",
"placeholders": [
{
"id": "2",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "2"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:63:10"
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": "",
"placeholders": [
{
"id": "N",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "n"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:68:10"
},
{
"id": "Use the following code for your discount: {ReferralCode}",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}",
"translation": "",
"placeholders": [
{
"id": "ReferralCode",
"string": "%[1]d",
"type": "golang.org/x/text/cmd/gotext/examples/extract.referralCode",
"underlyingType": "int",
"argNum": 1,
"expr": "c"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:74:10"
},
{
"id": [
"msgOutOfOrder",
"{Device} is out of order!"
],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "",
"comment": "FOO\n",
"placeholders": [
{
"id": "Device",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "device"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:82:10"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "",
"placeholders": [
{
"id": "Miles",
"string": "%.2[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
},
{
"id": "Miles_1",
"string": "%[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:86:10"
}
]
}

View file

@ -0,0 +1,82 @@
{
"language": "en-US",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "Hello world!",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "Hello {City}n"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "Hello {Town}!",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
]
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "{Person} is visiting {Place}!\n"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "{Person} is visiting {Place}!",
"comment": "Person visiting a place."
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": {
"select": {
"feature": "plural",
"arg": "N",
"cases": {
"one": "One file remaining!",
"other": "There are {N} more files remaining!"
}
}
}
},
{
"id": "Use the following code for your discount: {ReferralCode}",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}",
"translation": ""
},
{
"id": [ "msgOutOfOrder", "{Device} is out of order!" ],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "{Device} is out of order!",
"comment": "FOO\n"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "{Miles} miles traveled ({Miles_1})"
}
]
}

View file

@ -0,0 +1,206 @@
{
"language": "en-US",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:28:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "",
"placeholders": [
{
"id": "City",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "city"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:32:10"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:36:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "person",
"comment": "The person of matter."
},
{
"id": "Place",
"string": "%[2]s",
"type": "string",
"underlyingType": "string",
"argNum": 2,
"expr": "place",
"comment": "Place the person is visiting."
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:41:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"comment": "Person visiting a place.",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "pp.Person"
},
{
"id": "Place",
"string": "%[3]s",
"type": "string",
"underlyingType": "string",
"argNum": 3,
"expr": "pp.Place",
"comment": "Place the person is visiting."
},
{
"id": "Extra",
"string": "%[2]v",
"type": "int",
"underlyingType": "int",
"argNum": 2,
"expr": "pp.extra"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:56:10"
},
{
"id": "{2} files remaining!",
"key": "%d files remaining!",
"message": "{2} files remaining!",
"translation": "",
"placeholders": [
{
"id": "2",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "2"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:63:10"
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": "",
"placeholders": [
{
"id": "N",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "n"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:68:10"
},
{
"id": "Use the following code for your discount: {ReferralCode}",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}",
"translation": "",
"placeholders": [
{
"id": "ReferralCode",
"string": "%[1]d",
"type": "golang.org/x/text/cmd/gotext/examples/extract.referralCode",
"underlyingType": "int",
"argNum": 1,
"expr": "c"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:74:10"
},
{
"id": [
"msgOutOfOrder",
"{Device} is out of order!"
],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "",
"comment": "FOO\n",
"placeholders": [
{
"id": "Device",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "device"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:82:10"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "",
"placeholders": [
{
"id": "Miles",
"string": "%.2[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
},
{
"id": "Miles_1",
"string": "%[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:86:10"
}
]
}

View file

@ -0,0 +1,203 @@
{
"language": "zh",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "",
"placeholders": [
{
"id": "City",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "city"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:31:10"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:35:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "person",
"comment": "The person of matter."
},
{
"id": "Place",
"string": "%[2]s",
"type": "string",
"underlyingType": "string",
"argNum": 2,
"expr": "place",
"comment": "Place the person is visiting."
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:40:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"comment": "Person visiting a place.",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "pp.Person"
},
{
"id": "Place",
"string": "%[3]s",
"type": "string",
"underlyingType": "string",
"argNum": 3,
"expr": "pp.Place",
"comment": "Place the person is visiting."
},
{
"id": "Extra",
"string": "%[2]v",
"type": "int",
"underlyingType": "int",
"argNum": 2,
"expr": "pp.extra"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:55:10"
},
{
"id": "{} files remaining!",
"key": "%d files remaining!",
"message": "{} files remaining!",
"translation": "",
"placeholders": [
{
"id": "",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "2"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:62:10"
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": "",
"placeholders": [
{
"id": "N",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "n"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:67:10"
},
{
"id": "Use the following code for your discount: {ReferralCode}\n",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}\n",
"translation": "",
"placeholders": [
{
"id": "ReferralCode",
"string": "%[1]d",
"type": "golang.org/x/text/cmd/gotext/examples/extract.referralCode",
"underlyingType": "int",
"argNum": 1,
"expr": "c"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:73:10"
},
{
"id": [ "{Device} is out of order!", "msgOutOfOrder" ],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "",
"comment": "FOO\n",
"placeholders": [
{
"id": "Device",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "device"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:81:10"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "",
"placeholders": [
{
"id": "Miles",
"string": "%.2[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
},
{
"id": "Miles_1",
"string": "%[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:85:10"
}
]
}

View file

@ -0,0 +1,206 @@
{
"language": "zh",
"messages": [
{
"id": "Hello world!",
"key": "Hello world!\n",
"message": "Hello world!",
"translation": "",
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:28:10"
},
{
"id": "Hello {City}!",
"key": "Hello %s!\n",
"message": "Hello {City}!",
"translation": "",
"placeholders": [
{
"id": "City",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "city"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:32:10"
},
{
"id": "Hello {Town}!",
"key": "Hello %s!\n",
"message": "Hello {Town}!",
"translation": "",
"placeholders": [
{
"id": "Town",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "town",
"comment": "Town"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:36:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%s is visiting %s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "person",
"comment": "The person of matter."
},
{
"id": "Place",
"string": "%[2]s",
"type": "string",
"underlyingType": "string",
"argNum": 2,
"expr": "place",
"comment": "Place the person is visiting."
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:41:10"
},
{
"id": "{Person} is visiting {Place}!",
"key": "%[1]s is visiting %[3]s!\n",
"message": "{Person} is visiting {Place}!",
"translation": "",
"comment": "Person visiting a place.",
"placeholders": [
{
"id": "Person",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "pp.Person"
},
{
"id": "Place",
"string": "%[3]s",
"type": "string",
"underlyingType": "string",
"argNum": 3,
"expr": "pp.Place",
"comment": "Place the person is visiting."
},
{
"id": "Extra",
"string": "%[2]v",
"type": "int",
"underlyingType": "int",
"argNum": 2,
"expr": "pp.extra"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:56:10"
},
{
"id": "{2} files remaining!",
"key": "%d files remaining!",
"message": "{2} files remaining!",
"translation": "",
"placeholders": [
{
"id": "2",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "2"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:63:10"
},
{
"id": "{N} more files remaining!",
"key": "%d more files remaining!",
"message": "{N} more files remaining!",
"translation": "",
"placeholders": [
{
"id": "N",
"string": "%[1]d",
"type": "int",
"underlyingType": "int",
"argNum": 1,
"expr": "n"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:68:10"
},
{
"id": "Use the following code for your discount: {ReferralCode}",
"key": "Use the following code for your discount: %d\n",
"message": "Use the following code for your discount: {ReferralCode}",
"translation": "",
"placeholders": [
{
"id": "ReferralCode",
"string": "%[1]d",
"type": "golang.org/x/text/cmd/gotext/examples/extract.referralCode",
"underlyingType": "int",
"argNum": 1,
"expr": "c"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:74:10"
},
{
"id": [
"msgOutOfOrder",
"{Device} is out of order!"
],
"key": "%s is out of order!",
"message": "{Device} is out of order!",
"translation": "",
"comment": "FOO\n",
"placeholders": [
{
"id": "Device",
"string": "%[1]s",
"type": "string",
"underlyingType": "string",
"argNum": 1,
"expr": "device"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:82:10"
},
{
"id": "{Miles} miles traveled ({Miles_1})",
"key": "%.2[1]f miles traveled (%[1]f)",
"message": "{Miles} miles traveled ({Miles_1})",
"translation": "",
"placeholders": [
{
"id": "Miles",
"string": "%.2[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
},
{
"id": "Miles_1",
"string": "%[1]f",
"type": "float64",
"underlyingType": "float64",
"argNum": 1,
"expr": "miles"
}
],
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:86:10"
}
]
}

View file

@ -0,0 +1,87 @@
// 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
//go:generate gotext generate -out catalog.go
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main() {
p := message.NewPrinter(language.English)
p.Print("Hello world!\n")
p.Println("Hello", "world!")
person := "Sheila"
place := "Zürich"
p.Print("Hello ", person, " in ", place, "!\n")
// Greet everyone.
p.Printf("Hello world!\n")
city := "Amsterdam"
// Greet a city.
p.Printf("Hello %s!\n", city)
town := "Amsterdam"
// Greet a town.
p.Printf("Hello %s!\n",
town, // Town
)
// Person visiting a place.
p.Printf("%s is visiting %s!\n",
person, // The person of matter.
place, // Place the person is visiting.
)
pp := struct {
Person string // The person of matter. // TODO: get this comment.
Place string
extra int
}{
person, place, 4,
}
// extract will drop this comment in favor of the one below.
// argument is added as a placeholder.
p.Printf("%[1]s is visiting %[3]s!\n", // Person visiting a place.
pp.Person,
pp.extra,
pp.Place, // Place the person is visiting.
)
// Numeric literal
p.Printf("%d files remaining!", 2)
const n = 2
// Numeric var
p.Printf("%d more files remaining!", n)
// Infer better names from type names.
type referralCode int
const c = referralCode(5)
p.Printf("Use the following code for your discount: %d\n", c)
// Using a constant for a message will cause the constant name to be
// added as an identifier, allowing for stable message identifiers.
// Explain that a device is out of order.
const msgOutOfOrder = "%s is out of order!" // FOO
const device = "Soda machine"
p.Printf(msgOutOfOrder, device)
// Double arguments.
miles := 1.2345
p.Printf("%.2[1]f miles traveled (%[1]f)", miles)
}

View file

@ -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"
}
]
}

View file

@ -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"
}
]
}

View file

@ -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"
}
]
}

View file

@ -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))
}

View file

@ -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"))
}

View file

@ -0,0 +1,37 @@
// 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
import (
"fmt"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main() {
var nPizzas = 4
// The following call gets replaced by a call to the globally
// defined printer.
fmt.Println("We ate", nPizzas, "pizzas.")
p := message.NewPrinter(language.English)
// Prevent build failure, although it is okay for gotext.
p.Println(1024)
// Replaced by a call to p.
fmt.Println("Example punctuation:", "$%^&!")
{
q := message.NewPrinter(language.French)
const leaveAnIdentBe = "Don't expand me."
fmt.Print(leaveAnIdentBe)
q.Println() // Prevent build failure, although it is okay for gotext.
}
fmt.Printf("Hello %s\n", "City")
}

View file

@ -0,0 +1,16 @@
// 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.
// +build ignore
package main
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
// The printer defined here will be picked up by the first print statement
// in main.go.
var printer = message.NewPrinter(language.English)

View file

@ -5,22 +5,13 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"go/ast"
"go/build"
"go/constant"
"go/format"
"go/parser"
"go/types"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"golang.org/x/tools/go/loader"
"golang.org/x/text/internal"
"golang.org/x/text/message/pipeline"
)
// TODO:
@ -29,167 +20,44 @@ import (
// - handle features (gender, plural)
// - message rewriting
var (
lang *string
)
func init() {
lang = cmdExtract.Flag.String("lang", "en-US", "comma-separated list of languages to process")
}
var cmdExtract = &Command{
Run: runExtract,
UsageLine: "extract <package>*",
Short: "extract strings to be translated from code",
Short: "extracts strings to be translated from code",
}
func runExtract(cmd *Command, args []string) error {
if len(args) == 0 {
args = []string{"."}
}
conf := loader.Config{
Build: &build.Default,
ParserMode: parser.ParseComments,
}
// Use the initial packages from the command line.
args, err := conf.FromArgs(args, false)
func runExtract(cmd *Command, config *pipeline.Config, args []string) error {
config.Packages = args
state, err := pipeline.Extract(config)
if err != nil {
return err
return wrap(err, "extract failed")
}
out := state.Extracted
// Load, parse and type-check the whole program.
iprog, err := conf.Load()
if err != nil {
return err
}
// print returns Go syntax for the specified node.
print := func(n ast.Node) string {
var buf bytes.Buffer
format.Node(&buf, conf.Fset, n)
return buf.String()
}
var translations []Translation
for _, info := range iprog.InitialPackages() {
for _, f := range info.Files {
// Associate comments with nodes.
cmap := ast.NewCommentMap(iprog.Fset, f, f.Comments)
getComment := func(n ast.Node) string {
cs := cmap.Filter(n).Comments()
if len(cs) > 0 {
return strings.TrimSpace(cs[0].Text())
}
return ""
}
// Find function calls.
ast.Inspect(f, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
// Skip calls of functions other than
// (*message.Printer).{Sp,Fp,P}rintf.
sel, ok := call.Fun.(*ast.SelectorExpr)
if !ok {
return true
}
meth := info.Selections[sel]
if meth == nil || meth.Kind() != types.MethodVal {
return true
}
// TODO: remove cheap hack and check if the type either
// implements some interface or is specifically of type
// "golang.org/x/text/message".Printer.
m, ok := extractFuncs[path.Base(meth.Recv().String())]
if !ok {
return true
}
// argn is the index of the format string.
argn, ok := m[meth.Obj().Name()]
if !ok || argn >= len(call.Args) {
return true
}
// Skip calls with non-constant format string.
fmtstr := info.Types[call.Args[argn]].Value
if fmtstr == nil || fmtstr.Kind() != constant.String {
return true
}
posn := conf.Fset.Position(call.Lparen)
filepos := fmt.Sprintf("%s:%d:%d", filepath.Base(posn.Filename), posn.Line, posn.Column)
// TODO: identify the type of the format argument. If it is not
// a string, multiple keys may be defined.
var key []string
// TODO: replace substitutions (%v) with a translator friendly
// notation. For instance:
// "%d files remaining" -> "{numFiles} files remaining", or
// "%d files remaining" -> "{arg1} files remaining"
// Alternatively, this could be done at a later stage.
msg := constant.StringVal(fmtstr)
// Construct a Translation unit.
c := Translation{
Key: key,
Position: filepath.Join(info.Pkg.Path(), filepos),
Original: Text{Msg: msg},
ExtractedComment: getComment(call.Args[0]),
// TODO(fix): this doesn't get the before comment.
// Comment: getComment(call),
}
for i, arg := range call.Args[argn+1:] {
var val string
if v := info.Types[arg].Value; v != nil {
val = v.ExactString()
}
posn := conf.Fset.Position(arg.Pos())
filepos := fmt.Sprintf("%s:%d:%d", filepath.Base(posn.Filename), posn.Line, posn.Column)
c.Args = append(c.Args, Argument{
ID: i + 1,
Type: info.Types[arg].Type.String(),
UnderlyingType: info.Types[arg].Type.Underlying().String(),
Expr: print(arg),
Value: val,
Comment: getComment(arg),
Position: filepath.Join(info.Pkg.Path(), filepos),
// TODO report whether it implements
// interfaces plural.Interface,
// gender.Interface.
})
}
translations = append(translations, c)
return true
})
langs := append(getLangs(), config.SourceLanguage)
langs = internal.UniqueTags(langs)
for _, tag := range langs {
// TODO: inject translations from existing files to avoid retranslation.
out.Language = tag
data, err := json.MarshalIndent(out, "", " ")
if err != nil {
return wrap(err, "JSON marshal failed")
}
}
data, err := json.MarshalIndent(translations, "", " ")
if err != nil {
return err
}
for _, tag := range getLangs() {
// TODO: merge with existing files, don't overwrite.
os.MkdirAll(*dir, 0744)
file := filepath.Join(*dir, fmt.Sprintf("gotext_%v.out.json", tag))
if err := ioutil.WriteFile(file, data, 0744); err != nil {
return fmt.Errorf("could not create file: %v", err)
file := filepath.Join(*dir, tag.String(), outFile)
if err := os.MkdirAll(filepath.Dir(file), 0750); err != nil {
return wrap(err, "dir create failed")
}
if err := ioutil.WriteFile(file, data, 0740); err != nil {
return wrap(err, "write failed")
}
}
return nil
}
// extractFuncs indicates the types and methods for which to extract strings,
// and which argument to extract.
// TODO: use the types in conf.Import("golang.org/x/text/message") to extract
// the correct instances.
var extractFuncs = map[string]map[string]int{
// TODO: Printer -> *golang.org/x/text/message.Printer
"message.Printer": {
"Printf": 0,
"Sprintf": 0,
"Fprintf": 1,
},
}

35
vendor/golang.org/x/text/cmd/gotext/generate.go generated vendored Normal file
View file

@ -0,0 +1,35 @@
// 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
import (
"golang.org/x/text/message/pipeline"
)
func init() {
out = cmdGenerate.Flag.String("out", "", "output file to write to")
}
var (
out *string
)
var cmdGenerate = &Command{
Run: runGenerate,
UsageLine: "generate <package>",
Short: "generates code to insert translated messages",
}
func runGenerate(cmd *Command, config *pipeline.Config, args []string) error {
config.Packages = args
s, err := pipeline.Extract(config)
if err != nil {
return wrap(err, "extraction failed")
}
if err := s.Import(); err != nil {
return wrap(err, "import failed")
}
return wrap(s.Generate(), "generation failed")
}

View file

@ -25,6 +25,8 @@ import (
"unicode"
"unicode/utf8"
"golang.org/x/text/message/pipeline"
"golang.org/x/text/language"
"golang.org/x/tools/go/buildutil"
)
@ -34,10 +36,22 @@ func init() {
}
var (
dir = flag.String("dir", "textdata", "default subdirectory to store translation files")
langs = flag.String("lang", "en", "comma-separated list of languages to process")
srcLang = flag.String("srclang", "en-US", "the source-code language")
dir = flag.String("dir", "locales", "default subdirectory to store translation files")
)
func config() (*pipeline.Config, error) {
tag, err := language.Parse(*srcLang)
if err != nil {
return nil, wrap(err, "invalid srclang")
}
return &pipeline.Config{
SourceLanguage: tag,
TranslationsPattern: `messages\.(.*)\.json`,
GenFile: *out,
}, nil
}
// NOTE: the Command struct is copied from the go tool in core.
// A Command is an implementation of a go command
@ -45,7 +59,7 @@ var (
type Command struct {
// Run runs the command.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string) error
Run func(cmd *Command, c *pipeline.Config, args []string) error
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
@ -87,8 +101,9 @@ func (c *Command) Runnable() bool {
// The order here is the order in which they are printed by 'go help'.
var commands = []*Command{
cmdExtract,
cmdRewrite,
cmdGenerate,
// TODO:
// - generate code from translations.
// - update: full-cycle update of extraction, sending, and integration
// - report: report of freshness of translations
}
@ -126,8 +141,12 @@ func main() {
cmd.Flag.Usage = func() { cmd.Usage() }
cmd.Flag.Parse(args[1:])
args = cmd.Flag.Args()
if err := cmd.Run(cmd, args); err != nil {
fatalf("gotext: %v", err)
config, err := config()
if err != nil {
fatalf("gotext: %+v", err)
}
if err := cmd.Run(cmd, config, args); err != nil {
fatalf("gotext: %+v", err)
}
exit()
return
@ -277,12 +296,7 @@ func help(args []string) {
if strings.HasSuffix(arg, "documentation") {
w := &bytes.Buffer{}
fmt.Fprintln(w, "// Copyright 2016 The Go Authors. All rights reserved.")
fmt.Fprintln(w, "// Use of this source code is governed by a BSD-style")
fmt.Fprintln(w, "// license that can be found in the LICENSE file.")
fmt.Fprintln(w)
fmt.Fprintln(w, "// DO NOT EDIT THIS FILE. GENERATED BY go generate.")
fmt.Fprintln(w, "// Edit the documentation in other files and rerun go generate to generate this one.")
fmt.Fprintln(w, "// Code generated by go generate. DO NOT EDIT.")
fmt.Fprintln(w)
buf := new(bytes.Buffer)
printUsage(buf)
@ -292,10 +306,10 @@ func help(args []string) {
if arg == "gendocumentation" {
b, err := format.Source(w.Bytes())
if err != nil {
errorf("Could not format generated docs: %v\n", err)
logf("Could not format generated docs: %v\n", err)
}
if err := ioutil.WriteFile("doc.go", b, 0666); err != nil {
errorf("Could not create file alldocs.go: %v\n", err)
logf("Could not create file alldocs.go: %v\n", err)
}
} else {
fmt.Println(w.String())
@ -316,7 +330,10 @@ func help(args []string) {
}
func getLangs() (tags []language.Tag) {
for _, t := range strings.Split(*langs, ",") {
for _, t := range strings.Split(*lang, ",") {
if t == "" {
continue
}
tag, err := language.Parse(t)
if err != nil {
fatalf("gotext: could not parse language %q: %v", t, err)
@ -340,11 +357,11 @@ func exit() {
}
func fatalf(format string, args ...interface{}) {
errorf(format, args...)
logf(format, args...)
exit()
}
func errorf(format string, args ...interface{}) {
func logf(format string, args ...interface{}) {
log.Printf(format, args...)
setExitStatus(1)
}

View file

@ -1,127 +0,0 @@
// Copyright 2016 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
// TODO: these definitions should be moved to a package so that the can be used
// by other tools.
// The file contains the structures used to define translations of a certain
// messages.
//
// A translation may have multiple translations strings, or messages, depending
// on the feature values of the various arguments. For instance, consider
// a hypothetical translation from English to English, where the source defines
// the format string "%d file(s) remaining". A completed translation, expressed
// in JS, for this format string could look like:
//
// {
// "Key": [
// "\"%d files(s) remaining\""
// ],
// "Original": {
// "Msg": "\"%d files(s) remaining\""
// },
// "Translation": {
// "Select": {
// "Feature": "plural",
// "Arg": 1,
// "Case": {
// "one": { "Msg": "1 file remaining" },
// "other": { "Msg": "%d files remaining" }
// },
// },
// },
// "Args": [
// {
// "ID": 2,
// "Type": "int",
// "UnderlyingType": "int",
// "Expr": "nFiles",
// "Comment": "number of files remaining",
// "Position": "golang.org/x/text/cmd/gotext/demo.go:34:3"
// }
// ],
// "Position": "golang.org/x/text/cmd/gotext/demo.go:33:10",
// }
//
// Alternatively, the Translation section could be written as:
//
// "Translation": {
// "Msg": "%d %[files]s remaining",
// "Var": {
// "files" : {
// "Select": {
// "Feature": "plural",
// "Arg": 1,
// "Case": {
// "one": { "Msg": "file" },
// "other": { "Msg": "files" }
// }
// }
// }
// }
// }
// A Translation describes a translation for a single language for a single
// message.
type Translation struct {
// Key contains a list of identifiers for the message. If this list is empty
// Original is used as the key.
Key []string `json:"key,omitempty"`
Original Text `json:"original"`
Translation Text `json:"translation"`
ExtractedComment string `json:"extractedComment,omitempty"`
TranslatorComment string `json:"translatorComment,omitempty"`
Args []Argument `json:"args,omitempty"`
// Extraction information.
Position string `json:"position,omitempty"` // filePosition:line
}
// An Argument contains information about the arguments passed to a message.
type Argument struct {
ID interface{} `json:"id"` // An int for printf-style calls, but could be a string.
Type string `json:"type"`
UnderlyingType string `json:"underlyingType"`
Expr string `json:"expr"`
Value string `json:"value,omitempty"`
Comment string `json:"comment,omitempty"`
Position string `json:"position,omitempty"`
// Features contains the features that are available for the implementation
// of this argument.
Features []Feature `json:"features,omitempty"`
}
// Feature holds information about a feature that can be implemented by
// an Argument.
type Feature struct {
Type string `json:"type"` // Right now this is only gender and plural.
// TODO: possible values and examples for the language under consideration.
}
// Text defines a message to be displayed.
type Text struct {
// Msg and Select contains the message to be displayed. Within a Text value
// either Msg or Select is defined.
Msg string `json:"msg,omitempty"`
Select *Select `json:"select,omitempty"`
// Var defines a map of variables that may be substituted in the selected
// message.
Var map[string]Text `json:"var,omitempty"`
// Example contains an example message formatted with default values.
Example string `json:"example,omitempty"`
}
// Type Select selects a Text based on the feature value associated with
// a feature of a certain argument.
type Select struct {
Feature string `json:"feature"` // Name of variable or Feature type
Arg interface{} `json:"arg"` // The argument ID.
Cases map[string]Text `json:"cases"`
}

55
vendor/golang.org/x/text/cmd/gotext/rewrite.go generated vendored Normal file
View file

@ -0,0 +1,55 @@
// 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
import (
"os"
"golang.org/x/text/message/pipeline"
)
const printerType = "golang.org/x/text/message.Printer"
// TODO:
// - merge information into existing files
// - handle different file formats (PO, XLIFF)
// - handle features (gender, plural)
// - message rewriting
func init() {
overwrite = cmdRewrite.Flag.Bool("w", false, "write files in place")
}
var (
overwrite *bool
)
var cmdRewrite = &Command{
Run: runRewrite,
UsageLine: "rewrite <package>",
Short: "rewrites fmt functions to use a message Printer",
Long: `
rewrite is typically done once for a project. It rewrites all usages of
fmt to use x/text's message package whenever a message.Printer is in scope.
It rewrites Print and Println calls with constant strings to the equivalent
using Printf to allow translators to reorder arguments.
`,
}
func runRewrite(cmd *Command, _ *pipeline.Config, args []string) error {
w := os.Stdout
if *overwrite {
w = nil
}
pkg := "."
switch len(args) {
case 0:
case 1:
pkg = args[0]
default:
return errorf("can only specify at most one package")
}
return pipeline.Rewrite(w, pkg)
}