@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
103 lines • 3.46 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var convertContentDeclarationInto18nDictionaries_exports = {};
__export(convertContentDeclarationInto18nDictionaries_exports, {
createI18nextDictionaries: () => createI18nextDictionaries
});
module.exports = __toCommonJS(convertContentDeclarationInto18nDictionaries_exports);
var import_config = require("@intlayer/config");
var import_core = require("@intlayer/core");
var import_convertPluralsValues = require('./convertPluralsValues.cjs');
const isReactNode = (node) => typeof node?.key !== "undefined" && typeof node?.props !== "undefined" && typeof node?.type !== "undefined";
const buildDictionary = (content, locale) => {
if (
// Translation node
content && content.nodeType === import_core.NodeType.Translation
) {
const contentState = content[import_core.NodeType.Translation];
const result = contentState[locale];
return buildDictionary(result, locale);
} else if (
// Translation node
content && content.nodeType === import_core.NodeType.Enumeration
) {
const plurals = {};
Object.keys(
content[import_core.NodeType.Enumeration]
).forEach((quantity) => {
const letterNumber = (0, import_convertPluralsValues.convertPluralsValues)(quantity);
const value = content[quantity];
plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(
value,
locale
);
});
return plurals;
} else if (
// React element node
isReactNode(content)
) {
return JSON.stringify(content);
} else if (
// Nested object
typeof content === "object" && Array.isArray(content)
) {
const result = [];
Object.keys(content).forEach((dictionaryValue) => {
result.push(
buildDictionary(
content[dictionaryValue],
locale
)
);
});
return result;
} else if (
// Nested object
typeof content === "object"
) {
const result = {};
Object.keys(content).forEach(
(dictionaryValue) => {
result[dictionaryValue] = buildDictionary(
content?.[dictionaryValue],
locale
);
}
);
return result;
}
return content;
};
const createI18nextDictionaries = (content, configuration = (0, import_config.getConfiguration)()) => {
const { locales } = configuration.internationalization;
const result = locales.reduce(
(acc, locale) => ({
...acc,
[locale]: buildDictionary(content, locale)
}),
{}
);
return result;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createI18nextDictionaries
});
//# sourceMappingURL=convertContentDeclarationInto18nDictionaries.cjs.map