8000 cmd/gotext: distinguish between key and id · golang/text@595fa11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 595fa11

Browse files
committed
cmd/gotext: distinguish between key and id
The id of the translation and the key that is used at runtime to look up the translation are not the same. The id is used for tracking and linking messages. The key is used for lookup internally. Change-Id: I26cac35fb421ee8227fd8b0b5a712a752c4f5f5e Reviewed-on: https://go-review.googlesource.com/82202 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
1 parent a15b1bf commit 595fa11

File tree

10 files changed

+132
-148
lines changed

10 files changed

+132
-148
lines changed

cmd/gotext/examples/extract/locales/de/out.gotext.json

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
"language": "de",
33
"messages": [
44
{
5-
"key": [
6-
"Hello world!\n"
7-
],
5+
"id": "Hello world!\n",
6+
"key": "Hello world!\n",
87
"message": "Hello world!\n",
98
"translation": "",
109
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
1110
},
1211
{
13-
"key": [
14-
"Hello %s!\n"
15-
],
12+
"id": "Hello {City}!\n",
13+
"key": "Hello %s!\n",
1614
"message": "Hello {City}!\n",
1715
"translation": "",
1816
"placeholders": [
@@ -28,9 +26,8 @@
2826
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:31:10"
2927
},
3028
{
31-
"key": [
32-
"Hello %s!\n"
33-
],
29+
"id": "Hello {Town}!\n",
30+
"key": "Hello %s!\n",
3431
"message": "Hello {Town}!\n",
3532
"translation": "",
3633
"placeholders": [
@@ -47,9 +44,8 @@
4744
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:35:10"
4845
},
4946
{
50-
"key": [
51-
"%s is visiting %s!\n"
52-
],
47+
"id": "{Person} is visiting {Place}!\n",
48+
"key": "%s is visiting %s!\n",
5349
"message": "{Person} is visiting {Place}!\n",
5450
"translation": "",
5551
"placeholders": [
@@ -75,9 +71,8 @@
7571
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:40:10"
7672
},
7773
{
78-
"key": [
79-
"%[1]s is visiting %[3]s!\n"
80-
],
74+
"id": "{Person} is visiting {Place}!\n",
75+
"key": "%[1]s is visiting %[3]s!\n",
8176
"message": "{Person} is visiting {Place}!\n",
8277
"translation": "",
8378
"comment": "Person visiting a place.",
@@ -111,9 +106,8 @@
111106
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:55:10"
112107
},
113108
{
114-
"key": [
115-
"%d files remaining!"
116-
],
109+
"id": "{} files remaining!",
110+
"key": "%d files remaining!",
117111
"message": "{} files remaining!",
118112
"translation": "",
119113
"placeholders": [
@@ -129,9 +123,8 @@
129123
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:62:10"
130124
},
131125
{
132-
"key": [
133-
"%d more files remaining!"
134-
],
126+
"id": "{N} more files remaining!",
127+
"key": "%d more files remaining!",
135128
"message": "{N} more files remaining!",
136129
"translation": "",
137130
"placeholders": [
@@ -147,9 +140,8 @@
147140
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:67:10"
148141
},
149142
{
150-
"key": [
151-
"Use the following code for your discount: %d\n"
152-
],
143+
"id": "Use the following code for your discount: {ReferralCode}\n",
144+
"key": "Use the following code for your discount: %d\n",
153145
"message": "Use the following code for your discount: {ReferralCode}\n",
154146
"translation": "",
155147
"placeholders": [
@@ -165,10 +157,11 @@
165157
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:73:10"
166158
},
167159
{
168-
"key": [
160+
"id": [
169161
"msgOutOfOrder",
170-
"%s is out of order!"
162+
"{Device} is out of order!"
171163
],
164+
"key": "%s is out of order!",
172165
"message": "{Device} is out of order!",
173166
"translation": "",
174167
"comment": "FOO\n",
@@ -185,9 +178,8 @@
185178
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:81:10"
186179
},
187180
{
188-
"key": [
189-
"%.2[1]f miles traveled (%[1]f)"
190-
],
181+
"id": "{Miles} miles traveled ({Miles_1})",
182+
"key": "%.2[1]f miles traveled (%[1]f)",
191183
"message": "{Miles} miles traveled ({Miles_1})",
192184
"translation": "",
193185
"placeholders": [

cmd/gotext/examples/extract/locales/en-US/out.gotext.json

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
"language": "en-US",
33
"messages": [
44
{
5-
"key": [
6-
"Hello world!\n"
7-
],
5+
"id": "Hello world!\n",
6+
"key": "Hello world!\n",
87
"message": "Hello world!\n",
98
"translation": "",
109
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
1110
},
1211
{
13-
"key": [
14-
"Hello %s!\n"
15-
],
12+
"id": "Hello {City}!\n",
13+
"key": "Hello %s!\n",
1614
"message": "Hello {City}!\n",
1715
"translation": "",
1816
"placeholders": [
@@ -28,9 +26,8 @@
2826
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:31:10"
2927
},
3028
{
31-
"key": [
32-
"Hello %s!\n"
33-
],
29+
"id": "Hello {Town}!\n",
30+
"key": "Hello %s!\n",
3431
"message": "Hello {Town}!\n",
3532
"translation": "",
3633
"placeholders": [
@@ -47,9 +44,8 @@
4744
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:35:10"
F987 4845
},
4946
{
50-
"key": [
51-
"%s is visiting %s!\n"
52-
],
47+
"id": "{Person} is visiting {Place}!\n",
48+
"key": "%s is visiting %s!\n",
5349
"message": "{Person} is visiting {Place}!\n",
5450
"translation": "",
5551
"placeholders": [
@@ -75,9 +71,8 @@
7571
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:40:10"
7672
},
7773
{
78-
"key": [
79-
"%[1]s is visiting %[3]s!\n"
80-
],
74+
"id": "{Person} is visiting {Place}!\n",
75+
"key": "%[1]s is visiting %[3]s!\n",
8176
"message": "{Person} is visiting {Place}!\n",
8277
"translation": "",
8378
"comment": "Person visiting a place.",
@@ -111,9 +106,8 @@
111106
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:55:10"
112107
},
113108
{
114-
"key": [
115-
"%d files remaining!"
116-
],
109+
"id": "{} files remaining!",
110+
"key": "%d files remaining!",
117111
"message": "{} files remaining!",
118112
"translation": "",
119113
"placeholders": [
@@ -129,9 +123,8 @@
129123
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:62:10"
130124
},
131125
{
132-
"key": [
133-
"%d more files remaining!"
134-
],
126+
"id": "{N} more files remaining!",
127+
"key": "%d more files remaining!",
135128
"message": "{N} more files remaining!",
136129
"translation": "",
137130
"placeholders": [
@@ -147,9 +140,8 @@
147140
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:67:10"
148141
},
149142
{
150-
"key": [
151-
"Use the following code for your discount: %d\n"
152-
],
143+
"id": "Use the following code for your discount: {ReferralCode}\n",
144+
"key": "Use the following code for your discount: %d\n",
153145
"message": "Use the following code for your discount: {ReferralCode}\n",
154146
"translation": "",
155147
"placeholders": [
@@ -165,10 +157,11 @@
165157
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:73:10"
166158
},
167159
{
168-
"key": [
160+
"id": [
169161
"msgOutOfOrder",
170-
"%s is out of order!"
162+
"{Device} is out of order!"
171163
],
164+
"key": "%s is out of order!",
172165
"message": "{Device} is out of order!",
173166
"translation": "",
174167
"comment": "FOO\n",
@@ -185,9 +178,8 @@
185178
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:81:10"
186179
},
187180
{
188-
"key": [
189-
"%.2[1]f miles traveled (%[1]f)"
190-
],
181+
"id": "{Miles} miles traveled ({Miles_1})",
182+
"key": "%.2[1]f miles traveled (%[1]f)",
191183
"message": "{Miles} miles traveled ({Miles_1})",
192184
"translation": "",
193185
"placeholders": [

cmd/gotext/examples/extract/locales/extracted.gotext.json

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
"language": "en-US",
33
"messages": [
44
{
5-
"key": [
6-
"Hello world!\n"
7-
],
5+
"id": "Hello world!\n",
6+
"key": "Hello world!\n",
87
"message": "Hello world!\n",
98
"translation": "",
109
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:27:10"
1110
},
1211
{
13-
"key": [
14-
"Hello %s!\n"
15-
],
12+
"id": "Hello {City}!\n",
13+
"key": "Hello %s!\n",
1614
"message": "Hello {City}!\n",
1715
"translation": "",
1816
"placeholders": [
@@ -28,9 +26,8 @@
2826
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:31:10"
2927
},
3028
{
31-
"key": [
32-
"Hello %s!\n"
33-
],
29+
"id": "Hello {Town}!\n",
30+
"key": "Hello %s!\n",
3431
"message": "Hello {Town}!\n",
3532
"translation": "",
3633
"placeholders": [
@@ -47,9 +44,8 @@
4744
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:35:10"
4845
},
4946
{
50-
"key": [
51-
"%s is visiting %s!\n"
52-
],
47+
"id": "{Person} is visiting {Place}!\n",
48+
"key": "%s is visiting %s!\n",
5349
"message": "{Person} is visiting {Place}!\n",
5450
"translation": "",
5551
"placeholders": [
@@ -75,9 +71,8 @@
7571
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:40:10"
7672
},
7773
{
78-
"key": [
79-
"%[1]s is visiting %[3]s!\n"
80-
],
74+
"id": "{Person} is visiting {Place}!\n",
75+
"key": "%[1]s is visiting %[3]s!\n",
8176
"message": "{Person} is visiting {Place}!\n",
8277
"translation": "",
8378
"comment": "Person visiting a place.",
@@ -111,9 +106,8 @@
111106
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:55:10"
112107
},
113108
{
114-
"key": [
115-
"%d files remaining!"
116-
],
109+
"id": "{} files remaining!",
110+
"key": "%d files remaining!",
117111
"message": "{} files remaining!",
118112
"translation": "",
119113
"placeholders": [
@@ -129,9 +123,8 @@
129123
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:62:10"
130124
},
131125
{
132-
"key": [
133-
"%d more files remaining!"
134-
],
126+
"id": "{N} more files remaining!",
127+
"key": "%d more files remaining!",
135128
"message": "{N} more files remaining!",
136129
"translation": "",
137130
"placeholders": [
@@ -147,9 +140,8 @@
147140
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:67:10"
148141
},
149142
{
150-
"key": [
151-
"Use the following code for your discount: %d\n"
152-
],
143+
"id": "Use the following code for your discount: {ReferralCode}\n",
144+
"key": "Use the following code for your discount: %d\n",
153145
"message": "Use the following code for your discount: {ReferralCode}\n< D405 /span>",
154146
"translation": "",
155147
"placeholders": [
@@ -165,10 +157,11 @@
165157
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:73:10"
166158
},
167159
{
168-
"key": [
160+
"id": [
169161
"msgOutOfOrder",
170-
"%s is out of order!"
162+
"{Device} is out of order!"
171163
],
164+
"key": "%s is out of order!",
172165
"message": "{Device} is out of order!",
173166
"translation": "",
174167
"comment": "FOO\n",
@@ -185,9 +178,8 @@
185178
"position": "golang.org/x/text/cmd/gotext/examples/extract/main.go:81:10"
186179
},
187180
{
188-
"key": [
189-
"%.2[1]f miles traveled (%[1]f)"
190-
],
181+
"id": "{Miles} miles traveled ({Miles_1})",
182+
"key": "%.2[1]f miles traveled (%[1]f)",
191183
"message": "{Miles} miles traveled ({Miles_1})",
192184
"translation": "",
193185
"placeholders": [

0 commit comments

Comments
 (0)
0