This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/src/translator.js

25 lines
700 B
JavaScript

import translations from '../data/translations.suml';
export default (key, params = {}, warn = true) => {
let value = translations;
for (let part of key.split('.')) {
value = value[part];
if (value === undefined) {
if (warn) {
console.error('Cannot find translation: ' + key);
}
return undefined;
}
}
for (let k in params) {
if (params.hasOwnProperty(k)) {
value = Array.isArray(value)
? value.map(v => v.replace(new RegExp('%' + k + '%', 'g'), params[k]))
: value.replace(new RegExp('%' + k + '%', 'g'), params[k]);
}
}
return value;
}