i18next-utilities-core
v0.1.4
Published
A collection of utilities that parses i18next resource files, concatenates them, and can generate TypeScript definitions for them.
Downloads
11
Readme
i18next-utilities-core
A collection of utilities that parses i18next resource files, concatenates them, and can generate TypeScript definitions for them.
Methods
parseResourceFiles
Parses i18next resource files for a list of directories and returns an object with the list of files, the concatenated resources, and the bundle for the default locale.
import { parseResourceFiles, I18NextTypedLogger } from 'i18next-utilities-core';
const logger: I18NextTypedLogger = {
info: console.log,
warn: console.warn,
error: console.error,
};
const { files, bundle, defaultBundle } = parseResourceFiles(
{
paths: ['path/to/locales'],
namespaceResolution: 'basename',
defaultNamespace: 'translation',
defaultLocale: 'en-Gb',
},
logger
);
generateResourceTypeDefinition
Generates a TypeScript definition for the default locale bundle.
import { generateResourceTypeDefinition } from 'i18next-utilities-core';
const typeDefinition = generateResourceTypeDefinition(defaultLocaleBundle, {
defaultNamespace: 'translation',
});
generateModuleTypeDefinition
Generates a module definition. This is useful for plugins that might want to generate a virtual module.
import { generateModuleTypeDefinition } from 'i18next-utilities-core';
const moduleDefinition = generateModuleTypeDefinition(
'vite:i18next-typed-loader',
['eb', 'en-GB']
);