Tests about support of HTML tags in translations keys with GetText (#172)

- Verify that html tags are supported in translation keys
- Add typed support of gettext-parser
This commit is contained in:
Lorent Lempereur
2020-04-01 12:19:30 +02:00
committed by GitHub
parent 73f39d625c
commit 71f4f42b33
8 changed files with 63 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
import { CompilerInterface } from './compiler.interface';
import { TranslationCollection, TranslationType } from '../utils/translation.collection';
import * as gettext from 'gettext-parser';
import { po } from 'gettext-parser';
export class PoCompiler implements CompilerInterface {
public extension: string = 'po';
@@ -34,23 +34,24 @@ export class PoCompiler implements CompilerInterface {
}
};
return gettext.po.compile(data);
return po.compile(data).toString('utf8');
}
public parse(contents: string): TranslationCollection {
const collection = new TranslationCollection();
const po = gettext.po.parse(contents, 'utf8');
if (!po.translations.hasOwnProperty(this.domain)) {
const parsedPo = po.parse(contents, 'utf8');
if (!parsedPo.translations.hasOwnProperty(this.domain)) {
return collection;
}
const values = Object.keys(po.translations[this.domain])
const values = Object.keys(parsedPo.translations[this.domain])
.filter((key) => key.length > 0)
.reduce((result, key) => {
return {
...result,
[key]: po.translations[this.domain][key].msgstr.pop()
[key]: parsedPo.translations[this.domain][key].msgstr.pop()
};
}, {} as TranslationType);

View File

@@ -1 +0,0 @@
declare module 'gettext-parser';