@openmrs/esm-translations
Version:
O3 Framework module for translation support
26 lines (22 loc) • 863 B
text/typescript
import { coreTranslations } from './src/translations';
export const getCoreTranslation = jest.fn(
(key: string, defaultText?: string, options?: Record<string | number | symbol, unknown>) =>
interpolate(coreTranslations[key] ?? defaultText, options),
);
export const translateFrom = jest.fn(
(moduleName: string, key: string, fallback?: string, options?: Record<string | number | symbol, unknown>) => {
if (moduleName === 'core') {
return interpolate(coreTranslations[key] ?? fallback, options);
} else {
return interpolate(key ?? fallback, options);
}
},
);
function interpolate(stringValue: string, options?: Record<string | number | symbol, unknown>) {
if (options) {
Object.keys(options).forEach((key) => {
stringValue = stringValue.replace(`{{${key}}}`, '' + options[key]);
});
}
return stringValue;
}