Skip to content

Commit

Permalink
Merge pull request #37 from FlexConfirmMail/add-en-and-zh-locales
Browse files Browse the repository at this point in the history
Add en and zh-CN locales
  • Loading branch information
HashidaTKS authored Oct 17, 2024
2 parents 4a6700b + 02d3e07 commit 16476d7
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 17 deletions.
25 changes: 25 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"confirmation_trustedCaption": "Internal Recipients",
"confirmation_trustedCheckAllButtonLabel": "Check all",
"confirmation_untrustedCaption": "External Recipients",
"confirmation_miscCaption": "Attachments / Warnings",
"confirmation_sendButtonLabel": "Send",
"confirmation_cancelButtonLabel": "Cancel",

"confirmation_safeBccThresholdCheckboxLabel": "[Warn] To/Cc fields contain no less than ${threshold} domains",
"confirmation_unsafeDomainRecipientCheckboxLabel": "[Warn] An unsafe domain \"${domain}\" found in the recipient list",
"confirmation_unsafeRecipientCheckboxLabel": "[Warn] An unsafe address \"${address}\" found in the recipient list",
"confirmation_unsafeAttachmentCheckboxLabel": "[Warn] An unsafe keyword (${name}) found in the attachment list",
"confirmation_attachmentCheckboxLabel": "[Attachment] ${name}",

"newlyAddedDomainReconfirmation_caption": "CAUTION!",
"newlyAddedDomainReconfirmation_messageBefore": "There are recipients with domains not included in the recipients of the original message.",
"newlyAddedDomainReconfirmation_messageAfter": "Do you really want to send this message?",
"newlyAddedDomainReconfirmation_sendButtonLabel": "Send",
"newlyAddedDomainReconfirmation_cancelButtonLabel": "Cancel",

"countDown_messageBefore": "",
"countDown_messageAfter": "seconds to send",
"countDown_sendButtonLabel": "Send Now",
"countDown_cancelButtonLabel": "Cancel"
}
2 changes: 1 addition & 1 deletion locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"confirmation_unsafeDomainRecipientCheckboxLabel": "[警告] 注意が必要なドメイン(${domain})が宛先に含まれています。",
"confirmation_unsafeRecipientCheckboxLabel": "[警告] 注意が必要な宛先(${address})が含まれています。",
"confirmation_unsafeAttachmentCheckboxLabel": "[警告] 注意が必要なファイル名(${name})が含まれています。",
"confirmation_attachmentCheckboxLabel": "[添付ファイル] ${name}",
"confirmation_attachmentCheckboxLabel": "[添付ファイル] ${name}",

"newlyAddedDomainReconfirmation_caption": "CAUTION!",
"newlyAddedDomainReconfirmation_messageBefore": "返信元のメールの宛先に含まれていなかったドメインの以下の宛先が追加されています。",
Expand Down
25 changes: 25 additions & 0 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"confirmation_trustedCaption": "信任域,地址",
"confirmation_trustedCheckAllButtonLabel": "勾选所有",
"confirmation_untrustedCaption": "外部目的地",
"confirmation_miscCaption": "附件 / 警告",
"confirmation_sendButtonLabel": "发送",
"confirmation_cancelButtonLabel": "取消",

"confirmation_safeBccThresholdCheckboxLabel": "[警告] To/Cc 包含${threshold}个以上的域",
"confirmation_unsafeDomainRecipientCheckboxLabel": "[警告] 包含不安全的域 (${domain})",
"confirmation_unsafeRecipientCheckboxLabel": "[警告] 包含不安全地址 (${address})",
"confirmation_unsafeAttachmentCheckboxLabel": "[警告] 包含不安全的文件名 (${name})",
"confirmation_attachmentCheckboxLabel": "[附件] ${name}",

"newlyAddedDomainReconfirmation_caption": "警告!",
"_newlyAddedDomainReconfirmation_messageBefore": "There are recipients with domains not included in the recipients of the original message.",
"_newlyAddedDomainReconfirmation_messageAfter": "Do you really want to send this message?",
"newlyAddedDomainReconfirmation_sendButtonLabel": "发送",
"newlyAddedDomainReconfirmation_cancelButtonLabel": "取消",

"countDown_messageBefore": "",
"countDown_messageAfter": "秒后发送",
"countDown_sendButtonLabel": "现在发送",
"countDown_cancelButtonLabel": "取消"
}
10 changes: 8 additions & 2 deletions src/web/l10n.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ export class L10n {
return this.instances[language] || (this.instances[language] = new L10n(language));
}

static clearCache() {
this.cache = {};
this.requests = {};
this.instances = {};
}

constructor(language) {
this.language = language || "en-US";
this.language = language || "en";
this.ready = this.load().then(() => true);
}

