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:
@@ -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);
|
||||
|
||||
|
1
src/declarations.d.ts
vendored
1
src/declarations.d.ts
vendored
@@ -1 +0,0 @@
|
||||
declare module 'gettext-parser';
|
Reference in New Issue
Block a user