Crowdin CLI verwendet eine Konfigurationsdatei, die eine Beschreibung der zu verwaltenden Ressourcen enthält: Dateien, die in Crowdin hochgeladen werden sollen und die Orte der entsprechenden Übersetzungen.
To use Crowdin CLI, you should first generate your configuration file and then run the tool. By default, Crowdin CLI looks for a configuration file named crowdin.yml (so you don’t have to specify the file name unless it’s different from crowdin.yml).
To create the configuration file run the following command:
$ crowdin init
A valid Crowdin CLI configuration file has the following structure, so please make sure that you fill out all the needed information:
A typical configuration file looks similar to the following:
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"preserve_hierarchy": true
"files": [
{
"source": "/locale/en/folder1/[0-2].txt", #source files filter
"translation": "/locale/%two_letters_code%/folder1/%original_file_name%" #where translations are stored
},
{
"source": "/locale/en/folder2/[0-2].txt",
"translation": "/locale/%two_letters_code%/folder2/%original_file_name%"
}
]
To run the above configuration file and upload source files to Crowdin:
$ crowdin upload sources
Get translations from Crowdin and put them in the right locations:
$ crowdin download
You could load the API Credentials from an environment variable, for example:
"project_id_env": "CROWDIN_PROJECT_ID"
"api_token_env": "CROWDIN_PERSONAL_TOKEN"
"base_path_env": "CROWDIN_BASE_PATH"
"base_url_env": "CROWDIN_BASE_URL"
If mixed, api_token and project_id are prioritized:
"project_id_env": "CROWDIN_PROJECT_ID" # Low priority
"api_token_env": "CROWDIN_PERSONAL_TOKEN" # Low priority
"base_path_env": "CROWDIN_BASE_PATH" # Low priority
"base_url_env": "CROWDIN_BASE_PATH" # Low priority
"project_id": "projectId" # High priority
"api_token": "personal-access-token" # High priority
"base_path": "/project-base-path" # High priority
"base_url": "https://crowdin.com" # High priority
The crowdin.yml file contains a description of the resources to manage and API credentials (project_id, api_token, base_path, base_url). This means that it is unsafe to commit this file into the code repository because the API key would be accessible to other users. Crowdin CLI supports 2 types of configuration files:
If you need to run a command with user-specific credentials (for example upload sources
) then run the following command:
$ crowdin upload sources --identity 'path-to-user-credentials-file'
But if user-specific credentials file residing in $HOME/.crowdin.yml you can simply run:
$ crowdin upload sources
The sample configuration provided above has source and translation attributes containing standard wildcards (also known as globbing patterns) to make it easier to work with multiple files.
Here are patterns you can use:
* (asterisk)
Represents any character in file or directory name. If you specify a “*.json” it will include all files like “messages.json”, “about_us.json” and anything that ends with “.json”.
** (doubled asterisk)
Matches any string recursively (including sub-directories). Note that you can use ** in both source and translation patterns. When using ** in the translation pattern, it will always contain sub-path from source for a certain file. For example, you can use source: ‘/en/**/*.po’ to upload all *.po files to Crowdin recursively. The translation pattern will be ‘/%two_letters_code%/**/%original_file_name%’.
? (question mark)
Matches any single character.
[set]
Matches any single character in a set. Behaves exactly like character sets in Regexp, including set negation ([^a-z]).
\ (backslash)
Escapes the next metacharacter.
Crowdin CLI allows to use the following placeholders to put appropriate variables into the resulting file name:
Name | Beschreibung |
---|---|
%language% | Language name (e.g., Ukrainian) |
%two_letters_code% | Language code ISO 639-1 (e.g., uk) |
%three_letters_code% | Language code ISO 639-2/T (e.g., ukr) |
%locale% | Locale (e.g., uk-UA) |
%locale_with_underscore% | Locale (e.g., uk_UA) |
%original_file_name% | Ursprünglicher Dateiname |
%android_code% | Android-Standort-ID für die Benennung von „values-“-Ordnern |
%osx_code% | OS-X-Standort-ID für die Benennung von „lproj“-Ordnern |
%original_path% | Verwendet die Namen der übergeordneten Ordner in Ihrem Projekt, um den Dateipfad im späteren Archiv zu bilden |
%file_extension% | Ursprüngliche Dateierweiterung |
%file_name% | Dateiname ohne Erweiterung |
You can also define the path for files in the resulting archive by putting a slash (/) at the beginning of the pattern.
Your translation
option may look like: “/locale/%two_letters_code%/LC_MESSAGES/%original_file_name%”.
Structure of files and directories on the local machine:
- base_path | |-- folder | | | |-- 1.xml | |-- 1.txt | |-- 123.txt | |-- 123_test.txt | |-- a.txt | |-- a1.txt | |-- crowdin?test.txt | |-- crowdin_test.txt | |-- 1.xml |-- 1.txt |-- 123.txt |-- 123_test.txt |-- a.txt |-- a1.txt |-- crowdin?test.txt |-- crowdin_test.txt |-- 3.txt
Example 1. Usage of wildcards in the source path:
#........your project configuration........
"files": [
{
"source": "/**/?[0-9].txt", #upload a1.txt, folder/a1.txt
"translation": "/**/%two_letters_code%_%original_file_name%"
},
{
"source": "/**/*\\?*.txt", #upload crowdin?test.txt, folder/crowdin?test.txt
"translation": "/**/%two_letters_code%_%original_file_name%"
},
{
"source": "/**/[^0-2].txt", #upload 3.txt, folder/3.txt, a.txt, folder/a.txt (ignore 1.txt, folder/1.txt)
"translation": "/**/%two_letters_code%_%original_file_name%"
}
]
Example 2. Usage of wildcards for ignoring files:
#........your project configuration........
"files": [
{
"source": "/**/*.*", #hochladen aller Dateien, die der base_path enthält
"translation": "/**/%two_letters_code%_%original_file_name%",
"ignore": [
"/**/%two_letters_code%_%original_file_name%", #ignoriere die übersetzten Dateien
"/**/?.txt", #ignoriere 1.txt, a.txt, folder/1.txt, folder/a.txt
"/**/[0-9].txt", #ignoriere 1.txt, folder/1.txt
"/**/*\\?*.txt", #ignoriere crowdin?test.txt, folder/crowdin?test.txt
"/**/[0-9][0-9][0-9].txt", #ignoriere 123.txt , folder/123.txt
"/**/[0-9]*_*.txt" #ignoriere 123_test.txt, folder/123_test.txt
]
}
]
Often software projects have custom names for locale directories. Crowdin allows you to map your own languages to be recognizable in your projects.
Let’s say your locale directories are named ‘en’, ‘uk’, ‘fr’, ‘de’. All of them can be represented by the %two_letters_code% placeholder. Still, you have one directory named ‘zh_CH’. You can also override language codes for other placeholders like %android_code%, %locale%, etc.
Damit es mit Crowdin ohne Änderungen in Ihrem Projekt funktioniert, können Sie das Language Mapping über die Benutzeroberfläche einrichten.
To set up Language Mapping, follow these steps:
If you need to rename a file with translations after the export, you can easily do this with the help of the parameter translation_replace
.
For example, if the file is named “en_strings.po” it can be renamed to “strings.po”. For this, add a new parameter (at the same level as the translation parameter) to the configuration file (crowdin.yml):
"files": [
{
"source": "/locale/**/en_*.po",
"translation": "/locale/**/%two_letters_code%_%original_file_name%",
"translation_replace": {
"en_": ""
}
}
]
In this case, “_en” will simply be erased from the file name.
From time to time there are files and directories you don’t need to translate in Crowdin. In such cases, local per-file rules can be added to the config file in your project.
"files": [
{
"source": "/**/*.properties",
"translation": "/**/%file_name%_%two_letters_code%.%file_extension%",
"ignore": [
"/test/file.properties",
"/example.properties"
]
},
{
"source": "/locale/en/**/*.po",
"translation": "/locale/%two_letters_code%/**/%original_file_name%",
"ignore": [
"/locale/en/templates",
"/locale/en/workflow"
]
}
]
If a CSV or XLS/XLSX file contains the translations for all target languages, you should specify appropriate language codes in the scheme.
CSV file example:
identifier,source_phrase,context,Ukrainian,Russian,French ident1,Source 1,Context 1,,, ident2,Source 2,Context 2,,, ident3,Source 3,Context 3,,,
Configuration file example:
"files": [
{
"source": "multicolumn.csv",
"translation": "multicolumn.csv",
"first_line_contains_header": true,
"scheme": "identifier,source_phrase,context,uk,ru,fr"
}
]
If your CSV or XLS/XLSX file contains columns that should be skipped on import, use none
for such columns in the scheme, for example:
"scheme" : "identifier,source_phrase,context,uk,none,ru,none,fr"
To form the scheme for your CSV or XLS/XLSX file, use the following constants:
identifier
– Column contains string identifiers. source_phrase
– Column contains source strings. source_or_translation
– Column contains source strings, but the same column will be filled with translations when the file is exported. When uploading existing translations, the values from this column will be used as translations. translation
– Column contains translations. context
– Column contains comments or context information for the source strings. max_length
– Column contains max.length limit values for the translations of the strings. labels
– Column contains labels for the source strings. none
– Column that will be skipped on import.
"preserve_hierarchy": true
Example of the configuration file using the preserve_hierarchy
option:
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"preserve_hierarchy": true
"files": [
{
"source": "/locale/en/**/*.po",
"translation": "/locale/%two_letters_code%/**/%original_file_name%"
}
]
By default, directories that do not contain any files for translation will not be created in Crowdin. For example:
- locale | |-- en | |-- foo.po |-- bar.po
By default, project files will be represented in Crowdin as following:
- foo.po
- bar.po
Using the option preserve_hierarchy
, file structure in Crowdin will be the following:
- en | |-- foo.po |-- bar.po
This feature adds support for 2 optional parameters in the yml file section: dest
and type
. This is typically used for projects, where the uploaded name must be different, so Crowdin can detect the type correctly. The dest
parameter allows you to specify a file name in Crowdin.
dest
parameter only works for single files, and if you use it, the configuration file should also include the preserve_hierarchy
parameter with true value.Example of the configuration file with both parameters:
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"preserve_hierarchy": true
"files": [
{
"source": "/conf/messages",
"dest": "/messages.properties",
"translation": "/conf/messages.%two_letters_code%",
"type": "properties"
},
{
"source": "/app/strings.xml",
"dest": "/strings.xml",
"translation": "/res/values-%android_code%/%original_file_name%",
"type": "properties"
}
]
The parameter update_option
is optional. If it is not set, translations for changed strings will be lost. Useful for typo fixes and minor changes in source strings.
Depending on the value, update_option
is used to preserve translations and preserve/remove validations of changed strings during file update.
The values are:
Example of the configuration file with update_option parameter:
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"files": [
{
"source": "/*.csv",
"translation": "/%three_letters_code%/%file_name%.csv",
"first_line_contains_header": true,
"scheme": "identifier,source_phrase,translation,context",
"update_option": "update_as_unapproved"
},
{
"source": "/**/*.xlsx",
"translation": "/%three_letters_code%/folder/%file_name%.xlsx",
"update_option": "update_without_changes"
}
]
The command upload translations uploads existing translations to Crowdin. If no options specified, the uploaded translations will not be imported even if they are equal with the source strings and will not be approved.
The values are:
To configure the preferred export behavior for each file group, you may use the following export options:
skip_untranslated_strings
– Only translated strings will be included in the exported translation files. skip_untranslated_files
– Only translated files will be included in the exported translation archive. export_only_approved
– Only texts that are both translated and approved will be included in the exported translation files.
Example of the configuration file with the export options:
"project_id": "projectId" #Projekteinstellungen öffnen und zum Abschnitt API gehen
"api_token": "personal-access-token" #Profileinstellungen öffnen und zu API & SSO > Neues Token > Token erstellen gehen
"base_path": "/project-base-path"
"base_url": "https://api.crowdin.com"
"preserve_hierarchy": true
"files": [
{
"source": "/locale/en/**/*.po",
"translation": "/locale/%two_letters_code%/**/%original_file_name%",
"skip_untranslated_strings": true
},
{
"source": "/locale/en/**/*.json",
"translation": "/locale/%two_letters_code%/**/%original_file_name%",
"skip_untranslated_files": true
},
{
"source": "/locale/en/**/*.yml",
"translation": "/locale/%two_letters_code%/**/%original_file_name%",
"export_only_approved": true
}
]
translate_content optional | Boolean | Defines whether to translate texts placed inside the tags. Acceptable values are: 0 or 1. Der Standardwert ist 1. |
translate_attributes optional | Boolean | Defines whether to translate tags' attributes. Acceptable values are: 0 or 1. Der Standardwert ist 1. |
content_segmentation optional | Boolean | Defines whether to split long texts into smaller text segments. Acceptable values are: 0 or 1. Der Standardwert ist 1. Important! This option disables the possibility to upload existing translations for XML files when enabled. |
translatable_elements optional | Array | This is an array of strings, where each item is the XPaths to DOM element that should be imported. Sample path: /path/to/node or /path/to/attribute[@attr] Note! If defined, the parameters translate_content and translate_attributes are not taken into account while importing. |
Example of the configuration file with additional parameters:
"project_id": "projectId" #Projekteinstellungen öffnen und zum Abschnitt API gehen
"api_token": "personal-access-token" #Profileinstellungen öffnen und zu API & SSO > Neues Token > Token erstellen gehen
"base_path": "/project-base-path"
"base_url": "https://api.crowdin.com"
"files": [
{
"source": "/app/sample1.xml",
"translation": "/app/%locale%/%original_file_name%",
"translate_attributes": 1,
"translate_content": 0
},
{
"source": "/app/sample2.xml",
"translation": "/app/%locale%/%original_file_name%",
"translatable_elements": [
"/content/text", # übersetzbare Texte werden in 'text'-Knoten des übergeordneten Knotens 'content' gespeichert
"/content/text[@value]" # übersetzbare Texte werden im 'value'-Attribut von 'text'-Knoten gespeichert
]
}
]
Defines whether a single quote should be escaped by another single quote or backslash in exported translations. Sie können escape_quotes
per Datei Option hinzufügen. Zulässige Werte sind: „0”, „1”, „2” und „3”. Der Standardwert ist 3.
The values are:
Escape special characters
Defines whether any special characters (=, :, ! and #) should be escaped by backslash in exported translations. You can add escape_special_characters
per-file option.
Acceptable values are: 0, 1. Der Standardwert ist 1.
Example of the configuration file:
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"files": [
{
"source": "/en/strings.properties",
"translation": "/%two_letters_code%/%original_file_name%",
"escape_quotes": 1,
"translate_content": 0,
"escape_special_characters": 0
}
]
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"files": [
{
"source": "/*.csv",
"translation": "/%two_letters_code%/%original_file_name%",
# Specifies whether first line should be imported or it contains columns headers
"first_line_contains_header": true,
# used only when uploading CSV file to define data columns mapping
"scheme": "identifier,source_phrase,translation,context,max_length"
}
]
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"files" : [
{
"source" : "/locale/en/**/*.po",
"translation" : "/locale/%two_letters_code%/LC_MESSAGES/%original_file_name%",
"languages_mapping" : {
"two_letters_code" : {
"zh-CN" : "zh_CH",
"fr-QC": "fr"
}
}
}
]
"project_id": "projectId" #open project settings and go to API section
"api_token": "personal-access-token" #open profile settings and go to API & SSO > New Token > create Token
"base_path": "/project-base-path"
"base_url": "https://crowdin.com"
"files" : [
{
"source" : "/res/values/*.xml",
"translation" : "/res/values-%android_code%/%original_file_name%",
"languages_mapping" : {
"android_code" : {
"de" : "de",
"ru" : "ru"
}
}
}
]
VCS integrations require the same configuration file as the CLI tool, meaning the same structure is supported. The only difference, is that the project credentials should not be stored in the file header for security reasons. Also, two additional parameters can be used.
Each time translations are committed the default message is shown “New translations {fileName} ({languageName})”. You can use commit_message
parameter to add Git tags (e.g. to skip builds).
Beispiel:
"base_path": "/project-base-path"
"commit_message": "[ci skip]"
"files": [
{
"source" : "/resources/en/*.json",
"translation" : "/resources/%two_letters_code%/%original_file_name%"
}
]
To replace the default commit message, use append_commit_message
parameter with the value false. You can also add two optional placeholders: %original_file_name% and %language% to use the appropriate file name and language variables accordingly.
Beispiel:
"commit_message": "Fix: New translations %original_file_name% from Crowdin"
"append_commit_message": false
"files": [
{
"source" : "/resources/en/*.json",
"translation" : "/resources/%two_letters_code%/%original_file_name%"
}
]
By default, all the languages are exported. If you need to export some specific languages, use export_languages
parameter to specify them.
Beispiel:
"base_path": "/project-base-path"
"export_languages": [
"ru",
"uk",
"ja"
]
"files": [
{
"source" : "/resources/en/*.json",
"translation" : "/resources/%two_letters_code%/%original_file_name%"
}
]
To add existing or new labels to the source strings, use the labels
parameter. Labels will be added to the source strings only during the initial upload to the Crowdin project.
The strings uploaded to the Crowdin project before the use of the labels
parameter won’t be labeled. If you remove the label added during the initial upload directly in Crowdin, it won’t be re-added on the next syncs.
The label names can contain any characters except “,
”.
Beispiel:
"base_path": "/project-base-path"
"files": [
{
"source" : "/resources/en/*.json",
"translation" : "/resources/%two_letters_code%/%original_file_name%",
"labels" : [
"android",
"emails"
]
}
]
Read more about Labels.
There are cases when it’s necessary to use VCS integration and CLI for one project. Mostly, in this kind of situation, you’d need to have two separate configuration files, one for VCS integration and another for CLI. However, there is a possibility to use a single configuration file for both cases.
Since the VCS integration configuration file doesn’t contain project_id
and api_token
credentials that are required for CLI, you can pass them directly in the command using the following parameters: -i/--project-id
, -T/--token
. Alternatively, you may use environment variables for this purpose.
As a result, your command for downloading translations via CLI will look like the following:
$ crowdin download -i {your-project-id} -T {your-token}
Need help working with Crowdin CLI or have any questions? Contact Support Team.