You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48Lines changed: 48 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,54 @@ Here is an example of the default file format that go-i18n supports:
118
118
119
119
To use a different file format, write a parser for the format and add the parsed translations using [AddTranslation](https://godoc.org/github.com/nicksnyder/go-i18n/i18n#AddTranslation).
120
120
121
+
Flat Format
122
+
-------------
123
+
124
+
You can also write shorter translation files with flat format.
125
+
E.g the example above can be written in this way:
126
+
127
+
```json
128
+
{
129
+
"d_days": {
130
+
"one": "{{.Count}} day.",
131
+
"other": "{{.Count}} days."
132
+
},
133
+
134
+
"my_height_in_meters": {
135
+
"one": "I am {{.Count}} meter tall.",
136
+
"other": "I am {{.Count}} meters tall."
137
+
},
138
+
139
+
"person_greeting": {
140
+
"other": "Hello {{.Person}}"
141
+
},
142
+
143
+
"person_unread_email_count": {
144
+
"one": "{{.Person}} has {{.Count}} unread email.",
145
+
"other": "{{.Person}} has {{.Count}} unread emails."
146
+
},
147
+
148
+
"person_unread_email_count_timeframe": {
149
+
"one": "{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.",
150
+
"other": "{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}."
151
+
},
152
+
153
+
"program_greeting": {
154
+
"other": "Hello world"
155
+
},
156
+
157
+
"your_unread_email_count": {
158
+
"one": "You have {{.Count}} unread email.",
159
+
"other": "You have {{.Count}} unread emails."
160
+
}
161
+
}
162
+
```
163
+
164
+
The logic of flat format is, what it is structure of structures
165
+
and name of substructures (ids) should be always a string.
166
+
If there is only one key in substructure and it is "other", then it's non-plural
0 commit comments