A CLI tool for managing translation files in JSON format.
To install the translation-cli globally, run the following command:
npm install -g @bestcodetools/translation-cli
- Open the project folder in the shell/command prompt
- Run the following command:
npm link
To use the translation-cli, open your shell/command prompt and run the following command:
@bestcodetools/translation-cli set filename.json your.key.goes.here "your translation"
@bestcodetools/translation-cli get filename.json your.key.goes.here
@bestcodetools/translation-cli findKeys filename.json "search term" [options]
This command searches for keys that match the provided "search term" in the specified JSON file.
If filename is '*', it searches in all files within the locale directory.
- Options:
- --set-command: Generates a set command for each found key.
- --set-command-all: Generates set commands for each found key in all files within the locale directory.
- --with-values: Includes key-value pairs in the output.
For example, to generate set commands for each found key:
@bestcodetools/translation-cli findKeys filename.json "search term" --set-command
To generate set commands for each found key in all files within the locale directory:
@bestcodetools/translation-cli findKeys filename.json "search term" --set-command-all
To include key-value pairs in the output:
@bestcodetools/translation-cli findKeys filename.json "search term" --with-values
These options provide flexibility in how you interact with the keys found during the search process.
- jt: short for json-translation
- tj: short for translate-json
- ntc: short for node-translation-cli
NOTE: The set and get commands have corresponding direct commands, such as set-translation and get-translation.
- set-translation usage example:
set-translation filename.json your.key.goes.here "your translation"
- get-translation usage example:
get-translation filename.json your.key.goes.here
The translation-cli supports a configuration file for setting default options. By default, the CLI looks for a configuration file named .translation-cli.config.json
in the current directory. You can specify a different configuration file using the --config-file
option.
The configuration file should be in JSON format and may include the following options:
{
"extension": ".json",
"localeDir": "."
}
- extension: The file extension for the translation files.
- localeDir: The directory where the translation files are located.
Additionally, you can use the init
command to initialize a default configuration file with custom options. For example:
@bestcodetools/translation-cli init --locale-dir=my/translations/directory --extension=.txt
This command initializes a default configuration file named .translation-cli.config.json
with the specified localeDir
and extension
options. If no options are provided, the command will use the default values.
Please note that the configuration file is used to set default options and can be useful for streamlining your workflow when using the translation-cli.
NOTE: if you use --config-file= option this file will be generated instead.