Expand All @@ -36,7 +42,7 @@ export class L10n {
const [locale, fallbackLocale, defaultLocale] = await Promise.all([
L10n.loadLocale(this.language),
L10n.loadLocale(this.language.split("-")[0]),
L10n.loadLocale("en-US"),
L10n.loadLocale("en"),
]);
this.locale = locale;
this.fallbackLocale = fallbackLocale;
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"effectiveMessage": "Message with effective content",
"blankMessage": "Blank message",
"messageWithPlaceholders": "Message with placeholders: ${one}, ${two}",
"missingFallbackMessage": "Message defined in fallback locales",
"missingMessage": "Message not defined in non-default locales"
}
7 changes: 7 additions & 0 deletions tests/fixtures/locales/ja-JP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"effectiveMessage": "JP:意味ある内容を含むメッセージ",
"blankMessage": "",
"messageWithPlaceholders": "JP:プレースホルダーを含むメッセージ:${one}, ${two}, ${three}",
"_missingFallbackMessage": "JP:フォールバック先で定義されているメッセージ",
"_missingMessage": "JP:未定義のメッセージ"
}
7 changes: 7 additions & 0 deletions tests/fixtures/locales/ja.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"effectiveMessage": "意味ある内容を含むメッセージ",
"blankMessage": "空のメッセージ",
"messageWithPlaceholders": "プレースホルダーを含むメッセージ:${one}, ${two}",
"missingFallbackMessage": "フォールバック先で定義されているメッセージ",
"_missingMessage": "未定義のメッセージ"
}
5 changes: 4 additions & 1 deletion tests/unit/l10n.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ L10n.JSONFetcher = async (url) => {
return null;
};

L10n.baseUrl = (new URL(`${import.meta.url}/../../../`)).toString();
export function clear() {
L10n.clearCache();
L10n.baseUrl = (new URL(`${import.meta.url}/../../../`)).toString();
}
24 changes: 13 additions & 11 deletions tests/unit/test-attachments-confirmation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
*/
'use strict';

import "./l10n.mjs";
import * as L10nUtils from "./l10n.mjs";
import { L10n } from "../../src/web/l10n.mjs";
import { AttachmentsConfirmation } from "../../src/web/attachments-confirmation.mjs";
import { assert } from "tiny-esm-test-runner";
const { is } = assert;

const confirmation = new AttachmentsConfirmation("ja");
let confirmation;

export async function setUp() {
L10nUtils.clear();
confirmation = new AttachmentsConfirmation("ja");
await confirmation.ready;
}

Expand Down Expand Up @@ -71,8 +73,8 @@ test_classify.parameters = {
unsafeAttachments: [],
warnings: [],
confirmations: [
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
],
},
WithUnsafeFiles: {
Expand Down Expand Up @@ -102,8 +104,8 @@ test_classify.parameters = {
"[警告] 注意が必要なファイル名(Unsafe.txt)が含まれています。",
],
confirmations: [
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
],
},
WithMultipleUnsafeFiles: {
Expand Down Expand Up @@ -145,11 +147,11 @@ test_classify.parameters = {
"[警告] 注意が必要なファイル名(【機 密】.txt)が含まれています。",
],
confirmations: [
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
"[添付ファイル] Zipped.ZIP",
"[添付ファイル] 【機密】.txt",
"[添付ファイル] 【機 密】.txt",
"[添付ファイル] Safe.txt",
"[添付ファイル] Unsafe.txt",
"[添付ファイル] Zipped.ZIP",
"[添付ファイル] 【機密】.txt",
"[添付ファイル] 【機 密】.txt",
],
},
};
Expand Down
65 changes: 65 additions & 0 deletions tests/unit/test-l10n.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';

import "./l10n.mjs";
import { L10n } from "../../src/web/l10n.mjs";
import { assert } from "tiny-esm-test-runner";
const { is } = assert;

async function prepare(language) {
L10n.clearCache();
L10n.baseUrl = (new URL(`${import.meta.url}/../../fixtures/`)).toString();
const l10n = new L10n(language);
await l10n.ready;
return l10n;
}

test_get.parameters = {
effective: {
language: "ja-JP",
key: "effectiveMessage",
expected: "JP:意味ある内容を含むメッセージ",
},
blank: {
language: "ja-JP",
key: "blankMessage",
expected: "",
},
withPlaceholders: {
language: "ja-JP",
key: "messageWithPlaceholders",
params: {
one: "One",
two: "Two",
},
expected: "JP:プレースホルダーを含むメッセージ:One, Two, ${three}",
},
fallbackToGeneralLocale: {
language: "ja-JP",
key: "missingFallbackMessage",
expected: "フォールバック先で定義されているメッセージ",
},
fallbackToDefaultLocale: {
language: "ja-JP",
key: "missingMessage",
expected: "Message not defined in non-default locales",
},
differentLocale: {
language: "en",
key: "effectiveMessage",
expected: "Message with effective content",
},
undefinedMessage: {
language: "en",
key: "undefinedMessage",
expected: "undefinedMessage",
}
};
export async function test_get({ language, key, params, expected }) {
const l10n = await prepare(language);
is(expected, l10n.get(key, params || null));
}
6 changes: 4 additions & 2 deletions tests/unit/test-safe-bcc-confirmation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/
'use strict';

import "./l10n.mjs";
import * as L10nUtils from "./l10n.mjs";
import { SafeBccConfirmation } from "../../src/web/safe-bcc-confirmation.mjs";
import { assert } from "tiny-esm-test-runner";
const { ok, ng, is } = assert;

const confirmation = new SafeBccConfirmation("ja");
let confirmation;

export async function setUp() {
L10nUtils.clear();
confirmation = new SafeBccConfirmation("ja");
await confirmation.ready;
}

Expand Down

0 comments on commit 16476d7

Please sign in to comment.