Lokalise CLI tool

Updated 3 months ago ​by Nick Ustinov

Command line tool that allows easily export and import project files with Lokalise. The tool is built using The Go Programming Language and is being distributed as precompiled binary for different architectures.

Changes

version 0.412 (31 June 2017)

  • fixed support for Project directive in the config file (for the import function).

version 0.411  (1 June 2017)

  • export_sort added to export
  • yaml_include_root added to export

version 0.4  (13 March 2017)

  • replace_breaks supported for import and export
  • bugfixes


Download

Mac OS

lokalise-0.412-darwin-amd64.tgz
lokalise-0.412-darwin-386.tgz

Linux

lokalise-0.412-linux-amd64.tgz
lokalise-0.412-linux-386.tgz
lokalise-0.412-linux-ppc64.tgz

FreeBSD

lokalise-0.412-freebsd-amd64.tgz
lokalise-0.412-freebsd-386.tgz

Windows

lokalise-0.412-windows-amd64.tgz 
lokalise-0.412-windows-386.tgz


Install

Uncompress and put into any binary directory in PATH, for example /usr/local/bin. Then simply run "lokalise" in shell to see a list of global commands. Type "lokalise help command" to see help on specific command.


Usage

Global

COMMANDS:
     list, l    List your projects at Lokalise.
     export, d  Downloads language files.
     import, u  Upload language files.
     help, h    Shows a list of commands or help for one command
GLOBAL OPTIONS:
   --token token  API token is required and can be obtained under your Account page in Lokalise.
   --config file  Load configuration from file. Looks up /etc/lokalise.cfg by default.
   --help, -h     show help
   --version, -v  print the version
   

List projects

Lists your projects.

USAGE:
   lokalise --token TOKEN list

Export from project

Downloads projects files.

USAGE:
   lokalise --token TOKEN export PROJECTID --type TYPE 
OPTIONS:
   --type value              File format (strings, xliff, plist, xml, properties, json, po, php, ini, yml, xls) (single value, required)
   --dest value              Destination directory on local filesystem (/dir)
   --langs value             Languages to include. Don't specify for all languages. (comma separated)
   --use_original 0/1        Use original filenames/formats (0/1)
   --filter value            Filter by 'translated', 'nonfuzzy', 'nonhidden' fields (comma separated)
   --bundle_structure value  .ZIP bundle structure (see docs.lokalise.co for placeholders)
   --webhook_url value       Sends POST['file'] if specified (url)
   --export_all 0/1          Include all platform keys (0/1)
   --ota_plugin_bundle 0/1   Generate plugin for OTA iOS plugin (0/1)
   --export_empty value      How to export empty strings (empty, base, skip)
   --include_comments 0/1    Include comments in exported file (0/1)
   --include_pids value      Other projects ID's, which keys to include in this export (comma separated)
   --tags value              Filter keys by tags (comma separated)
   --yaml_include_root 0/1   Include language ISO code as root key in YAML export (0/1)
   --export_sort value       Key sort order (first_added, last_added, last_updated, a_z, z_a)   
   --replace_breaks 0/1      Replace link breaks with \n (0/1)

Import to project

Uploads local files to a project.

USAGE:
   lokalise --token TOKEN import PROJECTID --file FILE --lang_iso VALUE
OPTIONS:
   --file File          File on local filesystem to import (any of the supported file formats) (required)
   --lang_iso value     Language of the translations being imported (reqired)
   --replace 0/1        Shall existing translations be replaced (0/1)
   --fill_empty 0/1     If values are empty, keys will be copied to values (0/1)
   --distinguish 0/1    Distinguish similar keys in different files (0/1)
   --hidden 0/1         Hide imported keys from contributors (0/1)
   --tags value         Tags list for newly imported keys (comma separated)
   --use_trans_mem 0/1  Use translation memory to fill 100% matches (0/1)
   --replace_breaks 0/1  Replace \n with line breaks (0/1)


Config file

Optionally you may create /etc/lokalise.cfg (or place it anywhere and specify --config option) that contains your API token and (in case you have just one project) a project ID. Example config file:

Token = "a1921f0903b5864b75fafbb1951b7defba49781f"
# Project = "3231527727690217e560f6.73199070"


Docker image

Those using Docker environment may find useful our command line tool packaged as Docker image, in case you need platform independent way to import and export data with Lokalise. See usage examples below.

Export from Lokalise to local directory

API_TOKEN=<your api token>
PROJECT_ID=<project id>
LOCAL_DIR=/tmp
FILE_FORMAT=json
docker run \
     -v ${LOCAL_DIR}:/opt/dest \
     lokalise/lokalise-cli lokalise \
     --token ${API_TOKEN} \
     export ${PROJECT_ID} \
     --type json \
     --dest /opt/dest

Import local file to Lokalise

API_TOKEN=<your api token>
PROJECT_ID=<project id>
LOCAL_FILE=/tmp/en.json
LANG_ISO=en
docker run \
    -v ${LOCAL_FILE}:/opt/src/${LOCAL_FILE} \
    lokalise/lokalise-cli lokalise \
    --token ${API_TOKEN} \
    import ${PROJECT_ID} \
    --file /opt/src/${LOCAL_FILE} \
    --lang_iso ${LANG_ISO}

How did we do