Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(i18n): restore the Hebrew plural forms older Safari still selects
Yudhi Armyndharisbcb9b2d22c25
diff --git a/dashboard/src/i18n/he-legacy-plurals.test.ts b/dashboard/src/i18n/he-legacy-plurals.test.tsnew file mode 100644index 000000000..e094f1669--- /dev/null+++ b/dashboard/src/i18n/he-legacy-plurals.test.ts@@ -0,0 +1,56 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';+import i18next from 'i18next';++// Before CLDR 42 Hebrew had a `many` plural category (20, 30, 40, ...). Safari takes its plural data+// from the operating system, so Safari 16.4 and 17 on macOS 12 still select it, and those are inside+// the build's browser target. i18next falls back from a missing `_many` to the bare key, which is the+// Hebrew singular, so every plural key needs a `_many` form even though current runtimes never ask.++const HERE = dirname(fileURLToPath(import.meta.url));+const load = (file: string): Record<string, unknown> =>+ JSON.parse(readFileSync(join(HERE, 'locales', file), 'utf8')) as Record<string, unknown>;++function flatten(obj: Record<string, unknown>, prefix = '', out = new Map<string, unknown>()) {+ for (const [key, value] of Object.entries(obj)) {+ const path = prefix ? `${prefix}.${key}` : key;+ if (value && typeof value === 'object') flatten(value as Record<string, unknown>, path, out);+ else out.set(path, value);+ }+ return out;+}++class PreCldr42PluralRules extends Intl.PluralRules {+ select(n: number): Intl.LDMLPluralRule {+ return Number.isInteger(n) && n > 10 && n % 10 === 0 ? 'many' : super.select(n);+ }+ resolvedOptions(): Intl.ResolvedPluralRulesOptions {+ const options = super.resolvedOptions();+ return { ...options, pluralCategories: [...new Set([...options.pluralCategories, 'many' as const])] };+ }+}++test('Hebrew renders the plural form for 20 under the pre-CLDR-42 plural rules', async () => {+ const pluralBases = [...flatten(load('en.json')).keys()]+ .filter(key => key.endsWith('_other'))+ .map(key => key.slice(0, -'_other'.length));+ const he = flatten(load('he.json'));++ const intl = Intl as { PluralRules: typeof Intl.PluralRules };+ const native = intl.PluralRules;+ // A class cannot be called without `new`; i18next only ever constructs it.+ intl.PluralRules = PreCldr42PluralRules as typeof Intl.PluralRules;+ try {+ const i18n = i18next.createInstance();+ await i18n.init({ lng: 'he', resources: { he: { translation: load('he.json') } }, initAsync: false });+ for (const base of pluralBases) {+ const expected = String(he.get(`${base}_other`)).replace('{{count}}', '20');+ assert.equal(i18n.t(base, { count: 20 }), expected, base);+ }+ } finally {+ intl.PluralRules = native;+ }+});diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 0e121b623..96ccdb28d 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -32,9 +32,11 @@"never": "אף פעם","justNow": "ממש עכשיו","minAgo": "לפני {{count}} דקה",+ "minAgo_many": "לפני {{count}} דקות","minAgo_other": "לפני {{count}} דקות","minAgo_two": "לפני שתי דקות","hoursAgo": "לפני {{count}} שעה",+ "hoursAgo_many": "לפני {{count}} שעות","hoursAgo_other": "לפני {{count}} שעות","hoursAgo_two": "לפני שעתיים","optional": "אופציונלי",@@ -91,6 +93,7 @@"empty": "אין שיחות","noMessageYet": "אין הודעות עדיין","unreadBadge": "{{count}} הודעה שלא נקראה",+ "unreadBadge_many": "{{count}} הודעות שלא נקראו","unreadBadge_other": "{{count}} הודעות שלא נקראו","unreadBadge_two": "שתי הודעות שלא נקראו","loadingMessages": "טוען הודעות...",@@ -158,6 +161,7 @@"itemCount": "עדכון {{count}}","itemCount_one": "עדכון {{count}}","itemCount_two": "{{count}} עדכונים",+ "itemCount_many": "{{count}} עדכונים","itemCount_other": "{{count}} עדכונים","empty": "לאף איש קשר אין סטטוס פעיל.","loadError": "טעינת הסטטוסים נכשלה.",@@ -183,6 +187,7 @@"empty": "עדיין אינך רשום/ה לאף ערוץ.","notReady": "הסשן עדיין אינו מוכן.","subscribers": "{{count}} מנוי",+ "subscribers_many": "{{count}} מנויים","subscribers_other": "{{count}} מנויים","subscribers_two": "שני מנויים"},@@ -457,6 +462,7 @@"saveChanges": "שמירת שינויים","filters": {"badge": "{{count}} מסנן",+ "badge_many": "{{count}} מסננים","badge_other": "{{count}} מסננים","badge_two": "שני מסננים","title": "מסננים (אופציונלי)",