addon/.support/utils/translation.ts

31 lines
941 B
TypeScript
Raw Normal View History

import { TolgeeKey } from '../types';
export const normalize = (translation: string | null | undefined) => {
if (translation == null) {
return '';
}
return translation.replace(/\n/g, '\\n').replace(/"/g, "'");
};
export const writeMaleTranslation = (value: TolgeeKey['translations']) => {
let text = '';
const normalizedValue = normalize(value?.['cs']?.text);
if (normalizedValue != '') {
text += '\tm = "' + normalizedValue + '", \n';
}
return text;
};
export const writeAlsoFemaleTranslation = (value: TolgeeKey['translations']) => {
let text = '';
const normalizedMaleValue = normalize(value?.['cs']?.text);
const normalizedFemaleValue = normalize(value?.['csf']?.text);
if (normalizedMaleValue != '') {
text += '\tm = "' + normalizedMaleValue + '", \n';
}
if (normalizedFemaleValue != '' && normalizedMaleValue != normalizedFemaleValue) {
text += '\tf = "' + normalizedFemaleValue + '", \n';
}
return text;
};