From e404f5e6d3001906c11b82a532db518720caebfd Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 7 Apr 2020 20:17:15 +0530 Subject: add test case for i18n, fix react i18n bug --- src/i18n/strings.ts | 669 ++++++++++++++++++++++++------------------------ src/webex/i18n-test.tsx | 69 +++++ src/webex/i18n.tsx | 132 ++++------ 3 files changed, 452 insertions(+), 418 deletions(-) create mode 100644 src/webex/i18n-test.tsx (limited to 'src') diff --git a/src/i18n/strings.ts b/src/i18n/strings.ts index 6d9161f24..748b9656a 100644 --- a/src/i18n/strings.ts +++ b/src/i18n/strings.ts @@ -16,353 +16,358 @@ export const strings: { [s: string]: any } = {}; strings["de"] = { - "Invalid Wire": [null, ""], - "Invalid Test Wire Detail": [null, ""], - "Test Wire Acct #%1$s on %2$s": [null, ""], - "Unknown Wire Detail": [null, ""], - Operation: [null, ""], - "time (ms/op)": [null, ""], - "The total price is %1$s (plus %2$s fees).": [null, ""], - "The total price is %1$s.": [null, ""], - Retry: [null, ""], - Balance: [null, "Saldo"], - History: [null, "Verlauf"], - Debug: [null, "Debug"], - "%1$s incoming": [null, ""], - "%1$s being spent": [null, ""], - "Error: could not retrieve balance information.": [null, ""], - "Invalid ": [null, ""], - "Fees ": [null, ""], - "Refresh sessions has completed": [null, ""], - "Order Refused": [null, ""], - "Order redirected": [null, ""], - "Payment aborted": [null, ""], - "Payment Sent": [null, ""], - "Order accepted": [null, ""], - "Reserve balance updated": [null, ""], - "Payment refund": [null, ""], - "Tip Accepted": [null, ""], - "Tip Declined": [null, ""], - "%1$s": [null, ""], - "Your wallet has no events recorded.": [ - null, - "Ihre Geldbörse verzeichnet keine Vorkommnisse.", - ], - "Wire to bank account": [null, ""], - "Could not get details for withdraw operation:": [null, ""], - "Chose different exchange provider": [null, ""], - "Please select an exchange. You can review the details before after your selection.": [ - null, - "", - ], - "Select %1$s": [null, ""], - "Select custom exchange": [null, ""], - "You are about to withdraw %1$s from your bank account into your wallet.": [ - null, - "", - ], - "Accept fees and withdraw": [null, ""], - "Cancel withdraw operation": [null, ""], - "Rounding loss:": [null, ""], - "Earliest expiration (for deposit): %1$s": [null, ""], - "# Coins": [null, ""], - Value: [null, ""], - "Refresh Fee": [null, ""], - "Deposit Fee": [null, ""], - "": { - "project-id-version": "Taler Wallet", - "report-msgid-bugs-to": "", - "pot-creation-date": "2016-11-23 00:00+0100", - "po-revision-date": "YEAR-MO-DA HO:MI+ZONE", - "last-translator": "FULL NAME ", - "language-team": "LANGUAGE ", - language: "", - "mime-version": "1.0", - "content-type": "text/plain; charset=UTF-8", - "content-transfer-encoding": "8bit", - "plural-forms": "nplurals=2; plural=(n != 1);", + domain: "messages", + locale_data: { + messages: { + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + "Invalid Wire": [""], + "Invalid Test Wire Detail": [""], + "Test Wire Acct #%1$s on %2$s": [""], + "Unknown Wire Detail": [""], + Operation: [""], + "time (ms/op)": [""], + "The merchant %1$s offers you to purchase:": [ + "Der Händler %1$s möchte einen Vertrag über %2$s mit Ihnen abschließen.", + ], + "The total price is %1$s (plus %2$s fees).": [""], + "The total price is %1$s.": [""], + Retry: [""], + "Confirm payment": ["Bezahlung bestätigen"], + Balance: ["Saldo"], + History: ["Verlauf"], + Debug: ["Debug"], + "You have no balance to show. Need some %1$s getting started?": [ + "Sie haben kein Digitalgeld. Wollen Sie %1$s? abheben?", + ], + "%1$s incoming": [""], + "%1$s being spent": [""], + "Error: could not retrieve balance information.": [""], + "Invalid ": [""], + "Fees ": [""], + "Refresh sessions has completed": [""], + "Order Refused": [""], + "Order redirected": [""], + "Payment aborted": [""], + "Payment Sent": [""], + "Order accepted": [""], + "Reserve balance updated": [""], + "Payment refund": [""], + Withdrawn: ["Abheben bei %1$s"], + "Tip Accepted": [""], + "Tip Declined": [""], + "%1$s": [""], + "Your wallet has no events recorded.": [ + "Ihre Geldbörse verzeichnet keine Vorkommnisse.", + ], + "Wire to bank account": [""], + Confirm: ["Bezahlung bestätigen"], + Cancel: ["Saldo"], + "Could not get details for withdraw operation:": [""], + "Chose different exchange provider": [""], + "Please select an exchange. You can review the details before after your selection.": [ + "", + ], + "Select %1$s": [""], + "Select custom exchange": [""], + "You are about to withdraw %1$s from your bank account into your wallet.": [ + "", + ], + "Accept fees and withdraw": [""], + "Cancel withdraw operation": [""], + "Withdrawal fees:": ["Abheben bei"], + "Rounding loss:": [""], + "Earliest expiration (for deposit): %1$s": [""], + "# Coins": [""], + Value: [""], + "Withdraw Fee": ["Abheben bei %1$s"], + "Refresh Fee": [""], + "Deposit Fee": [""], + }, }, }; strings["en-US"] = { - "Invalid Wire": [null, ""], - "Invalid Test Wire Detail": [null, ""], - "Test Wire Acct #%1$s on %2$s": [null, ""], - "Unknown Wire Detail": [null, ""], - Operation: [null, ""], - "time (ms/op)": [null, ""], - "The merchant %1$s offers you to purchase:": [null, ""], - "The total price is %1$s (plus %2$s fees).": [null, ""], - "The total price is %1$s.": [null, ""], - Retry: [null, ""], - "Confirm payment": [null, ""], - Balance: [null, ""], - History: [null, ""], - Debug: [null, ""], - "You have no balance to show. Need some %1$s getting started?": [null, ""], - "%1$s incoming": [null, ""], - "%1$s being spent": [null, ""], - "Error: could not retrieve balance information.": [null, ""], - "Invalid ": [null, ""], - "Fees ": [null, ""], - "Refresh sessions has completed": [null, ""], - "Order Refused": [null, ""], - "Order redirected": [null, ""], - "Payment aborted": [null, ""], - "Payment Sent": [null, ""], - "Order accepted": [null, ""], - "Reserve balance updated": [null, ""], - "Payment refund": [null, ""], - Withdrawn: [null, ""], - "Tip Accepted": [null, ""], - "Tip Declined": [null, ""], - "%1$s": [null, ""], - "Your wallet has no events recorded.": [null, ""], - "Wire to bank account": [null, ""], - Confirm: [null, ""], - Cancel: [null, ""], - "Could not get details for withdraw operation:": [null, ""], - "Chose different exchange provider": [null, ""], - "Please select an exchange. You can review the details before after your selection.": [ - null, - "", - ], - "Select %1$s": [null, ""], - "Select custom exchange": [null, ""], - "You are about to withdraw %1$s from your bank account into your wallet.": [ - null, - "", - ], - "Accept fees and withdraw": [null, ""], - "Cancel withdraw operation": [null, ""], - "Withdrawal fees:": [null, ""], - "Rounding loss:": [null, ""], - "Earliest expiration (for deposit): %1$s": [null, ""], - "# Coins": [null, ""], - Value: [null, ""], - "Withdraw Fee": [null, ""], - "Refresh Fee": [null, ""], - "Deposit Fee": [null, ""], - "": { - "project-id-version": "Taler Wallet", - "report-msgid-bugs-to": "", - "pot-creation-date": "2016-11-23 00:00+0100", - "po-revision-date": "YEAR-MO-DA HO:MI+ZONE", - "last-translator": "FULL NAME ", - "language-team": "LANGUAGE ", - language: "", - "mime-version": "1.0", - "content-type": "text/plain; charset=UTF-8", - "content-transfer-encoding": "8bit", - "plural-forms": "nplurals=2; plural=(n != 1);", + domain: "messages", + locale_data: { + messages: { + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + "Invalid Wire": [""], + "Invalid Test Wire Detail": [""], + "Test Wire Acct #%1$s on %2$s": [""], + "Unknown Wire Detail": [""], + Operation: [""], + "time (ms/op)": [""], + "The merchant %1$s offers you to purchase:": [""], + "The total price is %1$s (plus %2$s fees).": [""], + "The total price is %1$s.": [""], + Retry: [""], + "Confirm payment": [""], + Balance: [""], + History: [""], + Debug: [""], + "You have no balance to show. Need some %1$s getting started?": [""], + "%1$s incoming": [""], + "%1$s being spent": [""], + "Error: could not retrieve balance information.": [""], + "Invalid ": [""], + "Fees ": [""], + "Refresh sessions has completed": [""], + "Order Refused": [""], + "Order redirected": [""], + "Payment aborted": [""], + "Payment Sent": [""], + "Order accepted": [""], + "Reserve balance updated": [""], + "Payment refund": [""], + Withdrawn: [""], + "Tip Accepted": [""], + "Tip Declined": [""], + "%1$s": [""], + "Your wallet has no events recorded.": [""], + "Wire to bank account": [""], + Confirm: [""], + Cancel: [""], + "Could not get details for withdraw operation:": [""], + "Chose different exchange provider": [""], + "Please select an exchange. You can review the details before after your selection.": [ + "", + ], + "Select %1$s": [""], + "Select custom exchange": [""], + "You are about to withdraw %1$s from your bank account into your wallet.": [ + "", + ], + "Accept fees and withdraw": [""], + "Cancel withdraw operation": [""], + "Withdrawal fees:": [""], + "Rounding loss:": [""], + "Earliest expiration (for deposit): %1$s": [""], + "# Coins": [""], + Value: [""], + "Withdraw Fee": [""], + "Refresh Fee": [""], + "Deposit Fee": [""], + }, }, }; strings["fr"] = { - "Invalid Wire": [null, ""], - "Invalid Test Wire Detail": [null, ""], - "Test Wire Acct #%1$s on %2$s": [null, ""], - "Unknown Wire Detail": [null, ""], - Operation: [null, ""], - "time (ms/op)": [null, ""], - "The merchant %1$s offers you to purchase:": [null, ""], - "The total price is %1$s (plus %2$s fees).": [null, ""], - "The total price is %1$s.": [null, ""], - Retry: [null, ""], - "Confirm payment": [null, ""], - Balance: [null, ""], - History: [null, ""], - Debug: [null, ""], - "You have no balance to show. Need some %1$s getting started?": [null, ""], - "%1$s incoming": [null, ""], - "%1$s being spent": [null, ""], - "Error: could not retrieve balance information.": [null, ""], - "Invalid ": [null, ""], - "Fees ": [null, ""], - "Refresh sessions has completed": [null, ""], - "Order Refused": [null, ""], - "Order redirected": [null, ""], - "Payment aborted": [null, ""], - "Payment Sent": [null, ""], - "Order accepted": [null, ""], - "Reserve balance updated": [null, ""], - "Payment refund": [null, ""], - Withdrawn: [null, ""], - "Tip Accepted": [null, ""], - "Tip Declined": [null, ""], - "%1$s": [null, ""], - "Your wallet has no events recorded.": [null, ""], - "Wire to bank account": [null, ""], - Confirm: [null, ""], - Cancel: [null, ""], - "Could not get details for withdraw operation:": [null, ""], - "Chose different exchange provider": [null, ""], - "Please select an exchange. You can review the details before after your selection.": [ - null, - "", - ], - "Select %1$s": [null, ""], - "Select custom exchange": [null, ""], - "You are about to withdraw %1$s from your bank account into your wallet.": [ - null, - "", - ], - "Accept fees and withdraw": [null, ""], - "Cancel withdraw operation": [null, ""], - "Withdrawal fees:": [null, ""], - "Rounding loss:": [null, ""], - "Earliest expiration (for deposit): %1$s": [null, ""], - "# Coins": [null, ""], - Value: [null, ""], - "Withdraw Fee": [null, ""], - "Refresh Fee": [null, ""], - "Deposit Fee": [null, ""], - "": { - "project-id-version": "Taler Wallet", - "report-msgid-bugs-to": "", - "pot-creation-date": "2016-11-23 00:00+0100", - "po-revision-date": "YEAR-MO-DA HO:MI+ZONE", - "last-translator": "FULL NAME ", - "language-team": "LANGUAGE ", - language: "", - "mime-version": "1.0", - "content-type": "text/plain; charset=UTF-8", - "content-transfer-encoding": "8bit", - "plural-forms": "nplurals=2; plural=(n != 1);", + domain: "messages", + locale_data: { + messages: { + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + "Invalid Wire": [""], + "Invalid Test Wire Detail": [""], + "Test Wire Acct #%1$s on %2$s": [""], + "Unknown Wire Detail": [""], + Operation: [""], + "time (ms/op)": [""], + "The merchant %1$s offers you to purchase:": [""], + "The total price is %1$s (plus %2$s fees).": [""], + "The total price is %1$s.": [""], + Retry: [""], + "Confirm payment": [""], + Balance: [""], + History: [""], + Debug: [""], + "You have no balance to show. Need some %1$s getting started?": [""], + "%1$s incoming": [""], + "%1$s being spent": [""], + "Error: could not retrieve balance information.": [""], + "Invalid ": [""], + "Fees ": [""], + "Refresh sessions has completed": [""], + "Order Refused": [""], + "Order redirected": [""], + "Payment aborted": [""], + "Payment Sent": [""], + "Order accepted": [""], + "Reserve balance updated": [""], + "Payment refund": [""], + Withdrawn: [""], + "Tip Accepted": [""], + "Tip Declined": [""], + "%1$s": [""], + "Your wallet has no events recorded.": [""], + "Wire to bank account": [""], + Confirm: [""], + Cancel: [""], + "Could not get details for withdraw operation:": [""], + "Chose different exchange provider": [""], + "Please select an exchange. You can review the details before after your selection.": [ + "", + ], + "Select %1$s": [""], + "Select custom exchange": [""], + "You are about to withdraw %1$s from your bank account into your wallet.": [ + "", + ], + "Accept fees and withdraw": [""], + "Cancel withdraw operation": [""], + "Withdrawal fees:": [""], + "Rounding loss:": [""], + "Earliest expiration (for deposit): %1$s": [""], + "# Coins": [""], + Value: [""], + "Withdraw Fee": [""], + "Refresh Fee": [""], + "Deposit Fee": [""], + }, }, }; strings["it"] = { - "Invalid Wire": [null, ""], - "Invalid Test Wire Detail": [null, ""], - "Test Wire Acct #%1$s on %2$s": [null, ""], - "Unknown Wire Detail": [null, ""], - Operation: [null, ""], - "time (ms/op)": [null, ""], - "The merchant %1$s offers you to purchase:": [null, ""], - "The total price is %1$s (plus %2$s fees).": [null, ""], - "The total price is %1$s.": [null, ""], - Retry: [null, ""], - "Confirm payment": [null, ""], - Balance: [null, ""], - History: [null, ""], - Debug: [null, ""], - "You have no balance to show. Need some %1$s getting started?": [null, ""], - "%1$s incoming": [null, ""], - "%1$s being spent": [null, ""], - "Error: could not retrieve balance information.": [null, ""], - "Invalid ": [null, ""], - "Fees ": [null, ""], - "Refresh sessions has completed": [null, ""], - "Order Refused": [null, ""], - "Order redirected": [null, ""], - "Payment aborted": [null, ""], - "Payment Sent": [null, ""], - "Order accepted": [null, ""], - "Reserve balance updated": [null, ""], - "Payment refund": [null, ""], - Withdrawn: [null, ""], - "Tip Accepted": [null, ""], - "Tip Declined": [null, ""], - "%1$s": [null, ""], - "Your wallet has no events recorded.": [null, ""], - "Wire to bank account": [null, ""], - Confirm: [null, ""], - Cancel: [null, ""], - "Could not get details for withdraw operation:": [null, ""], - "Chose different exchange provider": [null, ""], - "Please select an exchange. You can review the details before after your selection.": [ - null, - "", - ], - "Select %1$s": [null, ""], - "Select custom exchange": [null, ""], - "You are about to withdraw %1$s from your bank account into your wallet.": [ - null, - "", - ], - "Accept fees and withdraw": [null, ""], - "Cancel withdraw operation": [null, ""], - "Withdrawal fees:": [null, ""], - "Rounding loss:": [null, ""], - "Earliest expiration (for deposit): %1$s": [null, ""], - "# Coins": [null, ""], - Value: [null, ""], - "Withdraw Fee": [null, ""], - "Refresh Fee": [null, ""], - "Deposit Fee": [null, ""], - "": { - "project-id-version": "Taler Wallet", - "report-msgid-bugs-to": "", - "pot-creation-date": "2016-11-23 00:00+0100", - "po-revision-date": "YEAR-MO-DA HO:MI+ZONE", - "last-translator": "FULL NAME ", - "language-team": "LANGUAGE ", - language: "", - "mime-version": "1.0", - "content-type": "text/plain; charset=UTF-8", - "content-transfer-encoding": "8bit", - "plural-forms": "nplurals=2; plural=(n != 1);", + domain: "messages", + locale_data: { + messages: { + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + "Invalid Wire": [""], + "Invalid Test Wire Detail": [""], + "Test Wire Acct #%1$s on %2$s": [""], + "Unknown Wire Detail": [""], + Operation: [""], + "time (ms/op)": [""], + "The merchant %1$s offers you to purchase:": [""], + "The total price is %1$s (plus %2$s fees).": [""], + "The total price is %1$s.": [""], + Retry: [""], + "Confirm payment": [""], + Balance: [""], + History: [""], + Debug: [""], + "You have no balance to show. Need some %1$s getting started?": [""], + "%1$s incoming": [""], + "%1$s being spent": [""], + "Error: could not retrieve balance information.": [""], + "Invalid ": [""], + "Fees ": [""], + "Refresh sessions has completed": [""], + "Order Refused": [""], + "Order redirected": [""], + "Payment aborted": [""], + "Payment Sent": [""], + "Order accepted": [""], + "Reserve balance updated": [""], + "Payment refund": [""], + Withdrawn: [""], + "Tip Accepted": [""], + "Tip Declined": [""], + "%1$s": [""], + "Your wallet has no events recorded.": [""], + "Wire to bank account": [""], + Confirm: [""], + Cancel: [""], + "Could not get details for withdraw operation:": [""], + "Chose different exchange provider": [""], + "Please select an exchange. You can review the details before after your selection.": [ + "", + ], + "Select %1$s": [""], + "Select custom exchange": [""], + "You are about to withdraw %1$s from your bank account into your wallet.": [ + "", + ], + "Accept fees and withdraw": [""], + "Cancel withdraw operation": [""], + "Withdrawal fees:": [""], + "Rounding loss:": [""], + "Earliest expiration (for deposit): %1$s": [""], + "# Coins": [""], + Value: [""], + "Withdraw Fee": [""], + "Refresh Fee": [""], + "Deposit Fee": [""], + }, }, }; strings["sv"] = { - "Invalid Wire": [null, ""], - "Invalid Test Wire Detail": [null, ""], - "Test Wire Acct #%1$s on %2$s": [null, ""], - Operation: [null, ""], - "time (ms/op)": [null, ""], - Retry: [null, ""], - "Confirm payment": [null, "Godkän betalning"], - Balance: [null, "Balans"], - History: [null, "Historia"], - Debug: [null, ""], - "%1$s being spent": [null, ""], - "Error: could not retrieve balance information.": [null, ""], - "Invalid ": [null, ""], - "Fees ": [null, ""], - "Refresh sessions has completed": [null, ""], - "Order Refused": [null, ""], - "Order redirected": [null, ""], - "Payment aborted": [null, ""], - "Payment Sent": [null, ""], - "Order accepted": [null, ""], - "Reserve balance updated": [null, ""], - "Payment refund": [null, ""], - "Tip Accepted": [null, ""], - "Tip Declined": [null, ""], - "%1$s": [null, ""], - "Your wallet has no events recorded.": [null, "plånboken"], - "Wire to bank account": [null, "Övervisa till bank konto"], - Confirm: [null, "Bekräfta"], - Cancel: [null, "Avbryt"], - "Could not get details for withdraw operation:": [null, ""], - "Please select an exchange. You can review the details before after your selection.": [ - null, - "", - ], - "Select custom exchange": [null, ""], - "Accept fees and withdraw": [null, "Acceptera avgifter och utbetala"], - "Cancel withdraw operation": [null, ""], - "Withdrawal fees:": [null, "Utbetalnings avgifter:"], - "Rounding loss:": [null, ""], - "Earliest expiration (for deposit): %1$s": [null, ""], - "# Coins": [null, "# Mynt"], - Value: [null, "Värde"], - "Withdraw Fee": [null, "Utbetalnings avgift"], - "Refresh Fee": [null, "Återhämtnings avgift"], - "Deposit Fee": [null, "Depostitions avgift"], - "": { - "project-id-version": "Taler Wallet", - "report-msgid-bugs-to": "", - "pot-creation-date": "2016-11-23 00:00+0100", - "po-revision-date": "YEAR-MO-DA HO:MI+ZONE", - "last-translator": "Flo Reitz ", - "language-team": "LANGUAGE ", - language: "", - "mime-version": "1.0", - "content-type": "text/plain; charset=UTF-8", - "content-transfer-encoding": "8bit", - "plural-forms": "nplurals=2; plural=(n != 1);", + domain: "messages", + locale_data: { + messages: { + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + "Invalid Wire": [""], + "Invalid Test Wire Detail": [""], + "Test Wire Acct #%1$s on %2$s": [""], + "Unknown Wire Detail": ["visa mer"], + Operation: [""], + "time (ms/op)": [""], + "The merchant %1$s offers you to purchase:": [ + "Säljaren %1$s erbjuder följande:", + ], + "The total price is %1$s (plus %2$s fees).": [ + "Det totala priset är %1$s (plus %2$s avgifter).\n", + ], + "The total price is %1$s.": ["Det totala priset är %1$s."], + Retry: [""], + "Confirm payment": ["Godkän betalning"], + Balance: ["Balans"], + History: ["Historia"], + Debug: [""], + "You have no balance to show. Need some %1$s getting started?": [ + "Du har ingen balans att visa. Behöver du\n %1$s att börja?\n", + ], + "%1$s incoming": ["%1$s inkommande"], + "%1$s being spent": [""], + "Error: could not retrieve balance information.": [""], + "Invalid ": [""], + "Fees ": [""], + "Refresh sessions has completed": [""], + "Order Refused": [""], + "Order redirected": [""], + "Payment aborted": [""], + "Payment Sent": [""], + "Order accepted": [""], + "Reserve balance updated": [""], + "Payment refund": [""], + Withdrawn: ["Utbetalnings avgift"], + "Tip Accepted": [""], + "Tip Declined": [""], + "%1$s": [""], + "Your wallet has no events recorded.": ["plånboken"], + "Wire to bank account": ["Övervisa till bank konto"], + Confirm: ["Bekräfta"], + Cancel: ["Avbryt"], + "Could not get details for withdraw operation:": [""], + "Chose different exchange provider": ["Ändra tjänsteleverantörer"], + "Please select an exchange. You can review the details before after your selection.": [ + "", + ], + "Select %1$s": ["Välj %1$s"], + "Select custom exchange": [""], + "You are about to withdraw %1$s from your bank account into your wallet.": [ + "Du är på väg att ta ut\n %1$s från ditt bankkonto till din plånbok.\n", + ], + "Accept fees and withdraw": ["Acceptera avgifter och utbetala"], + "Cancel withdraw operation": [""], + "Withdrawal fees:": ["Utbetalnings avgifter:"], + "Rounding loss:": [""], + "Earliest expiration (for deposit): %1$s": [""], + "# Coins": ["# Mynt"], + Value: ["Värde"], + "Withdraw Fee": ["Utbetalnings avgift"], + "Refresh Fee": ["Återhämtnings avgift"], + "Deposit Fee": ["Depostitions avgift"], + }, }, }; diff --git a/src/webex/i18n-test.tsx b/src/webex/i18n-test.tsx new file mode 100644 index 000000000..4a1c40254 --- /dev/null +++ b/src/webex/i18n-test.tsx @@ -0,0 +1,69 @@ +/* + This file is part of GNU Taler + (C) 2020 Taler Systems SA + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +import test from "ava"; +import { internalSetStrings, str, Translate } from "./i18n"; +import { strings } from "../i18n/strings"; +import React from "react"; +import { render } from "enzyme"; +import { configure } from "enzyme"; +import Adapter from "enzyme-adapter-react-16"; + +configure({ adapter: new Adapter() }); + +const testStrings = { + domain: "messages", + locale_data: { + messages: { + str1: ["foo1"], + str2: [""], + "str3 %1$s / %2$s": ["foo3 %2$s ; %1$s"], + "": { + domain: "messages", + plural_forms: "nplurals=2; plural=(n != 1);", + lang: "", + }, + }, + }, +}; + +test("str translation", (t) => { + // Alias, so we nly use the function for lookups, not for string extranction. + const strAlias = str; + const TranslateAlias = Translate; + internalSetStrings(testStrings); + t.is(strAlias`str1`, "foo1"); + t.is(strAlias`str2`, "str2"); + const a = "a"; + const b = "b"; + t.is(strAlias`str3 ${a} / ${b}`, "foo3 b ; a"); + const r = render(str1); + t.is(r.text(), "foo1"); + + const r2 = render( + + str3 {a} / {b} + , + ); + t.is(r2.text(), "foo3 b ; a"); + + t.pass(); +}); + +test("existing str translation", (t) => { + internalSetStrings(strings); + t.pass(); +}); diff --git a/src/webex/i18n.tsx b/src/webex/i18n.tsx index 4c111a05a..6b5c2318d 100644 --- a/src/webex/i18n.tsx +++ b/src/webex/i18n.tsx @@ -28,7 +28,7 @@ import * as jedLib from "jed"; import * as React from "react"; -const jed = setupJed(); +let jed = setupJed(); const enableTracing = false; @@ -54,6 +54,14 @@ function setupJed(): any { return new jedLib.Jed(strings[lang]); } +/** + * Use different translations for testing. Should not be used outside + * of test cases. + */ +export function internalSetStrings(langStrings: any): void { + jed = new jedLib.Jed(langStrings); +} + /** * Convert template strings to a msgid */ @@ -110,6 +118,37 @@ interface TranslateProps { wrapProps?: any; } +function getTranslatedChildren( + translation: string, + children: React.ReactNode, +): React.ReactNode[] { + const tr = translation.split(/%(\d+)\$s/); + const childArray = React.Children.toArray(children); + // Merge consecutive string children. + const placeholderChildren = []; + for (let i = 0; i < childArray.length; i++) { + const x = childArray[i]; + if (x === undefined) { + continue; + } else if (typeof x === "string") { + continue; + } else { + placeholderChildren.push(x); + } + } + const result = []; + for (let i = 0; i < tr.length; i++) { + if (i % 2 == 0) { + // Text + result.push(tr[i]); + } else { + const childIdx = Number.parseInt(tr[i]) - 1; + result.push(placeholderChildren[childIdx]); + } + } + return result; +} + /** * Translate text node children of this component. * If a child component might produce a text node, it must be wrapped @@ -125,35 +164,8 @@ interface TranslateProps { export class Translate extends React.Component { render(): JSX.Element { const s = stringifyChildren(this.props.children); - const tr = jed - .ngettext(s, s, 1) - .split(/%(\d+)\$s/) - .filter((e: any, i: number) => i % 2 === 0); - const childArray = React.Children.toArray(this.props.children); - for (let i = 0; i < childArray.length - 1; ++i) { - if ( - typeof childArray[i] === "string" && - typeof childArray[i + 1] === "string" - ) { - childArray[i + 1] = (childArray[i] as string).concat( - childArray[i + 1] as string, - ); - childArray.splice(i, 1); - } - } - const result = []; - while (childArray.length > 0) { - const x = childArray.shift(); - if (x === undefined) { - continue; - } - if (typeof x === "string") { - const t = tr.shift(); - result.push(t); - } else { - result.push(x); - } - } + const translation: string = jed.ngettext(s, s, 1); + const result = getTranslatedChildren(translation, this.props.children); if (!this.props.wrap) { return
{result}
; } @@ -216,34 +228,8 @@ export class TranslatePlural extends React.Component< > { render(): JSX.Element { const s = stringifyChildren(this.props.children); - const tr = jed - .ngettext(s, s, 1) - .split(/%(\d+)\$s/) - .filter((e: any, i: number) => i % 2 === 0); - const childArray = React.Children.toArray(this.props.children); - for (let i = 0; i < childArray.length - 1; ++i) { - if ( - typeof childArray[i] === "string" && - typeof childArray[i + 1] === "string" - ) { - childArray[i + i] = ((childArray[i] as string) + - childArray[i + 1]) as string; - childArray.splice(i, 1); - } - } - const result = []; - while (childArray.length > 0) { - const x = childArray.shift(); - if (x === undefined) { - continue; - } - if (typeof x === "string") { - const t = tr.shift(); - result.push(t); - } else { - result.push(x); - } - } + const translation = jed.ngettext(s, s, 1); + const result = getTranslatedChildren(translation, this.props.children); return
{result}
; } } @@ -257,34 +243,8 @@ export class TranslateSingular extends React.Component< > { render(): JSX.Element { const s = stringifyChildren(this.props.children); - const tr = jed - .ngettext(s, s, 1) - .split(/%(\d+)\$s/) - .filter((e: any, i: number) => i % 2 === 0); - const childArray = React.Children.toArray(this.props.children); - for (let i = 0; i < childArray.length - 1; ++i) { - if ( - typeof childArray[i] === "string" && - typeof childArray[i + 1] === "string" - ) { - childArray[i + i] = ((childArray[i] as string) + - childArray[i + 1]) as string; - childArray.splice(i, 1); - } - } - const result = []; - while (childArray.length > 0) { - const x = childArray.shift(); - if (x === undefined) { - continue; - } - if (typeof x === "string") { - const t = tr.shift(); - result.push(t); - } else { - result.push(x); - } - } + const translation = jed.ngettext(s, s, this.props.target); + const result = getTranslatedChildren(translation, this.props.children); return
{result}
; } } -- cgit v1.2.3