v3 init push
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
export default class Lang {
|
||||
|
||||
constructor({translations = {}, prefix = '', locale = 'en'} = {}) {
|
||||
this.translations = translations;
|
||||
this.prefix = prefix;
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
get(sLangId = '', params = []) {
|
||||
if(sLangId === '') return '';
|
||||
|
||||
const asParams = Array.isArray(params) ? params : [params];
|
||||
|
||||
if(Object.prototype.hasOwnProperty.call(this.translations, sLangId)) {
|
||||
let sText = this.translations[sLangId];
|
||||
asParams.forEach((sParam, iIndex) => {
|
||||
sText = sText.replace('$' + iIndex, sParam);
|
||||
});
|
||||
return sText;
|
||||
}
|
||||
|
||||
console.warn('Missing translation:', sLangId);
|
||||
return sLangId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user