@@ -83,10 +83,10 @@ const OUTPUT_BANNER = `#
83
83
84
84
/** @type {import("i18next-parser").UserConfig } */
85
85
const config = {
86
- // Our translation system requires that we add ". zero", ". one", ". other" keys for plurals
86
+ // Our translation system requires that we add all 6 forms ( zero, one, two, few, many, other) keys for plurals
87
87
// i18next-parser extracts plural keys based on the target locale, so we are passing a
88
- // locale that need exactly the ".zero", ".one", ".other" keys , even if we are extracting English strings
89
- locales : [ "lv " ] ,
88
+ // locale that need exactly the 6 forms , even if we are extracting English strings
89
+ locales : [ "ar " ] ,
90
90
keySeparator : false ,
91
91
namespaceSeparator : false ,
92
92
pluralSeparator : "." ,
@@ -132,7 +132,9 @@ class SourceYmlTransform extends Transform {
132
132
}
133
133
134
134
// Add new keys to the source YAML or log mismatched value
135
- for ( const [ key , value ] of Object . entries ( strings ) ) {
135
+ for ( let [ key , value ] of Object . entries ( strings ) ) {
136
+ value = this . #fixPluralValue( key , value , strings ) ;
137
+
136
138
const existingPart = outputContent . parts . find (
137
139
( part ) => part . translation . key === key
138
140
) ;
@@ -205,6 +207,32 @@ class SourceYmlTransform extends Transform {
205
207
206
208
return result ;
207
209
}
210
+
211
+ // if the key ends with .zero, .one, .two, .few, .many, .other and the value is empty
212
+ // find the same key with the `.other` suffix in strings and return the value
213
+ #fixPluralValue( key , value , strings ) {
214
+ if ( key . endsWith ( ".zero" ) && value === "" ) {
215
+ return strings [ key . replace ( ".zero" , ".other" ) ] || "" ;
216
+ }
217
+
218
+ if ( key . endsWith ( ".one" ) && value === "" ) {
219
+ return strings [ key . replace ( ".one" , ".other" ) ] || "" ;
220
+ }
221
+
222
+ if ( key . endsWith ( ".two" ) && value === "" ) {
223
+ return strings [ key . replace ( ".two" , ".other" ) ] || "" ;
224
+ }
225
+
226
+ if ( key . endsWith ( ".few" ) && value === "" ) {
227
+ return strings [ key . replace ( ".few" , ".other" ) ] || "" ;
228
+ }
229
+
230
+ if ( key . endsWith ( ".many" ) && value === "" ) {
231
+ return strings [ key . replace ( ".many" , ".other" ) ] || "" ;
232
+ }
233
+
234
+ return value ;
235
+ }
208
236
}
209
237
210
238
const sourceFilesGlob = args . module
0 commit comments