Skip to content

TooPick/TolgeeImportExportTool

Repository files navigation

Tolgee Import Export Tool

An Import/Export tool to synchronize json translation files from an i18n folder to Tolgee database.

With this tool Tolgee translations are always up to date with files used in development.

This tool is composed of two scripts :

  • import-translations.js : This script get zipped Tolgee translations and extract it in the folder provided in parameter.

  • export-translations.js : This script take all translation files in a folder (en.json, fr.json, it.json, ...) and connect to Tolgee to update the database. It update translations, remove keys that are not anymore in json files and add new translations.

Both scripts support single and multiple Tolgee projects. Indeed, the app where I use Tolgee is an angular app with multiple modules. Each one has an subfolder in the i18n translation folder.

For example for 2 modules "admin" and "app":

assets/
    i18n/
        admin/
	        en.json
	        fr.json
	    app/
	        en.json
	        fr.json

I use this architecture to lazy load translations (load only when the module is used) and it also provides a good organization for all translations. For each of these modules I have created a Tolgee project. With that each module is still independant and I can import/export only the part I need.

How to use

Need npm and node.

Install dependencies

npm install

Common configuration

These are options that are shared by both import and export scripts.

Options:
		-v, --version           output the version number
		-u, --url <value>       api url (default: "https://app.tolgee.io/")
		-k, --apiKey <value>    api key
		-m, --multiple <value>  conf file for multiple projects
		-h, --help              display help for command

Option Details

-k, --apiKey Required option. Here you have to provide the REST Api Key generated by Tolgee (see Tolgee documentation for more informations).

-u, --url Allow to use the script with self-hosted Tolgee, you just have to provide the url (example: -u http://localhost:8085/).

-m, --multiple This option is used only is you have the subfolder structure and the multiple Tolgee project architecture I decribed previously. For this you have to provide a conf file (example -m ./conf.json).

The conf file needs to be like this :

{
  "<sub_folder_name_1>": "<sub_folder_name_1_tolgee_project_rest_api_key>",
  "<sub_folder_name_2>": "<sub_folder_name_2_tolgee_project_rest_api_key>",
  ...
}

Example for my described architecture :

{
  "admin": "admin_tolgee_project_rest_api_key",
  "app": "app_tolgee_project_rest_api_key"
}

For the import script it will create an sub folder in the output for each key (here "admin" and "app"), and will extract the corresponding project in there.

For the export script it will scan the input folder and match the subfolder name with the key in conf (here "admin" and "app", it need to match exactly). Next it scan translation files and merge translations with Tolgee database.

Import script options and use

To use the import script you have to run node ./import-translations.js

By default the script will create a translations/ folder next to the script but you can use the following option to set the folder you want. -o, --output <value> translations output dir (default: "translations")

Example : node ./import-translations.js -o ../my-custom-folder/here

Export script options and use

To use the export script you have to run node ./export-translations.js

By default the script will import all translations from a translations/ folder next to the script but you can use the following option to set the folder you want. -i, --input <value> translations input dir (default: "translations")

Example : node ./export-translations.js -i ../my-custom-folder/here

About

An Import/Export tool to synchronize translation files from an app to Tolgee database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published