Lang files packer/unpacker
npm install lang-packerpacking) and then parse it back for separate small files (and this is unpacking).
npm i lang-packer - for in project use (as a library)
npm i lang-packer -g - to install it globaly and use from command line
LangPacker class from lang-packer module.
input folder path - string - the folder in which LangPacker should search for language files. The base language folder should be the .lang folder. All files with .json extension will be extracted as a language files. See below for example of correct folder structure.
output folder path - string - the folder for resulting language files.
options - object - available options:
prefix - output lang file name prefix. Default is "".
postfix - output lang file name postfix. Default is ""
extension - output lang file name extension. Default is .lng;
[prefix][postfix][extension]
{
"prefix": "test",
"postfix": "file",
"extension": ".lng"
}
`
the output lang files will be look like this:
`
test0000file.lng
test0413file.lng
test0123file.lng
`
$3
`
- /src/
- /classes/
- /.lang/
- en-EN.json
- ru-RU.json
- /components/
- /.lang/
- /componentA/
- en-EN.json
- ru-RU.json
- /lang/
- ...
- /languages/
- ...
`
LangPacker will collect all .json files from /src/classes/.lang and /src/components/.lang (include subdirectories), but no /lang and /languages folders.
The language file's name should be in the format:
Examples:
`
en-EN.json
nl-NL.json
es-US.json
`
The full list of available tags can be found here
$3
`
const { LangPacker } = require("lang-packer");
const packer = new LangPacker("./src/", "./lang-out/", {
"prefix": "test",
"postfix": "file",
"extension": ".lng"
});
packer.do();
`
$3
If you install lang-packer module globaly you can run packlng command from it.
packlng command supports the following options:
-i - input folder path;
-o - output folder path;
-pr - prefix option;
-po - postfix option;
-e - extension option.
Also you can use packlng -h command to see the full list of available options;
Example call: packlng -i "./src/" -o "./lng-out" -e ".lng" -pr "language"
It will collect all lang files from ./src/ folder (relative to the current folder) and place it to ./lng-out/ folder (also relative). If outout folder does not exist the packer will create it.
Unpacking
For this purpose we should use a LangUnpacker class from lang-packer module.
The constructor takes three parameters:
- input folder path - string - the folder containing lang files, generated by LangPacker.
- output folder path - string - the folder into which LangUnpacker will parse the language files. Usually this is the same folder from which LangPacker collected these files. (./src/ in out example)
- options - object - available options:
- prefix - output lang file name prefix. Default is "".
- postfix - output lang file name postfix. Default is ""
- extension - output lang file name extension. Default is .lng;
- index - whether to generate index.js file
This options should be relevant to previously generated lang files. Another words they should be equal with options, that was passed to LangPacker for henerating this lang files.
$3
LangUnpacker will parse each lang file from input folder and create a set of language files. The result language files structure will be the same as structure, from which it was packed.
It means that all languages files will rewriten source language files if LangPacker input folder will be the same as LangUnpacker output folder.
$3
`
const { LangUnpacker } = require("lang-packer");
const packer = new LangPacker("./lang-out/", "./src/", {
"prefix": "test",
"postfix": "file",
"extension": ".lng"
});
packer.do();
`
This example assumes that we are running it in the same folder as the example for LangPacker
$3
If you install lang-packer module globaly you can run unpacklng command from it.
packlng command supports the following options:
-i - input folder path;
-o - output folder path;
-pr - prefix option;
-po - postfix option;
-e - extension option.
-in - should generate index.js file in each .lang folder
-s - should file parser skip empty values in result output files
Also you can use unpacklng -h command to see the full list of available options;
Example call: unpacklng -o "./src/" -i "./lng-out" -e ".lng" -pr "language" -in
It will parse all lang files from ./lng-out/ folder (relative to the current folder) and place it to ./src/ folder acording to elemnt's paths. If output folders does not exist the unpacker` will create them.