From 60d47931112cb98e3efb644bdf57dbb1bee0659e Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 2 Dec 2016 16:12:24 -0800 Subject: [PATCH] Adds a variable to the possible translations. --- client/coral-framework/modules/i18n/i18n.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/coral-framework/modules/i18n/i18n.js b/client/coral-framework/modules/i18n/i18n.js index afe8606d1..a4a22f5b8 100644 --- a/client/coral-framework/modules/i18n/i18n.js +++ b/client/coral-framework/modules/i18n/i18n.js @@ -46,9 +46,11 @@ class i18n { * it takes a string with the translation key and returns * the translation value or the key itself if not found * it works with nested translations (my.page.title) + * + * the second parameter is optional and replaces a variable marked by {0} in the translation. */ - this.t = (key) => { + this.t = (key, att) => { const arr = key.split('.'); let translation = this.translations; try { @@ -58,8 +60,9 @@ class i18n { return key; } - const val = String(translation); + let val = String(translation); if (val) { + val = val.replace('/\{0\/g', att); return val; } else { console.warn(`${key} language key not set`);