@bestcodetools/translation-cli

1.1.2 • Public • Published

@bestcodetools/translation-cli

A CLI tool for managing translation files in JSON format.

Installation

To install the translation-cli globally, run the following command:

npm install -g @bestcodetools/translation-cli

If you're developing the project locally, you can link it with the following steps:

  1. Open the project folder in the shell/command prompt
  2. Run the following command:
npm link

Usage

To use the translation-cli, open your shell/command prompt and run the following command:

Set Translation

@bestcodetools/translation-cli set filename.json your.key.goes.here "your translation"

Get Translation

@bestcodetools/translation-cli get filename.json your.key.goes.here

Find Keys

@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.

You can also use various aliases instead of @bestcodetools/translation-cli for convenience:

  • 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.

Direct commands usage

  • 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

Configuration file

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.

Package Sidebar

Install

npm i @bestcodetools/translation-cli

Weekly Downloads

4

Version

1.1.2

License

ISC

Unpacked Size

20.5 kB

Total Files

14

Last publish

Collaborators

  • kamikai