Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should extract 1 singular/plural string with context', () => {
transform(
'',
OPTIONS
)
const po = poParser.parse(fs.readFileSync(TESTPO))
assertHasPluralContextEntry(po, '1 flag', 'Many flags', 'Object')
assertNumberOfEntries(po, 1)
})
it('should extract 1 singular/plural string ', () => {
transform("_n('One', 'Many', 5)", OPTIONS)
const po = poParser.parse(fs.readFileSync(TESTPO))
assertHasPluralEntry(po, 'One', 'Many')
assertNumberOfEntries(po, 1)
})
it('should extract comments', () => {
transform(
'', OPTIONS)
const po = poParser.parse(fs.readFileSync(TESTPO))
expect(po.translations['']['Hey there!'].comments.extracted).toBe('On Homepage')
assertNumberOfEntries(po, 1)
})
})
it('should extract from shortform call expression', () => {
transform("", OPTIONS)
const po = poParser.parse(fs.readFileSync(TESTPO))
assertHasSingularEntry(po, 'Hey {name}!')
assertNumberOfEntries(po, 1)
})
name: 'msgc',
singular: 1,
context: 2,
}, {
type: 'PLURAL_CONTEXT',
name: 'msgpc',
singular: 1,
plural: 2,
context: 4,
},
],
}],
],
}
)
const po = poParser.parse(fs.readFileSync(TESTPO))
assertHasSingularEntry(po, 'Hello')
assertHasSingularContextEntry(po, 'Block', 'Lego')
assertHasPluralEntry(po, '1 person', '{x} people')
assertHasPluralContextEntry(po, 'One', 'Many', 'People')
assertNumberOfEntries(po, 4)
})
})
const readPoMessages = (path) => {
const file = readFileSync(path)
return po.parse(file)
}
function addTextLocale(locale, body, options = {}) {
const gt = new Gettext();
const domain = 'messages';
const { filter, gettextDefaultCharset = 'UTF-8' } = options;
if (body.length > 0) {
gt.addTranslations(locale, domain, po.parse(body, gettextDefaultCharset));
}
if (filter) {
const filterAsync = Promise.promisify(filter);
return filterAsync(gt, locale);
}
return Promise.resolve(
gt.catalogs[locale] && gt.catalogs[locale][domain].translations,
);
}
update_translations: () => {
process.stdout.write(common.messageStart('Updating translations'));
const start_time = Date.now();
const messages_file = Path.join(common.root_path, translations_dir, 'messages.pot');
const content = fs.readFileSync(messages_file, 'utf8');
const parsed = po.parse(content);
const old_strings = Object.keys(parsed.translations['']).filter(s => s);
const old_count = old_strings.length;
const new_strings = [];
parsed.translations[''] = {};
source_strings.sort().forEach(entry => {
const idx = old_strings.indexOf(entry);
if (idx === -1) {
new_strings.push(entry);
} else {
old_strings.splice(idx, 1);
}
parsed.translations[''][entry] = {
msgid : entry,
msgstr: [''],
};