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

21 lines
518 B
JavaScript
Raw Normal View History

import translations from '../data/translations.suml';
2020-10-14 12:46:39 -07:00
export default (key, params = {}) => {
let value = translations;
for (let part of key.split('.')) {
value = value[part];
if (value === undefined) {
console.error('Cannot find translation: ' + key);
return undefined;
}
}
2020-10-14 12:46:39 -07:00
for (let k in params) {
if (params.hasOwnProperty(k)) {
value = value.replace(new RegExp('%' + k + '%', 'g'), params[k])
}
}
return value;
}