@kemdict/gettext 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,6 +155,12 @@ export const pluralFuncTable = {
155
155
  "(n>2)": (n) => n > 2,
156
156
  };
157
157
 
158
+ // Extra plurals, which should be submitted somewhere but no one (including me)
159
+ // has bothered yet
160
+ const extraPlurals = {
161
+ nan: "nplurals=1; plural=0;",
162
+ };
163
+
158
164
  // from Gettext's plural-table.c
159
165
  // prettier-ignore
160
166
  const pluralTable = {
@@ -234,12 +240,10 @@ const cldrPlurals = {
234
240
  * @param {string} locale - The locale to look up.
235
241
  */
236
242
  export function localePluralForms(locale) {
237
- // Try gettext's first
238
- for (const [langs, value] of Object.entries(pluralTable)) {
239
- if (langs.split(" ").includes(locale)) return value;
240
- }
241
- // Then try CLDR
242
- for (const [langs, value] of Object.entries(cldrPlurals)) {
243
- if (langs.split(" ").includes(locale)) return value;
243
+ // Try our extras first, then gettext's plural-table, then finally cldr
244
+ for (const table of [extraPlurals, pluralTable, cldrPlurals]) {
245
+ for (const [langs, value] of Object.entries(table)) {
246
+ if (langs.split(" ").includes(locale)) return value;
247
+ }
244
248
  }
245
249
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kemdict/gettext",
3
3
  "description": "A JavaScript implementation of gettext, a localization framework",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1 +1 @@
1
- {"version":3,"file":"plural-data.d.ts","sourceRoot":"","sources":["../lib/plural-data.js"],"names":[],"mappings":"AAuOA;;;GAGG;AACH,0CAFW,MAAM,sBAWhB;AA/OD;;;;;uBAKuB;AAEvB;;;;;GAKG;AACH,8BAFS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA2IjC;yBArJY,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;6BAClD;IACR,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAA;CACpB"}
1
+ {"version":3,"file":"plural-data.d.ts","sourceRoot":"","sources":["../lib/plural-data.js"],"names":[],"mappings":"AA6OA;;;GAGG;AACH,0CAFW,MAAM,sBAShB;AAnPD;;;;;uBAKuB;AAEvB;;;;;GAKG;AACH,8BAFS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA2IjC;yBArJY,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;6BAClD;IACR,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAA;CACpB"}