Files
geg-gas-web/src/locales/bpmn/customTranslate.ts

20 lines
555 B
TypeScript
Raw Normal View History

2024-02-05 09:15:37 +08:00
export default function customTranslate(translations) {
return function (template, replacements) {
replacements = replacements || {};
// Translate
template = translations[template] || template;
// Replace
return template.replace(/{([^}]+)}/g, function (_, key) {
let str = replacements[key];
if (
translations[replacements[key]] !== null &&
translations[replacements[key]] !== undefined
) {
str = translations[replacements[key]];
}
return str || '{' + key + '}';
});
};
}