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.
2020-09-28 08:51:26 -07:00
|
|
|
import translations from '../data/translations.suml';
|
|
|
|
|
2020-12-08 14:14:40 -08:00
|
|
|
export default (key, params = {}, warn = true) => {
|
2020-09-28 08:51:26 -07:00
|
|
|
let value = translations;
|
|
|
|
for (let part of key.split('.')) {
|
|
|
|
value = value[part];
|
|
|
|
if (value === undefined) {
|
2020-12-08 14:14:40 -08:00
|
|
|
if (warn) {
|
|
|
|
console.error('Cannot find translation: ' + key);
|
|
|
|
}
|
2020-09-28 08:51:26 -07:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:46:39 -07:00
|
|
|
for (let k in params) {
|
|
|
|
if (params.hasOwnProperty(k)) {
|
2020-12-18 02:34:58 -08:00
|
|
|
value = Array.isArray(value)
|
|
|
|
? value.map(v => v.replace(new RegExp('%' + k + '%', 'g'), params[k]))
|
|
|
|
: value.replace(new RegExp('%' + k + '%', 'g'), params[k]);
|
2020-10-14 12:46:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 08:51:26 -07:00
|
|
|
return value;
|
|
|
|
}
|