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.
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 to install it.
- Create the folder for your project.
On your terminal type in these commands;
mkdir locize-cli
cd locize-cli
npm init
- Install the Cli
npm install locize-cli
Locize will be implemented using NPX, NPX is a NPM package runner 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
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
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
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
npx locize dl -p ./translation -k (api key) -i (project id)
- Add a new key and value
Enter the add command to see the right method to add the key and value using (npx locize add -h).
- Use the add command
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
npx locize dl -p ./translation -k (api key) -i (project id)
- Synchronize locize with your repository
npx locize sync -k (api key here) -i (project id here)
apiVersion: v1
kind: ConfigMap
metadata:
name: locize-config
data:
LOCIZE_SYNC_PATH: "/app/translations"
LOCIZE_FORMAT: "json"
LOCIZE_PATH_MASK: "{{language}}/{{namespace}}"
---
apiVersion: v1
kind: Secret
metadata:
name: locize-secrets
type: Opaque
data:
LOCIZE_API_KEY: "api_key_here"
LOCIZE_PROJECT_ID: "project_id_here"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: locize-app
spec:
replicas: 2
selector:
matchLabels:
app: locize-app
template:
metadata:
labels:
app: locize-app
spec:
initContainers:
- name: locize-sync
image: node:16-alpine
command:
- /bin/sh
- -c
- |
npm install -g locize-cli
npx locize download \
-k $(LOCIZE_API_KEY) \
-i $(LOCIZE_PROJECT_ID) \
-p $(LOCIZE_SYNC_PATH) \
-f $(LOCIZE_FORMAT) \
-m $(LOCIZE_PATH_MASK)
envFrom:
- configMapRef:
name: locize-config
- secretRef:
name: locize-secrets
volumeMounts:
- name: translations
mountPath: /app/translations
containers:
- name: main-app
image: your-app-image:tag
volumeMounts:
- name: translations
mountPath: /app/translations
readOnly: true
env:
- name: NODE_ENV
value: "production"
volumes:
- name: translations
emptyDir: {}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: locize-sync-job
spec:
schedule: "0 */6 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: sync
image: node:16-alpine
command:
- /bin/sh
- -c
- |
npm install -g locize-cli
npx locize sync \
-k $(LOCIZE_API_KEY) \
-i $(LOCIZE_PROJECT_ID) \
-p $(LOCIZE_SYNC_PATH)
envFrom:
- configMapRef:
name: locize-config
- secretRef:
name: locize-secrets
volumeMounts:
- name: translations
mountPath: /app/translations
volumes:
- name: translations
emptyDir: {}
restartPolicy: OnFailure
Deploy your Locize configuration on a DigitalOcean droplet
First, create a new droplet:
Verify all your deployments and apply it:
Storage: The current configuration uses emptyDir volumes, which are temporary. For production, you might want to use persistent volumes:
Monitoring: You can set up monitoring using Prometheus and Grafana: