customTranslate.ts 478 B

1234567891011121314
  1. // https://github.com/bpmn-io/bpmn-js-examples/blob/master/i18n/app/customTranslate/customTranslate.js
  2. import translations from './translations';
  3. export default function customTranslate(template: string, replacements: Record<string, string>) {
  4. replacements = replacements || {};
  5. // Translate
  6. template = translations[template] || template;
  7. // Replace
  8. return template.replace(/{([^}]+)}/g, function (_, key) {
  9. return replacements[key] || '{' + key + '}';
  10. });
  11. }