@peassoft/dict-builder
v0.1.0
Published
Utility for building i18n dictionaries
Readme
@peasoft/dict-builder
Utility for building dictionaries object from dictionary text files.
Usage Example
import path from 'node:path';
import { dictBuilder, type DictBuilderOptions } from '@oeasoft/dict-builder';
type Dictionary = Record<string, Record<string, string>>;
const dictBuilderOptions: DictBuilderOptions = {
srcDir: path.resolve(import.meta.dirname, './path/to/dicts'),
lang: 'en;,
};
const englishDictionary: Dictionary = dictBuilder(dictBuilderOptions);Creating Dictionaries
Create text files in a folder. File names (without extension) will become dictionary names.
E.g., file global.txt:
[heading]
en: Hello, World!
ru: Привет!
[subHeading]
en: This is sub-heading.
ru: Это подзаголовок.Text withing square brackets will become an entry key.
Use a dictionary entry in your code like this: dict.global.heading, dict.global.subHeading.
