i18n
This commit is contained in:
parent
c21b7adc0a
commit
835efda6e3
@ -28,19 +28,7 @@ function init () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var i18n = <any>function i18n(strings, ...values) {
|
function getI18nString (strings) {
|
||||||
init();
|
|
||||||
console.log('i18n:', strings[0]);
|
|
||||||
return jed.translate(strings[0]).fetch();
|
|
||||||
};
|
|
||||||
|
|
||||||
i18n.lang = chrome.i18n.getUILanguage();
|
|
||||||
i18n.strings = {};
|
|
||||||
|
|
||||||
// Interpolate i8nized values with arbitrary objects and
|
|
||||||
// return array of strings/objects.
|
|
||||||
i18n.parts = function(strings, ...values) {
|
|
||||||
init();
|
|
||||||
let str = '';
|
let str = '';
|
||||||
for (let i = 0; i < strings.length; i++) {
|
for (let i = 0; i < strings.length; i++) {
|
||||||
str += strings[i];
|
str += strings[i];
|
||||||
@ -48,6 +36,38 @@ i18n.parts = function(strings, ...values) {
|
|||||||
str += '%'+ (i+1) +'$s';
|
str += '%'+ (i+1) +'$s';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('i18n.parts:', str, ...values[0].children);
|
return str;
|
||||||
return jed.translate(str).fetch(...values[0].children);
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
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 i18nized values with arbitrary objects and
|
||||||
|
// return array of strings/objects.
|
||||||
|
i18n.parts = function(strings, ...values) {
|
||||||
|
init();
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
@ -116,6 +116,11 @@ namespace WalletBalance {
|
|||||||
let link = m("a[href=https://demo.taler.net]",
|
let link = m("a[href=https://demo.taler.net]",
|
||||||
{config: openInExtension},
|
{config: openInExtension},
|
||||||
i18n`free KUDOS`);
|
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}?`;
|
return i18n.parts`You have no balance to show. Want to get some ${link}?`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,4 +277,3 @@ function openTab(page) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user