@ts-intl/dictionary
Version:
I18n dictionary/messages generator
30 lines (29 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractDictionaryFs = void 0;
const shared_1 = require("@ts-intl/shared");
const extractDictionary_1 = require("./extractDictionary");
const extractDictionaryFs = ({ localePath, locale, basicLocale, include, exclude, reader = shared_1.readJsonFile, }) => {
const includeTrie = (0, shared_1.buildTrieByNSPath)(include);
const excludeTrie = (exclude === null || exclude === void 0 ? void 0 : exclude.length) ? (0, shared_1.buildTrieByNSPath)(exclude) : undefined;
const [lngDict, fallbackDict] = [locale, basicLocale].map((locale) => initDictionaryFs(localePath, reader, includeTrie, excludeTrie, locale));
return (0, extractDictionary_1.extractDictionary)(lngDict, fallbackDict, includeTrie, excludeTrie);
};
exports.extractDictionaryFs = extractDictionaryFs;
const initDictionaryFs = (localePath, reader, includeTrie, excludeTrie, locale) => {
if (!locale)
return {};
const include = [];
includeTrie.childrenNameMap.forEach((v) => {
var _a;
if (!v.name || ((_a = excludeTrie === null || excludeTrie === void 0 ? void 0 : excludeTrie.get(v.name)) === null || _a === void 0 ? void 0 : _a.isLeaf))
return;
include.push(v.name);
});
const { dictionary } = (0, shared_1.dictionaryResolverFs)(localePath, locale, reader, include);
return include.reduce((res, namespace) => {
var _a;
res[namespace] = (_a = dictionary === null || dictionary === void 0 ? void 0 : dictionary[namespace]) !== null && _a !== void 0 ? _a : {};
return res;
}, {});
};