--- tags: '@badging/i18n' --- Integrate Locize API ===================== The Locize API enables you to integrate your project using the Command Line. The locize Command Line enables you to add new segments or complete files. - Source: https://docs.locize.com/integration/api locize cli can be used to import / export locales, add / edit / remove sync segments. **How to Install the Locize CLI** Before Installing the locize CLI, make sure `NMP` is installed. If `NPM` isn't installed follow the process [here](https://www.npmjs.com/get-npm) to install it. - Create the folder for your project. ```shell= On your terminal type in these commands; mkdir locize-cli cd locize-cli npm init ``` - Install the Cli ```shell= npm install locize-cli ``` *Locize will be implemented using **NPX**, NPX is a tht can be used to run a locally installed package easily. It is also a CLI tool whose purpose is to make it easy to install and manage dependencies hosted in the npm registry.* - Print the Locize Cli ```shell= npx locize -h OUTPUT: Usage: locize [options] [command] Options: -V, --version output the version number -a, --add-path <url> Specify the add-path url that should be used (default: https://api.locize.app/update/{{projectId}}/{{version}}/{{lng}}/{{ns}}) -h, --help display help for command Commands: migrate|m [options] migration of existing translation files add|a [options] <namespace> <key> <value> add a new key remove|rm [options] <namespace> <key> remove a key download|dl [options] download namespaces get|g [options] <namespace> <key> get a key sync|s [options] synchronizes locize with your repository (or any other local directory) save-missing|sm [options] saves missing keys to locize from your repository (or any other local directory) copy-version|cv [options] <fromVersion> copy version publish-version|pv [options] publish version delete-namespace|dn [options] <namespace> delete a namespace format|ft [options] [fileOrDirectory] format local files help [command] display help for command ``` - Print the `download` command usage ```shell= npx locize dl -h OUTPUT: Usage: locize download|dl [options] download namespaces Options: -i, --project-id <projectId> The project-id that should be used -v, --ver <version> The version that should be targeted (default: latest) -l, --language <lng> The language that should be targeted -n, --namespace <ns> The namespace that should be targeted -p, --path <path> Specify the path that should be used (default: /home/thecraftman/myproject) (default: "/home/thecraftman/myproject") -g, --get-path <url> Specify the get-path url that should be used (default: https://api.locize.app/{{projectId}}/{{version}}/{{lng}}/{{ns}}) -k, --api-key <apiKey> The api-key that should be used -f, --format <json> File format of namespaces (default: json; [flat, xliff2, xliff12, xlf2, xlf12, android, yaml, yaml-rails, yaml-nested, csv, xlsx, po, strings, resx, fluent, tmx, laravel, properties]) (default: "json") -s, --skip-empty <true|false> Skips to download empty files (default: true) (default: "true") -P, --language-folder-prefix <prefix> This will be added as a local folder name prefix in front of the language. (default: "") -m, --path-mask <mask> This will define the folder and file structure; do not add a file extension (default: {{language}}/{{namespace}}) (default: "{{language}}/{{namespace}}") -c, --clean <true|false> Removes all local files by removing the whole folder (default: false) (default: "false") -C, --config-path <configPath> Specify the path to the optional locize config file (default: /home/thecraftman/myproject/.locize or /home/thecraftman/.locize) -h, --help display help for command Examples: $ locize download $ locize download --ver latest $ locize download --project-id <projectId> --ver latest --language en --namespace common $ locize download --project-id <projectId> --ver latest --language en --namespace common --format flat ``` The locize download command shortcuts can be used for typing the locize commands in the Command line. - Adding/Updating new keys ```shell= npx locize add -k (paste your api key here) -i (paste your project Id here) -l en namespace1 myNewKey "My new value" ``` - Download Locize Project ```shell= npx locize dl -p ./translation -k (api key) -i (project id) ``` - Add a new key and value ```shell= Enter the add command to see the right method to add the key and value using (npx locize add -h). ``` - Use the add command ```shell= npx locize add -k (api key here) -i (project id here) -l de translation "(key here)" "(value here)" ``` - Download the key and value you just added using the download command ```shell= npx locize dl -p ./translation -k (api key) -i (project id) ``` - Synchronize locize with your repository ```shell= npx locize sync -k (api key here) -i (project id here) ``` #### Confirm changes on your Locize Webpage.