0.2.0 • Published 2 years ago
@memnrev/dict-loader v0.2.0
dict-loader
Webpack loader for replacing dictionary entries with string literals.
The loader replaces entries of the form dict.dictName.entryKey
in the code with string literals
found in dictionaries.
Usage Example
// webpack.config.js
const path = require('path');
module.exports = {
// ...
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: '@gorsoft/dict-loader',
options: {
dictsFolder: path.resolve(__dirname, './src/dicts'),
currLang: 'en',
},
},
],
},
],
},
};
Creating Dictinaries
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
.