New upstream snapshot.
Debian Janitor
2 years ago
5 | 5 | build: |
6 | 6 | name: Build |
7 | 7 | runs-on: ubuntu-latest |
8 | if: (github.event_name == 'push' && github.repository_owner == 'nicksnyder') || (github.event_name == 'pull_request' && github.repository_owner != 'nicksnyder') | |
8 | if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'pull_request' | |
9 | 9 | steps: |
10 | 10 | - name: Install Go |
11 | 11 | uses: actions/setup-go@v2 |
12 | 12 | with: |
13 | go-version: 1.15.2 | |
13 | go-version: 1.16.5 | |
14 | 14 | - name: Git checkout |
15 | 15 | uses: actions/checkout@v2 |
16 | 16 | - name: Build |
27 | 27 | build_1_9_7: |
28 | 28 | name: Build with Go 1.9.7 |
29 | 29 | runs-on: ubuntu-latest |
30 | if: (github.event_name == 'push' && github.repository_owner == 'nicksnyder') || (github.event_name == 'pull_request' && github.repository_owner != 'nicksnyder') | |
30 | if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'pull_request' | |
31 | 31 | steps: |
32 | 32 | - name: Install Go |
33 | 33 | uses: actions/setup-go@v2 |
0 | name: Sourcegraph code intelligence | |
1 | on: | |
2 | - push | |
3 | ||
4 | jobs: | |
5 | lsif-go: | |
6 | runs-on: ubuntu-latest | |
7 | container: sourcegraph/lsif-go:latest | |
8 | steps: | |
9 | - uses: actions/checkout@v1 | |
10 | - name: Generate LSIF data | |
11 | run: lsif-go | |
12 | - name: Upload LSIF data to Sourcegraph.com | |
13 | run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} -ignore-upload-failure |
9 | 9 | |
10 | 10 | The first commit to this project was January 2012 (go1 had not yet been released) and v1.0.0 was tagged June 2015 (go1.4). |
11 | 11 | This project has evolved with the Go ecosystem since then in a backwards compatible way, |
12 | but there is a growing list of issues and warts that cannot be addressed without breaking compatiblity. | |
12 | but there is a growing list of issues and warts that cannot be addressed without breaking compatibility. | |
13 | 13 | |
14 | 14 | v2 is rewrite of the API from first principals to make it more idiomatic Go, and to resolve a backlog of issues: https://github.com/nicksnyder/go-i18n/milestone/1 |
15 | 15 |
1 | 1 | |
2 | 2 | go-i18n is a Go [package](#package-i18n) and a [command](#command-goi18n) that helps you translate Go programs into multiple languages. |
3 | 3 | |
4 | - Supports [pluralized strings](http://cldr.unicode.org/index/cldr-spec/plural-rules) for all 200+ languages in the [Unicode Common Locale Data Repository (CLDR)](http://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html). | |
5 | - Code and tests are [automatically generated](https://github.com/nicksnyder/go-i18n/tree/master/i18n/language/codegen) from [CLDR data](http://cldr.unicode.org/index/downloads). | |
4 | - Supports [pluralized strings](http://cldr.unicode.org/index/cldr-spec/plural-rules) for all 200+ languages in the [Unicode Common Locale Data Repository (CLDR)](https://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html). | |
5 | - Code and tests are [automatically generated](https://github.com/nicksnyder/go-i18n/tree/main/v2/internal/plural/codegen) from [CLDR data](http://cldr.unicode.org/index/downloads). | |
6 | 6 | - Supports strings with named variables using [text/template](http://golang.org/pkg/text/template/) syntax. |
7 | 7 | - Supports message files of any format (e.g. JSON, TOML, YAML). |
8 | 8 | |
9 | ## Package i18n [![GoDoc](http://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](http://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n) | |
9 | ## Package i18n | |
10 | [![GoDoc](https://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n) | |
10 | 11 | |
11 | 12 | The i18n package provides support for looking up messages according to a set of locale preferences. |
12 | 13 | |
54 | 55 | }) // Nick has 2 cats. |
55 | 56 | ``` |
56 | 57 | |
57 | ## Command goi18n [![GoDoc](http://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](http://godoc.org/github.com/nicksnyder/go-i18n/v2/goi18n) | |
58 | ## Command goi18n | |
59 | [![GoDoc](https://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](https://godoc.org/github.com/nicksnyder/go-i18n/v2/goi18n) | |
58 | 60 | |
59 | 61 | The goi18n command manages message files used by the i18n package. |
60 | 62 | |
78 | 80 | ### Translating a new language |
79 | 81 | |
80 | 82 | 1. Create an empty message file for the language that you want to add (e.g. `translate.es.toml`). |
81 | 2. Run `goi18n merge active.en.toml translate.es.toml` to populate `translate.es.toml` with the mesages to be translated. | |
83 | 2. Run `goi18n merge active.en.toml translate.es.toml` to populate `translate.es.toml` with the messages to be translated. | |
82 | 84 | |
83 | 85 | ```toml |
84 | 86 | # translate.es.toml |
114 | 116 | |
115 | 117 | ## For more information and examples: |
116 | 118 | |
117 | - Read the [documentation](http://godoc.org/github.com/nicksnyder/go-i18n/v2). | |
118 | - Look at the [code examples](https://github.com/nicksnyder/go-i18n/blob/master/v2/i18n/example_test.go) and [tests](https://github.com/nicksnyder/go-i18n/blob/master/i18n/v2/localizer_test.go). | |
119 | - Look at an example [application](https://github.com/nicksnyder/go-i18n/tree/master/v2/example). | |
119 | - Read the [documentation](https://godoc.org/github.com/nicksnyder/go-i18n/v2). | |
120 | - Look at the [code examples](https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/example_test.go) and [tests](https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/localizer_test.go). | |
121 | - Look at an example [application](https://github.com/nicksnyder/go-i18n/tree/main/v2/example). | |
120 | 122 | |
121 | 123 | ## License |
122 | 124 |
0 | golang-github-nicksnyder-go-i18n.v2 (2.1.2+git20210623.1.240abfe-1) UNRELEASED; urgency=low | |
1 | ||
2 | * New upstream snapshot. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Wed, 13 Oct 2021 02:01:11 -0000 | |
5 | ||
0 | 6 | golang-github-nicksnyder-go-i18n.v2 (2.1.1-2) unstable; urgency=medium |
1 | 7 | |
2 | 8 | * Run "cme fix dpkg" and "wrap-and-sort -ast" which tidied up |
8 | 8 | "io/ioutil" |
9 | 9 | "os" |
10 | 10 | "path/filepath" |
11 | "strconv" | |
11 | 12 | "strings" |
12 | 13 | |
13 | 14 | "github.com/nicksnyder/go-i18n/v2/i18n" |
239 | 240 | if v.Kind != token.STRING { |
240 | 241 | return "", false |
241 | 242 | } |
242 | s := v.Value[1 : len(v.Value)-1] | |
243 | if v.Value[0] == '"' { | |
244 | s = strings.Replace(s, `\"`, `"`, -1) | |
243 | s, err := strconv.Unquote(v.Value) | |
244 | if err != nil { | |
245 | return "", false | |
245 | 246 | } |
246 | 247 | return s, true |
247 | 248 | case *ast.BinaryExpr: |
31 | 31 | ID: "Plural ID", |
32 | 32 | } |
33 | 33 | `, |
34 | }, | |
35 | { | |
36 | name: "escape newline", | |
37 | fileName: "file.go", | |
38 | file: `package main | |
39 | ||
40 | import "github.com/nicksnyder/go-i18n/v2/i18n" | |
41 | ||
42 | var hasnewline = &i18n.Message{ | |
43 | ID: "hasnewline", | |
44 | Other: "\nfoo\nbar\\", | |
45 | } | |
46 | `, | |
47 | activeFile: []byte(`hasnewline = "\nfoo\nbar\\" | |
48 | `), | |
34 | 49 | }, |
35 | 50 | { |
36 | 51 | name: "escape", |
0 | // +build go1.16 | |
1 | ||
2 | package i18n | |
3 | ||
4 | import ( | |
5 | "io/fs" | |
6 | ) | |
7 | ||
8 | // LoadMessageFileFS is like LoadMessageFile but instead of reading from the | |
9 | // hosts operating system's file system it reads from the fs file system. | |
10 | func (b *Bundle) LoadMessageFileFS(fsys fs.FS, path string) (*MessageFile, error) { | |
11 | buf, err := fs.ReadFile(fsys, path) | |
12 | if err != nil { | |
13 | return nil, err | |
14 | } | |
15 | ||
16 | return b.ParseMessageFileBytes(buf, path) | |
17 | } |
0 | 0 | # How to upgrade CLDR data |
1 | 1 | |
2 | 2 | 1. Go to http://cldr.unicode.org/index/downloads to find the latest version. |
3 | 1. Download the latest version of cldr-common (e.g. http://unicode.org/Public/cldr/37/cldr-common-37.0.zip) | |
3 | 1. Download the latest version of cldr-common (e.g. https://unicode.org/Public/cldr/39/cldr-common-39.0.zip) | |
4 | 4 | 1. Unzip and copy `common/supplemental/plurals.xml` to this directory. |
5 | 5 | 1. Run `generate.sh`. |
0 | 0 | package internal |
1 | 1 | |
2 | 2 | import ( |
3 | "strings" | |
3 | 4 | "testing" |
4 | 5 | "text/template" |
5 | 6 | ) |
44 | 45 | template: &Template{ |
45 | 46 | Src: "hello {{", |
46 | 47 | }, |
47 | err: "template: :1: unexpected unclosed action in command", | |
48 | err: "unclosed action", | |
48 | 49 | noallocs: true, |
49 | 50 | }, |
50 | 51 | } |
52 | 53 | for _, test := range tests { |
53 | 54 | t.Run(test.template.Src, func(t *testing.T) { |
54 | 55 | result, err := test.template.Execute(test.funcs, test.data) |
55 | if actual := str(err); actual != test.err { | |
56 | t.Errorf("expected err %q; got %q", test.err, actual) | |
56 | if actual := str(err); !strings.Contains(str(err), test.err) { | |
57 | t.Errorf("expected err %q to contain %q", actual, test.err) | |
57 | 58 | } |
58 | 59 | if result != test.result { |
59 | 60 | t.Errorf("expected result %q; got %q", test.result, result) |