From b45c06ac36cc7879660c74a5d53b30061adac0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 6 Aug 2020 01:39:51 +0800 Subject: [PATCH] Added the JavaScript text message translation. --- .../locale/zh_Hant/LC_MESSAGES/djangojs.po | 43 +++++++++++++++++++ .../static/accounting/js/transaction-form.js | 36 +++------------- 2 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 accounting/locale/zh_Hant/LC_MESSAGES/djangojs.po diff --git a/accounting/locale/zh_Hant/LC_MESSAGES/djangojs.po b/accounting/locale/zh_Hant/LC_MESSAGES/djangojs.po new file mode 100644 index 0000000..cfac216 --- /dev/null +++ b/accounting/locale/zh_Hant/LC_MESSAGES/djangojs.po @@ -0,0 +1,43 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-08-06 01:34+0800\n" +"PO-Revision-Date: 2020-08-06 01:38+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: accounting/static/accounting/js/transaction-form.js:369 +msgid "Please fill in the date." +msgstr "請填上日期。" + +#: accounting/static/accounting/js/transaction-form.js:389 +msgid "Please select the account." +msgstr "請選擇會計科目。" + +#: accounting/static/accounting/js/transaction-form.js:410 +msgid "This summary is too long (max. 128 characters)." +msgstr "摘要太長了(最長128個字)。" + +#: accounting/static/accounting/js/transaction-form.js:431 +msgid "Please fill in the amount." +msgstr "請填上金額。" + +#: accounting/static/accounting/js/transaction-form.js:463 +msgid "The total amount of debit and credit records are inconsistent." +msgstr "借方和貸方合計不符。" + +#: accounting/static/accounting/js/transaction-form.js:484 +msgid "This note is too long (max. 128 characters)." +msgstr "註記太長了(最長128個字)。" diff --git a/accounting/static/accounting/js/transaction-form.js b/accounting/static/accounting/js/transaction-form.js index 0b59168..bc24248 100644 --- a/accounting/static/accounting/js/transaction-form.js +++ b/accounting/static/accounting/js/transaction-form.js @@ -66,30 +66,6 @@ $(function () { }); }); -/** - * The localized messages - * @type {Array.} - * @private - */ -let l10n = null; - -/** - * Returns the localization of a message. - * - * @param {string} key the message key - * @returns {string} the localized message - * @private - */ -function __(key) { - if (l10n === null) { - l10n = JSON.parse($("#l10n-messages").val()); - } - if (key in l10n) { - return l10n[key]; - } - return key; -} - /** * Returns whether this is a transfer transaction. * @@ -390,7 +366,7 @@ function validateDate() { const errorMessage = $("#txn-date-error"); if (date.value === "") { date.classList.add("is-invalid"); - errorMessage.text(__("Please fill in the date.")); + errorMessage.text(gettext("Please fill in the date.")); return false; } date.classList.remove("is-invalid"); @@ -410,7 +386,7 @@ function validateAccount(account) { const errorMessage = $("#" + account.id + "-error"); if (account.value === "") { account.classList.add("is-invalid"); - errorMessage.text(__("Please select the account.")); + errorMessage.text(gettext("Please select the account.")); return false; } account.classList.remove("is-invalid"); @@ -431,7 +407,7 @@ function validateSummary(summary) { summary.value = summary.value.trim(); if (summary.value.length > 128) { summary.classList.add("is-invalid"); - errorMessage.text(__("This summary is too long (max. 128 characters).")); + errorMessage.text(gettext("This summary is too long (max. 128 characters).")); return false; } summary.classList.remove("is-invalid"); @@ -452,7 +428,7 @@ function validateAmount(amount) { amount.value = amount.value.trim(); if (amount.value === "") { amount.classList.add("is-invalid"); - errorMessage.text(__("Please fill in the amount.")); + errorMessage.text(gettext("Please fill in the amount.")); return false; } amount.classList.remove("is-invalid"); @@ -484,7 +460,7 @@ function validateBalance() { }); if (debitTotal !== creditTotal) { balanceRows.addClass("is-invalid"); - errorMessages.text(__("The sum of debit and credit are inconsistent.")) + errorMessages.text(gettext("The total amount of debit and credit records are inconsistent.")) return false; } balanceRows.removeClass("is-invalid"); @@ -505,7 +481,7 @@ function validateNote() { note.value = note.value.trim(); if (note.value.length > 128) { note.classList.add("is-invalid"); - errorMessage.text(__("This note is too long (max. 128 characters).")); + errorMessage.text(gettext("This note is too long (max. 128 characters).")); return false; } note.classList.remove("is-invalid");