Codebase list golang-github-nicksnyder-go-i18n.v2 / ae4e07d8-56f0-4277-a72e-0c06efcffa29/main
New upstream snapshot. Debian Janitor 2 years ago
10 changed file(s) with 76 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
55 build:
66 name: Build
77 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'
99 steps:
1010 - name: Install Go
1111 uses: actions/setup-go@v2
1212 with:
13 go-version: 1.15.2
13 go-version: 1.16.5
1414 - name: Git checkout
1515 uses: actions/checkout@v2
1616 - name: Build
2727 build_1_9_7:
2828 name: Build with Go 1.9.7
2929 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'
3131 steps:
3232 - name: Install Go
3333 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
99
1010 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).
1111 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.
1313
1414 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
1515
11
22 go-i18n is a Go [package](#package-i18n) and a [command](#command-goi18n) that helps you translate Go programs into multiple languages.
33
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).
66 - Supports strings with named variables using [text/template](http://golang.org/pkg/text/template/) syntax.
77 - Supports message files of any format (e.g. JSON, TOML, YAML).
88
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)
1011
1112 The i18n package provides support for looking up messages according to a set of locale preferences.
1213
5455 }) // Nick has 2 cats.
5556 ```
5657
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)
5860
5961 The goi18n command manages message files used by the i18n package.
6062
7880 ### Translating a new language
7981
8082 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.
8284
8385 ```toml
8486 # translate.es.toml
114116
115117 ## For more information and examples:
116118
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).
120122
121123 ## License
122124
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
06 golang-github-nicksnyder-go-i18n.v2 (2.1.1-2) unstable; urgency=medium
17
28 * Run "cme fix dpkg" and "wrap-and-sort -ast" which tidied up
88 "io/ioutil"
99 "os"
1010 "path/filepath"
11 "strconv"
1112 "strings"
1213
1314 "github.com/nicksnyder/go-i18n/v2/i18n"
239240 if v.Kind != token.STRING {
240241 return "", false
241242 }
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
245246 }
246247 return s, true
247248 case *ast.BinaryExpr:
3131 ID: "Plural ID",
3232 }
3333 `,
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 `),
3449 },
3550 {
3651 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 }
00 # How to upgrade CLDR data
11
22 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)
44 1. Unzip and copy `common/supplemental/plurals.xml` to this directory.
55 1. Run `generate.sh`.
00 package internal
11
22 import (
3 "strings"
34 "testing"
45 "text/template"
56 )
4445 template: &Template{
4546 Src: "hello {{",
4647 },
47 err: "template: :1: unexpected unclosed action in command",
48 err: "unclosed action",
4849 noallocs: true,
4950 },
5051 }
5253 for _, test := range tests {
5354 t.Run(test.template.Src, func(t *testing.T) {
5455 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)
5758 }
5859 if result != test.result {
5960 t.Errorf("expected result %q; got %q", test.result, result)