Email for professionals and teams
Prune unused keys; plural-aware catalog parity test
Hieu Nguyen (Jack)0db440c24c62
diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.jsonindex d2b0487..89b8399 100644--- a/src/lib/i18n/en.json+++ b/src/lib/i18n/en.json@@ -114,7 +114,6 @@"source.couldNotCopy": "Could not copy","source.copied": "Copied","source.copy": "Copy to clipboard",- "common.notSpamOrInbox": "Not spam","actions.error.update": "Could not update message","actions.error.delete": "Could not delete message","actions.error.trashRule": "Could not create trash rule",@@ -136,7 +135,6 @@"folder.empty.archived": "No archived emails","folder.empty.spam": "No spam","folder.empty.trash": "No emails in trash",- "folder.empty.custom": "No emails","list.noMatch": "No messages match these filters","list.draft": "Draft","list.unknownSender": "Unknown sender",@@ -160,8 +158,8 @@"list.emptyFailed": "Could not empty {folder}. Please try again.","delete.confirm.one": "Permanently delete this message? This cannot be undone.","delete.confirm.other": "Permanently delete these {count} messages? This cannot be undone.",- "empty.confirm.one": "Permanently delete the 1 message in {folder}? This cannot be undone.",- "empty.confirm.many": "Permanently delete all {count} messages in {folder}? This cannot be undone.",+ "empty.confirm.single": "Permanently delete the 1 message in {folder}? This cannot be undone.",+ "empty.confirm.multiple": "Permanently delete all {count} messages in {folder}? This cannot be undone.","empty.confirm.all": "Permanently delete every message in {folder}? This cannot be undone.","error.updateSelected": "Unable to update selected messages","error.emptyFolder": "Unable to empty folder",@@ -1825,7 +1823,6 @@"agent.queue.sendNow": "Send now","agent.queue.remove": "Remove queued message","agent.loadingConversation": "Loading conversation",- "agent.duration.lessThanSecond": "<1s","importPage.others": "Others","importPage.selectSections": "Select source sections","importPage.selectMailboxFirst": "Select a mailbox first",@@ -1862,6 +1859,5 @@"layout.resizeMenu": "Resize left menu","nav.loadingPage": "Loading page","message.blockRemote": "Block remote content",- "message.allowRemote": "Allow remote content",- "settingsPage.rules.title": "Rules"+ "message.allowRemote": "Allow remote content"}diff --git a/src/lib/i18n/pt-BR.json b/src/lib/i18n/pt-BR.jsonindex 4d5cee0..b407666 100644--- a/src/lib/i18n/pt-BR.json+++ b/src/lib/i18n/pt-BR.json@@ -114,7 +114,6 @@"source.couldNotCopy": "Não foi possível copiar","source.copied": "Copiado","source.copy": "Copiar para a área de transferência",- "common.notSpamOrInbox": "Não é spam","actions.error.update": "Não foi possível atualizar a mensagem","actions.error.delete": "Não foi possível excluir a mensagem","actions.error.trashRule": "Não foi possível criar a regra de lixeira",@@ -136,7 +135,6 @@"folder.empty.archived": "Nenhum e-mail arquivado","folder.empty.spam": "Nenhum spam","folder.empty.trash": "Nenhum e-mail na lixeira",- "folder.empty.custom": "Nenhum e-mail","list.noMatch": "Nenhuma mensagem corresponde a estes filtros","list.draft": "Rascunho","list.unknownSender": "Remetente desconhecido",@@ -160,8 +158,8 @@"list.emptyFailed": "Não foi possível esvaziar {folder}. Tente novamente.","delete.confirm.one": "Excluir esta mensagem permanentemente? Esta ação não pode ser desfeita.","delete.confirm.other": "Excluir estas {count} mensagens permanentemente? Esta ação não pode ser desfeita.",- "empty.confirm.one": "Excluir permanentemente a única mensagem em {folder}? Esta ação não pode ser desfeita.",- "empty.confirm.many": "Excluir permanentemente todas as {count} mensagens em {folder}? Esta ação não pode ser desfeita.",+ "empty.confirm.single": "Excluir permanentemente a única mensagem em {folder}? Esta ação não pode ser desfeita.",+ "empty.confirm.multiple": "Excluir permanentemente todas as {count} mensagens em {folder}? Esta ação não pode ser desfeita.","empty.confirm.all": "Excluir permanentemente todas as mensagens em {folder}? Esta ação não pode ser desfeita.","error.updateSelected": "Não foi possível atualizar as mensagens selecionadas","error.emptyFolder": "Não foi possível esvaziar a pasta",@@ -1825,7 +1823,6 @@"agent.queue.sendNow": "Enviar agora","agent.queue.remove": "Remover mensagem da fila","agent.loadingConversation": "Carregando conversa",- "agent.duration.lessThanSecond": "<1s","importPage.others": "Outras","importPage.selectSections": "Selecione as seções de origem","importPage.selectMailboxFirst": "Selecione uma caixa de correio primeiro",@@ -1862,6 +1859,5 @@"layout.resizeMenu": "Redimensionar menu lateral","nav.loadingPage": "Carregando página","message.blockRemote": "Bloquear conteúdo remoto",- "message.allowRemote": "Permitir conteúdo remoto",- "settingsPage.rules.title": "Regras"+ "message.allowRemote": "Permitir conteúdo remoto"}diff --git a/src/lib/messages/permanent-delete-utils.ts b/src/lib/messages/permanent-delete-utils.tsindex f741689..e50a4c6 100644--- a/src/lib/messages/permanent-delete-utils.ts+++ b/src/lib/messages/permanent-delete-utils.ts@@ -22,6 +22,6 @@ export function getPermanentDeleteConfirmText(count: number, t: Translator = defexport function getEmptyFolderConfirmText(folder: PermanentDeleteFolder, total?: number, t: Translator = defaultTranslator): string {const vars = { count: total ?? 0, folder: getPermanentDeleteFolderLabel(folder, t) };- if (total === 1) return t("empty.confirm.one", vars);- return total && total > 1 ? t("empty.confirm.many", vars) : t("empty.confirm.all", vars);+ if (total === 1) return t("empty.confirm.single", vars);+ return total && total > 1 ? t("empty.confirm.multiple", vars) : t("empty.confirm.all", vars);}diff --git a/tests/i18n.test.mjs b/tests/i18n.test.mjsindex bb3111f..6285d18 100644--- a/tests/i18n.test.mjs+++ b/tests/i18n.test.mjs@@ -66,11 +66,31 @@ await bundleI18n(outfile);const i18n = await import(pathToFileURL(outfile).href);const en = JSON.parse(readFileSync(join(root, "src/lib/i18n/en.json"), "utf8"));+const CATEGORIES = ["zero", "one", "two", "few", "many", "other"];+const categoryOf = (key) => CATEGORIES.find((category) => key.endsWith(`.${category}`));+const baseOf = (key) => categoryOf(key) ? key.slice(0, key.lastIndexOf(".")) : key;+const placeholders = (text) => [...new Set([...text.matchAll(/\{(\w+)\}/g)].map((match) => match[1]))].sort();+// A plural group is `base.other` plus any other CLDR categories; catalogs may carry the categories their language needs.+const pluralBases = new Set(Object.keys(en).filter((key) => key.endsWith(".other")).map(baseOf));+const isPluralKey = (key) => categoryOf(key) && pluralBases.has(baseOf(key));+test("every registered catalog has the English keys and nonempty messages and label", () => {- for (const { messages: catalog, label } of Object.values(i18n.locales)) {- assert.ok(label.trim().length > 0);- assert.deepEqual(Object.keys(catalog).sort(), Object.keys(en).sort());- for (const value of Object.values(catalog)) assert.ok(typeof value === "string" && value.trim().length > 0);+ for (const [code, { messages: catalog, label }] of Object.entries(i18n.locales)) {+ assert.ok(label.trim().length > 0, code);+ const plain = (keys) => keys.filter((key) => !isPluralKey(key)).sort();+ assert.deepEqual(plain(Object.keys(catalog)), plain(Object.keys(en)), `${code}: keys differ from English`);+ for (const base of pluralBases) assert.ok(typeof catalog[`${base}.other`] === "string", `${code}: ${base}.other is required`);+ for (const key of Object.keys(catalog)) {+ if (isPluralKey(key)) assert.ok(`${baseOf(key)}.other` in catalog, `${code}: ${key} has no .other`);+ const value = catalog[key];+ assert.ok(typeof value === "string" && value.trim().length > 0, `${code}: ${key} is empty`);+ const reference = isPluralKey(key) ? en[`${baseOf(key)}.other`] : en[key];+ // A plural variant may drop {count} ("this message"), but never invent a placeholder.+ const allowed = placeholders(reference);+ const used = placeholders(value);+ if (isPluralKey(key)) assert.ok(used.every((name) => allowed.includes(name)), `${code}: ${key} uses an unknown {placeholder}`);+ else assert.deepEqual(used, allowed, `${code}: ${key} changes its {placeholders}`);+ }}});