aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-02-23 18:28:12 +0100
committertg(x) <*@tg-x.net>2016-02-23 18:28:12 +0100
commit835efda6e381a32dc7f396d6ede9d7922d652b79 (patch)
treed26a5020f54404f3ba5b38d3feb7682c632eedb0 /extension
parentc21b7adc0a24b4a23afedea43007e66b74be9e67 (diff)
downloadwallet-core-835efda6e381a32dc7f396d6ede9d7922d652b79.tar.xz
i18n
Diffstat (limited to 'extension')
-rw-r--r--extension/lib/i18n.ts44
-rw-r--r--extension/popup/popup.tsx6
2 files changed, 37 insertions, 13 deletions
diff --git a/extension/lib/i18n.ts b/extension/lib/i18n.ts
index 93bf9a622..a722e8322 100644
--- a/extension/lib/i18n.ts
+++ b/extension/lib/i18n.ts
@@ -28,26 +28,46 @@ function init () {
}
}
+function getI18nString (strings) {
+ let str = '';
+ for (let i = 0; i < strings.length; i++) {
+ str += strings[i];
+ if (i < strings.length - 1) {
+ str += '%'+ (i+1) +'$s';
+ }
+ }
+ return str;
+}
+
+function getPluralValue (values) {
+ // use the first number in values to determine plural form
+ for (let i = 0; i < values.length; i++) {
+ if ('number' == typeof values[i]) {
+ return values[i];
+ }
+ }
+ return 1;
+}
+
var i18n = <any>function i18n(strings, ...values) {
init();
- console.log('i18n:', strings[0]);
- return jed.translate(strings[0]).fetch();
+ let str = getI18nString (strings);
+ let n = getPluralValue (values);
+ console.log('i18n:', n, str, strings, values);
+ console.log('i18n:', jed.translate(str).ifPlural(n, str).fetch(...values););
+ return jed.translate(str).ifPlural(n, str).fetch(...values);
};
i18n.lang = chrome.i18n.getUILanguage();
i18n.strings = {};
-// Interpolate i8nized values with arbitrary objects and
+// Interpolate i18nized values with arbitrary objects and
// return array of strings/objects.
i18n.parts = function(strings, ...values) {
init();
- let str = '';
- for (let i = 0; i < strings.length; i++) {
- str += strings[i];
- if (i < strings.length - 1) {
- str += '%'+ (i+1) +'$s';
- }
- }
- console.log('i18n.parts:', str, ...values[0].children);
- return jed.translate(str).fetch(...values[0].children);
+ let str = getI18nString (strings);
+ let n = getPluralValue (values);
+ console.log('i18n.parts:', n, str, values, ...values);
+ console.log('i18n.parts:', jed.translate(str).ifPlural(n, str).fetch(...values));
+ return jed.translate(str).ifPlural(n, str).fetch(...values);
};
diff --git a/extension/popup/popup.tsx b/extension/popup/popup.tsx
index 11f722d4b..a5d271b5c 100644
--- a/extension/popup/popup.tsx
+++ b/extension/popup/popup.tsx
@@ -116,6 +116,11 @@ namespace WalletBalance {
let link = m("a[href=https://demo.taler.net]",
{config: openInExtension},
i18n`free KUDOS`);
+ // i18n test
+ let amount = 5, currency = "EUR", date = new Date(), text = 'demo.taler.net';
+ console.log (i18n`Your balance on ${date} is ${amount} KUDO. Get more at ${text}`);
+ console.log (i18n.parts`Your balance on ${date} is ${amount} KUDO. Get more at ${link}`);
+
return i18n.parts`You have no balance to show. Want to get some ${link}?`;
}
}
@@ -272,4 +277,3 @@ function openTab(page) {
});
}
}
-