@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
55 lines (53 loc) • 1.98 kB
JavaScript
import { i18nextToIntlayerFormatter, icuToIntlayerFormatter, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, portableObjectToIntlayerFormatter, vueI18nToIntlayerFormatter } from "@intlayer/core/messageFormat";
//#region src/formatDictionary.ts
const formatDictionary = (dictionary) => {
if (dictionary.format === "icu") return {
...dictionary,
format: "intlayer",
content: icuToIntlayerFormatter(dictionary.content)
};
if (dictionary.format === "i18next") return {
...dictionary,
format: "intlayer",
content: i18nextToIntlayerFormatter(dictionary.content)
};
if (dictionary.format === "vue-i18n") return {
...dictionary,
format: "intlayer",
content: vueI18nToIntlayerFormatter(dictionary.content)
};
if (dictionary.format === "po") return {
...dictionary,
format: "intlayer",
content: portableObjectToIntlayerFormatter(dictionary.content)
};
return dictionary;
};
const formatDictionaries = async (dictionaries) => Promise.all(dictionaries.map(formatDictionary));
const formatDictionaryOutput = (dictionary, format) => {
if (format === "icu") return {
...dictionary,
format: "icu",
content: intlayerToICUFormatter(dictionary.content)
};
if (format === "i18next") return {
...dictionary,
format: "i18next",
content: intlayerToI18nextFormatter(dictionary.content)
};
if (format === "vue-i18n") return {
...dictionary,
format: "vue-i18n",
content: intlayerToVueI18nFormatter(dictionary.content)
};
if (dictionary.format === "po") return {
...dictionary,
format: "po",
content: intlayerToPortableObjectFormatter(dictionary.content)
};
return dictionary;
};
const formatDictionariesOutput = (dictionaries, format) => dictionaries.map((dictionary) => formatDictionaryOutput(dictionary, format));
//#endregion
export { formatDictionaries, formatDictionariesOutput, formatDictionary, formatDictionaryOutput };
//# sourceMappingURL=formatDictionary.mjs.map