在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):oliviertassinari/i18n-extract开源软件地址(OpenSource Url):https://github.com/oliviertassinari/i18n-extract开源编程语言(OpenSource Language):JavaScript 99.7%开源软件介绍(OpenSource Introduction):i18n-extract
Installationnpm install --save-dev i18n-extract The problem solvedThis module analyses code statically for key usages, such as
E.g. This module works well in conjunction with:
Supported keys
i18n('key.static')
i18n('key.' + 'concat')
i18n(`key.template`)
i18n(`key.${dynamic}`)
/* i18n-extract key.comment */ APIextractFromCode(code, [options])Parse the
Exampleimport {extractFromCode} from 'i18n-extract';
const keys = extractFromCode("const followMe = i18n('b2b.follow');", {
marker: 'i18n',
});
// keys = ['b2b.follow'] extractFromFiles(files, [options])Parse the
Exampleimport {extractFromFiles} from 'i18n-extract';
const keys = extractFromFiles([
'*.jsx',
'*.js',
], {
marker: 'i18n',
}); Options
findMissing(locale, keysUsed)Report the missing keys. Those keys should probably be translated.
Exampleimport {findMissing} from 'i18n-extract';
const missing = findMissing({
key1: 'key 1',
}, ['key1', 'key2']);
/**
* missing = [{
* type: 'MISSING',
* key: 'key2',
* }];
*/ PluginsfindUnused(locale, keysUsed)Report the unused key. Those keys should probably be removed.
Exampleimport {findUnused} from 'i18n-extract';
const unused = findUnused({
key1: 'key 1',
key2: 'key 2',
}, ['key1']);
/**
* unused = [{
* type: 'UNUSED',
* key: 'key2',
* }];
*/ findDuplicated(locale, keysUsed, options)Report the duplicated key. Those keys should probably be mutualized.
The default
Exampleimport {findDuplicated} from 'i18n-extract';
const duplicated = findDuplicated({
key1: 'Key 1',
key2: 'Key 2',
key3: 'Key 2',
});
/**
* unused = [{
* type: 'DUPLICATED',
* keys: [
* 'key2',
* 'key3',
* ],
* value: 'Key 2',
* }];
*/ forbidDynamic(locale, keysUsed)Report any dynamic key. It's arguably more dangerous to use dynamic key. They may break.
Exampleimport {forbidDynamic} from 'i18n-extract';
const forbidDynamic = forbidDynamic({}, ['key.*']);
/**
* forbidDynamic = [{
* type: 'FORBID_DYNAMIC',
* key: 'key.*',
* }];
*/ flatten(object)Flatten the object.
Exampleimport {flatten} from 'i18n-extract';
const flattened = flatten({
key2: 'Key 2',
key4: {
key41: 'Key 4.1',
key42: {
key421: 'Key 4.2.1',
},
},
});
/**
* flattened = {
* key2: 'Key 2',
* 'key4.key41': 'Key 4.1',
* 'key4.key42.key421': 'Key 4.2.1',
* };
*/ mergeMessagesWithPO(messages, poInput, poOutput)Output a new po file with only the messages present in
Exampleimport {mergeMessagesWithPO} from 'i18n-extract';
const messages = ['Message 1', 'Message 2'];
mergeMessagesWithPO(messages, 'messages.po', 'messages.output.po');
/**
* Will output :
* > messages.output.po has 812 messages.
* > We have added 7 messages.
* > We have removed 3 messages.
*/ LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论