Skip to content

Commit cfcc22d

Browse files
authored
Merge pull request #3 from gohugoio/sync2022510take2
sync2022510take2
2 parents e63c132 + ec001b7 commit cfcc22d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1567
-639
lines changed

‎.codecov.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage:
2-
range: 50..100
2+
range: 50..75
33
status:
44
patch:
55
default:

‎.github/README.uk-UA.md‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# go-i18n
2+
![Build status](https://github.com/nicksnyder/go-i18n/workflows/Build/badge.svg) [![Report card](https://goreportcard.com/badge/github.com/nicksnyder/go-i18n/v2)](https://goreportcard.com/report/github.com/nicksnyder/go-i18n/v2) [![codecov](https://codecov.io/gh/nicksnyder/go-i18n/graph/badge.svg?token=A9aMfR9vxG)](https://codecov.io/gh/nicksnyder/go-i18n) [![Sourcegraph](https://sourcegraph.com/github.com/nicksnyder/go-i18n/-/badge.svg)](https://sourcegraph.com/github.com/nicksnyder/go-i18n?badge)
3+
4+
go-i18n — це Go [пакет](#package-i18n) та [інструмент](#command-goi18n), які допомагають перекладати Go програми на різні мови.
5+
6+
- Підтримує [множинні форми](http://cldr.unicode.org/index/cldr-spec/plural-rules) для всіх 200+ мов у [Unicode Common Locale Data Repository (CLDR)](https://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html).
7+
- Код і тести [автоматично генеруються](https://github.com/nicksnyder/go-i18n/tree/main/internal/plural/codegen) з даних [CLDR](http://cldr.unicode.org/index/downloads).
8+
- Підтримує рядки з іменованими змінними, використовуючи синтаксис [text/template](http://golang.org/pkg/text/template/).
9+
- Підтримує файли повідомлень у будь-якому форматі (наприклад, JSON, TOML, YAML).
10+
11+
## Пакет i18n
12+
13+
[![Go Reference](https://pkg.go.dev/badge/github.com/nicksnyder/go-i18n/v2/i18n.svg)](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/i18n)
14+
15+
Пакет i18n забезпечує підтримку пошуку повідомлень відповідно до набору мовних уподобань.
16+
17+
```go
18+
import "github.com/nicksnyder/go-i18n/v2/i18n"
19+
```
20+
21+
Створіть Bundle, який використовуватимете протягом усього терміну служби вашої програми.
22+
23+
```go
24+
bundle := i18n.NewBundle(language.English)
25+
```
26+
27+
Завантажуйте переклади у ваш пакет під час ініціалізації.
28+
29+
```go
30+
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
31+
bundle.LoadMessageFile("es.toml")
32+
```
33+
34+
```go
35+
// Якщо використовуєте go:embed
36+
//go:embed locale.*.toml
37+
var LocaleFS embed.FS
38+
39+
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
40+
bundle.LoadMessageFileFS(LocaleFS, "locale.es.toml")
41+
```
42+
43+
Створіть Localizer, який використовуватимете для набору мовних уподобань.
44+
45+
```go
46+
func(w http.ResponseWriter, r *http.Request) {
47+
lang := r.FormValue("lang")
48+
accept := r.Header.Get("Accept-Language")
49+
localizer := i18n.NewLocalizer(bundle, lang, accept)
50+
}
51+
```
52+
53+
Використовуйте Localizer для пошуку повідомлень.
54+
55+
```go
56+
localizer.Localize(&i18n.LocalizeConfig{
57+
DefaultMessage: &i18n.Message{
58+
ID: "PersonCats",
59+
One: "{{.Name}} has {{.Count}} cat.",
60+
Other: "{{.Name}} has {{.Count}} cats.",
61+
},
62+
TemplateData: map[string]interface{}{
63+
"Name": "Nick",
64+
"Count": 2,
65+
},
66+
PluralCount: 2,
67+
}) // Nick has 2 cats.
68+
```
69+
70+
## Команда goi18n
71+
72+
[![Go Reference](https://pkg.go.dev/badge/github.com/nicksnyder/go-i18n/v2/goi18n.svg)](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/goi18n)
73+
74+
Команда goi18n управляє файлами повідомлень, що використовуються пакетом i18n.
75+
76+
```
77+
go install -v github.com/nicksnyder/go-i18n/v2/goi18n@latest
78+
goi18n -help
79+
```
80+
81+
### Витяг повідомлень
82+
83+
Використовуйте команду `goi18n extract`, щоб витягнути всі літерали структури i18n.Message із Go-файлів у файл повідомлень для перекладу.
84+
85+
```toml
86+
# active.en.toml
87+
[PersonCats]
88+
description = "The number of cats a person has"
89+
one = "{{.Name}} has {{.Count}} cat."
90+
other = "{{.Name}} has {{.Count}} cats."
91+
```
92+
93+
### Переклад нової мови
94+
95+
1. Створіть порожній файл повідомлень для мови, яку ви хочете додати (наприклад, translate.uk.toml).
96+
2. Виконайте команду `goi18n merge active.en.toml translate.es.toml`, щоб заповнити `translate.es.toml` повідомленнями для перекладу.
97+
98+
```toml
99+
# translate.uk.toml
100+
[HelloPerson]
101+
hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
102+
other = "Hello {{.Name}}"
103+
```
104+
105+
3. Після перекладу файлу `translate.es.toml` перейменуйте його на `active.es.toml`.
106+
107+
```toml
108+
# active.uk.toml
109+
[HelloPerson]
110+
hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
111+
other = "Вітаю {{.Name}}"
112+
```
113+
114+
4. Завантажте файл `active.es.toml` у свій пакет.
115+
116+
```go
117+
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
118+
bundle.LoadMessageFile("active.es.toml")
119+
```
120+
121+
### Переклад нових повідомлень
122+
123+
Якщо ви додали нові повідомлення до своєї програми:
124+
125+
1. Виконайте `goi18n extract`, щоб оновити файл `active.en.toml` новими повідомленнями.
126+
2. Виконайте `goi18n merge active.*.toml`, щоб згенерувати оновлені файли `translate.*.toml`.
127+
3. Перекладіть усі повідомлення у файлах `translate.*.toml`.
128+
4. Виконайте `goi18n merge active.*.toml translate.*.toml`, щоб об’єднати перекладені повідомлення з активними файлами повідомлень.
129+
130+
## Для отримання додаткової інформації та прикладів:
131+
132+
- Ознайомтеся з [документацією](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2).
133+
- Подивіться [приклади коду](https://github.com/nicksnyder/go-i18n/blob/main/i18n/example_test.go) та [тести](https://github.com/nicksnyder/go-i18n/blob/main/i18n/localizer_test.go).
134+
- Перегляньте приклад [додатку](https://github.com/nicksnyder/go-i18n/tree/main/example).
135+
136+
## Переклади цього документа
137+
138+
Переклади цього документа, зроблені спільнотою, можна знайти в папці [.github](.github).
139+
140+
Ці переклади підтримуються спільнотою і не підтримуються автором цього проєкту.
141+
Немає гарантії, що вони є точними або актуальними.
142+
143+
## Ліцензія
144+
145+
go-i18n доступний під ліцензією MIT. Див. файл [LICENSE](LICENSE) для отримання додаткової інформації.

‎.github/README.zh-Hans.md‎

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# go-i18n ![Build status](https://github.com/nicksnyder/go-i18n/workflows/Build/badge.svg) [![Report card](https://goreportcard.com/badge/github.com/nicksnyder/go-i18n)](https://goreportcard.com/report/github.com/nicksnyder/go-i18n) [![codecov](https://codecov.io/gh/nicksnyder/go-i18n/branch/master/graph/badge.svg)](https://codecov.io/gh/nicksnyder/go-i18n) [![Sourcegraph](https://sourcegraph.com/github.com/nicksnyder/go-i18n/-/badge.svg)](https://sourcegraph.com/github.com/nicksnyder/go-i18n?badge)
1+
# go-i18n
2+
![Build status](https://github.com/nicksnyder/go-i18n/workflows/Build/badge.svg) [![Report card](https://goreportcard.com/badge/github.com/nicksnyder/go-i18n/v2)](https://goreportcard.com/report/github.com/nicksnyder/go-i18n/v2) [![codecov](https://codecov.io/gh/nicksnyder/go-i18n/graph/badge.svg?token=A9aMfR9vxG)](https://codecov.io/gh/nicksnyder/go-i18n) [![Sourcegraph](https://sourcegraph.com/github.com/nicksnyder/go-i18n/-/badge.svg)](https://sourcegraph.com/github.com/nicksnyder/go-i18n?badge)
23

3-
go-i18n 是一个帮助您将 Go 程序翻译成多种语言的 Go [](#package-i18n)[命令](#command-goi18n)
4+
go-i18n 是一个帮助您将 Go 程序翻译成多种语言的 Go [](#package-i18n)[命令](#command-goi18n)
45

5-
- 支持 [Unicode Common Locale Data Repository (CLDR)](https://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html) 中所有 200 多种语言的 [复数字符](http://cldr.unicode.org/index/cldr-spec/plural-rules)
6-
- 代码和测试是从 [CLDR 数据](http://cldr.unicode.org/index/downloads)[自动生成](https://github.com/nicksnyder/go-i18n/tree/main/v2/internal/plural/codegen) 的。
6+
- 支持 [Unicode Common Locale Data Repository (CLDR)](https://www.unicode.org/cldr/charts/28/supplemental/language_plural_rules.html)
7+
中所有 200 多种语言的[复数字符串](http://cldr.unicode.org/index/cldr-spec/plural-rules)
8+
- 代码和测试是基于 [CLDR 数据](http://cldr.unicode.org/index/downloads)[自动生成](https://github.com/nicksnyder/go-i18n/tree/main/internal/plural/codegen)的。
79
- 使用 [text/template](http://golang.org/pkg/text/template/) 语法支持带有命名变量的字符串。
8-
- 支持任何格式的消息文件(例如:JSON、TOML、YAML)。
10+
- 支持所有格式的消息文件(例如:JSON、TOML、YAML)。
911

1012
<strong align="center">
1113
<samp>
@@ -15,11 +17,11 @@ go-i18n 是一个帮助您将 Go 程序翻译成多种语言的 Go [包](#packag
1517
</samp>
1618
</strong>
1719

18-
## Package i18n
20+
## i18n
1921

20-
[![GoDoc](https://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n)
22+
[![Go Reference](https://pkg.go.dev/badge/github.com/nicksnyder/go-i18n/v2/i18n.svg)](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/i18n)
2123

22-
i18n 包支持根据一组语言环境首选项查找消息
24+
i18n 包支持根据一组语言环境首选项来查找消息
2325

2426
```go
2527
import "github.com/nicksnyder/go-i18n/v2/i18n"
@@ -31,7 +33,7 @@ import "github.com/nicksnyder/go-i18n/v2/i18n"
3133
bundle := i18n.NewBundle(language.English)
3234
```
3335

34-
在初始化期间将翻译加载到您的 bundle 中。
36+
在初始化时,将翻译加载到你的 Bundle 中。
3537

3638
```go
3739
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
@@ -47,7 +49,7 @@ bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
4749
bundle.LoadMessageFileFS(LocaleFS, "locale.es.toml")
4850
```
4951

50-
创建一个 Localizer 以用于一组语言首选项
52+
创建一个 Localizer 以便用于一组首选语言
5153

5254
```go
5355
func(w http.ResponseWriter, r *http.Request) {
@@ -57,7 +59,7 @@ func(w http.ResponseWriter, r *http.Request) {
5759
}
5860
```
5961

60-
使用 Localizer 查找消息。
62+
使用此 Localizer 查找消息。
6163

6264
```go
6365
localizer.Localize(&i18n.LocalizeConfig{
@@ -71,14 +73,14 @@ localizer.Localize(&i18n.LocalizeConfig{
7173
"Count": 2,
7274
},
7375
PluralCount: 2,
74-
}) // Nick has 2 cats.
76+
}) // Nick 有两只猫
7577
```
7678

7779
## goi18n 命令
7880

79-
[![GoDoc](https://godoc.org/github.com/nicksnyder/go-i18n?status.svg)](https://godoc.org/github.com/nicksnyder/go-i18n/v2/goi18n)
81+
[![Go Reference](https://pkg.go.dev/badge/github.com/nicksnyder/go-i18n/v2/goi18n.svg)](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/goi18n)
8082

81-
goi18n 命令管理 i18n 包使用的消息文件
83+
goi18n 命令管理 i18n 包所使用的消息文件
8284

8385
```
8486
go install -v github.com/nicksnyder/go-i18n/v2/goi18n@latest
@@ -87,7 +89,7 @@ goi18n -help
8789

8890
### 提取消息
8991

90-
使用 `goi18n extract` 将 Go 源文件中的所有 i18n.Message 结构文字提取到消息文件中以进行翻译
92+
使用 `goi18n extract` 将 Go 源文件中的所有 i18n.Message 结构中的文字提取到消息文件中以进行翻译
9193

9294
```toml
9395
# active.en.toml
@@ -99,8 +101,8 @@ other = "{{.Name}} has {{.Count}} cats."
99101

100102
### 翻译一种新语言
101103

102-
1. 为您要添加的语言创建一个空消息文件(例如:`translate.es.toml`)。
103-
2. 运行 `goi18n merge active.en.toml translate.es.toml` 以填充 `translate.es.toml` 要翻译的消息
104+
1. 为你要添加的语言创建一个空的消息文件(例如:`translate.es.toml`)。
105+
2. 运行 `goi18n merge active.en.toml translate.es.toml` 以将要翻译的消息填充到 `translate.es.toml`
104106

105107
```toml
106108
# translate.es.toml
@@ -109,7 +111,7 @@ other = "{{.Name}} has {{.Count}} cats."
109111
other = "Hello {{.Name}}"
110112
```
111113

112-
3. 翻译完成 `translate.es.toml` ,将其重命名为 `active.es.toml``。
114+
3. 完成 `translate.es.toml` 的翻译之后,将其重命名为 `active.es.toml`
113115

114116
```toml
115117
# active.es.toml
@@ -118,7 +120,7 @@ other = "{{.Name}} has {{.Count}} cats."
118120
other = "Hola {{.Name}}"
119121
```
120122

121-
4. 加载 `active.es.toml` 到您的 bundle 中。
123+
4. 加载 `active.es.toml` 到你的 Bundle 中。
122124

123125
```go
124126
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
@@ -127,19 +129,21 @@ other = "{{.Name}} has {{.Count}} cats."
127129

128130
### 翻译新消息
129131

130-
如果您在程序中添加了新消息
132+
如果你在程序中添加了新消息
131133

132-
1. 运行 `goi18n extract` 以使用新消息更新 `active.en.toml`
133-
2. 运行 `goi18n merge active.*.toml` 以生成更新的 `translate.*.toml` 文件。
134+
1. 运行 `goi18n extract` 以将新的消息更新到 `active.en.toml`
135+
2. 运行 `goi18n merge active.*.toml` 以生成更新后的 `translate.*.toml` 文件。
134136
3. 翻译 `translate.*.toml` 文件中的所有消息。
135-
4. 运行 `goi18n merge active.*.toml translate.*.toml` 将翻译后的消息合并到 active 消息文件中。
137+
4. 运行 `goi18n merge active.*.toml translate.*.toml` 将翻译后的消息合并到活跃消息文件
138+
(Active Message Files)中。
136139

137-
## 有关更多信息和示例
140+
## 进一步的信息和示例
138141

139-
- 阅读 [文档](https://godoc.org/github.com/nicksnyder/go-i18n/v2)
140-
- 查看 [代码示例](https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/example_test.go)[测试](https://github.com/nicksnyder/go-i18n/blob/main/v2/i18n/localizer_test.go)
141-
- 查看一个示例 [程序](https://github.com/nicksnyder/go-i18n/tree/main/v2/example)
142+
- 阅读[文档](https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2)
143+
- 查看[代码示例](https://github.com/nicksnyder/go-i18n/blob/main/i18n/example_test.go)
144+
[测试](https://github.com/nicksnyder/go-i18n/blob/main/i18n/localizer_test.go)
145+
- 查看示例[程序](https://github.com/nicksnyder/go-i18n/tree/main/example)
142146

143147
## 许可证
144148

145-
go-i18n MIT 许可下可用。有关更多信息,请参阅 [许可证](LICENSE) 文件。
149+
go-i18n 使用在 MIT 许可来提供。更多的相关信息,请参 [LICENSE](LICENSE) 文件。

‎.github/dependabot.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
- package-ecosystem: "gomod"
8+
directory: "/"
9+
schedule:
10+
interval: "monthly"

‎.github/workflows/build.yml‎

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,37 @@
11
name: Build
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
58
jobs:
69
build:
7-
name: Build
10+
name: Build (go:${{ matrix.go-version.name }})
811
runs-on: ubuntu-latest
9-
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'pull_request'
12+
strategy:
13+
matrix:
14+
go-version:
15+
- name: latest
16+
version: 1.24.x
17+
- name: previous
18+
version: 1.23.x
1019
steps:
1120
- name: Install Go
12-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
1322
with:
14-
go-version: stable
23+
go-version: ${{ matrix.go-version.version }}
1524
- name: Git checkout
16-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
1726
- name: Build
18-
uses: goreleaser/goreleaser-action@v2
27+
uses: goreleaser/goreleaser-action@v6
1928
with:
2029
version: latest
21-
args: release --rm-dist --snapshot
22-
workdir: v2
30+
args: release --clean --snapshot
2331
- name: Test
24-
working-directory: v2
2532
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
26-
- name: Upload coverage
27-
uses: codecov/codecov-action@v1
28-
build_1_12:
29-
name: Build with Go 1.12.17
30-
runs-on: ubuntu-latest
31-
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'pull_request'
32-
steps:
33-
- name: Install Go
34-
uses: actions/setup-go@v4
35-
with:
36-
go-version: '1.12.17'
37-
- name: Git checkout
38-
uses: actions/checkout@v3
33+
- name: Lint
34+
uses: golangci/golangci-lint-action@v7
35+
if: matrix.go-version.name == 'latest'
3936
with:
40-
path: gopath/src/github.com/nicksnyder/go-i18n
41-
- name: Build and test
42-
working-directory: gopath/src/github.com/nicksnyder/go-i18n/v2
43-
env:
44-
GOPATH: ${{ github.workspace }}/gopath
45-
GO111MODULE: on
46-
run: |
47-
go get ./...
48-
go test -race ./...
37+
version: v2.0

0 commit comments

Comments
 (0)