Crowdin CLI uses a configuration file that contains a description of the resources to manage: files to be uploaded into Crowdin and the locations of the corresponding translations.
For at benytte Crowdin-CLI skal du først generere din opsætningsfil og herefter afvikle værktøjet. 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).
For at oprette opsætningsfilen, så kør følgende kommando:
$ crowdin lint
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%"
}
]
For at køre ovenstående opsætningsfil og uploade kildefiler til Crowdin:
$ crowdin upload sources -b
Get translations from Crowdin and put them in the right locations:
$ crowdin download
Du kan indlæse API-akkreditiverne fra en miljøvariabel, f.eks.:
"project_id_env": "CROWDIN_PROJECT_ID"
"api_token_env": "CROWDIN_PERSONAL_TOKEN"
"base_path_env": "CROWDIN_BASE_PATH"
"base_url_env": "CROWDIN_BASE_URL"
Hvis blandet, prioriteres api_token samt project_id:
"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). Det betyder, at det er reiskabelt at lagre denne i kodedepotet, da API-nøglen vil være tilgængelig for andre brugere. Crowdin-CLI understøtter 2 typer opsætningsfiler:
Har du behov for at køre en kommando med brugerspecifikke akkreditiver (f.eks. upload-kilder
). så eksekvér flg. kommando:
$ crowdin upload sources --identity 'path-to-user-credentials-file'
Hvis brugerspecifikke akkreditiver er placeret i $HOME/.crowdin.yml, kan du blot køre:
$ crowdin upload sources -b
Den ovenfor viste prøveopsætning har kilde- og oversættelsesattributter indeholdende standard jokertegn (også betegnet globbing mønstre) for at gøre det nemmere at arbejde med flere filer.
Her er mønstre, du kan bruge:
* (stjerne)
Repræsenterer alle tegn i et fil- eller mappenavn. Angives en “*.json”, vil den indeholde alle filer, såsom “messages.json”, “about_us.json”, og alt af filtypen “.json”.
*** (dobbeltstjerne)
Matcher enhver streng rekursivt (inkl. undermapper). Bemærk, at *** kan benyttes i både kilde- og oversættelsesmønstre. Ved brug af *** i oversættelsesmønsteret vil det altid indeholde understier fra kilden til en bestemt fil. Der kan f.eks. benyttes kilden: ‘/da/*.po’ for rekursivt at uploade alle *.po-filer til Crowdin. Oversættelsesmønsteret vil være ‘/%two_letters_code%/\/%original_file_name%’.
? (spørgsmålstegn)
Matcher ethvert enkelttegn.
[set]
Matcher ethvert enkelttegn i et sæt. Opfører sig nøjagtig som tegnsæt i Regexp, herunder negation ([^a-z]).
\ (omvendt skråstreg)
Escaper det næste metategn.
Crowdin-CLI gør det muligt at benytte flg. pladsholdere til at indsætte passende variabler i det resulterende filnavn:
Navn | Beskriveslse |
---|---|
%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% | Oprindeligt filnavn |
%android_code% | Android Landestandard-ID benyttes ved navngivning af "værdier"-mapper |
%osx_code% | OS X-landestandard-ID benyttet ved navngivning af ".lproj"-mapper |
%original_path% | Benyt navne på overordnede mapper i Crowdin-projektet for at opbygge en filsti i den resulterende pakke |
%file_extension% | Oprindeligt filtypenavn |
%file_name% | Filnavn uden fiíltypeangivelse |
Du kan også definere stien til filer i det resulterende depot ved at sætte et skråstreg (/) i starten af mønsteret.
Din oversættelsesindstilling
kan se ud som: “/ locale /%two_letters_code%/ LC_MESSAGES /%original_file_name%”.
Opbygning af filer og mapper på den lokale maskine:
- 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
Eksempel 1. Brug af jokertegn i kildestien:
#........din projektkonfiguration........
"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%"
}
]
Eksempel 2. Brug af jokertegn til ignorering af filer:
#........din projektkonfiguration........
"files": [
{
"source": "/**/*.*", #upload all files that the base_path contains
"translation": "/**/%two_letters_code%_%original_file_name%",
"ignore": [
"/**/%two_letters_code%_%original_file_name%", #ignore the translated files
"/**/?.txt", #ignore 1.txt, a.txt, folder/1.txt, folder/a.txt
"/**/[0-9].txt", #ignore 1.txt, folder/1.txt
"/**/*\\?*.txt", #ignore crowdin?test.txt, folder/crowdin?test.txt
"/**/[0-9][0-9][0-9].txt", #ignore 123.txt , folder/123.txt
"/**/[0-9]*_*.txt" #ignore 123_test.txt, folder/123_test.txt
]
}
]
Ofte har softwareprojekter tilpassede navne til lokalmapper. Crowdin allows you to map your own languages to be recognizable in your projects.
Lad os antage, at dine lokalmapper er navngivet ‘en’, ‘uk’, ‘fr’, ‘de’. De kan alle repræsenteres af parameteren %two_letters_code%. Du har stadig en mappe med navnet ‘zh_CH’. Du kan også tilsidesætte sprogkoder for andre parametre såsom %android_code%, %locale% mv.
To make it work with Crowdin without changes in your project, you can set up Language Mapping via UI.
To set up Language Mapping, follow these steps:
Har du behov for at omdøbe en fil med oversættelser efter eksporten, kan du nemt gøre dette vha. parameteren translation_replace
.
Hedder filen f.eks. “en_strings.po”, kan den omdøbes til “strings.po”. Til dette skal du føje en ny parameter (på samme niveau som oversættelsesparameteren) til opsætningsfilen (crowdin.yml):
"files": [
{
"source": "/locale/**/en_*.po",
"translation": "/locale/**/%two_letters_code%_%original_file_name%",
"translation_replace": {
"en_": ""
}
}
]
I dette tilfælde vil “_en” simpelthen blive slettet fra filnavnet.
Fra tid til anden er der filer og mapper i dit projekt, du behøver ikke oversætte. I sådanne tilfælde kan lokale pr. fil-regler føjes til dit projekts config-fil.
"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"
]
}
]
By default, the source files are available for translation into all target languages of the project. If some source files shouldn’t be translated into specific target languages, you can exclude them with the help of the parameter excluded_target_languages
.
Opsætningsfileksempel:
"files": [
{
"source": "/resources/en/*.json",
"translation": "/resources/%two_letters_code%/%original_file_name%",
"excluded_target_languages": [
"uk",
"fr"
]
}
]
If a CSV or XLS/XLSX file contains the translations for all target languages, you should specify appropriate language codes in the scheme.
CSV-fileksempel:
identifier,source_phrase,context,Ukrainian,Russian,French ident1,Source 1,Context 1,,, ident2,Source 2,Context 2,,, ident3,Source 3,Context 3,,,
Opsætningsfileksempel:
"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%"
}
]
Som standard oprettes mapper uden filindehold til oversættelse ikke i projekt. F.eks.:
- locale | |-- en | |-- foo.po |-- bar.po
Som standard repræsenteres projektfiler som følgende:
- foo.po
- bar.po
Vha. indstillingen preserve_hierarchy
, vil filstrukturen vil være følgende:
- en | |-- foo.po |-- bar.po
This feature adds support for 2 optional parameters in the yml file section: dest
and type
. Dette benyttes typisk til projekter, hvor det uploadede navn skal være anderledes, så Crowdin kan registrere typen korrekt. dest
-parameteren giver mulighed for at angive et filnavn i Crowdin.
dest
fungerer kun for enkeltfiler, og benyttes den, bør opsætningsfilen også medtage parameteren preserve_hierarchy
med true som indholdsdata.Eksempel på en opsætningsfil med begge parametre:
"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"
}
]
Parameteren update_option
er valgfri. Opsættes den ikke, mistes oversættelser til ændrede strenge. Nyttigt for skrivefejlrettelser og mindre kildestrengsændringer.
Afhængigt af værdien benyttes update_option
til at bevare oversættelser og bevare/fjerne valideringer af ændrede strenge under filopdatering.
Værdierne er:
Eksempel på en opsætningsfil med update_option-parameteren:
"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.
Værdierne er:
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" #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://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 valgfrit | bool | Defines whether to translate texts placed inside the tags. Acceptable values are: 0 or 1. Standard er 1. |
translate_attibutes valgfri | bool | Defines whether to translate tags' attributes. Acceptable values are: 0 or 1. Standard er 1. |
content_segmentation valgfri | bool | Defines whether to split long texts into smaller text segments. Acceptable values are: 0 or 1. Standard er 1. Vigtigt! Denne indstilling umuliggør upload af eksisterende oversættelser til XML-filer, når den er aktiveret. |
translatable_elements valgfri | matrix | Dette er en matrix af strenge, hvori hvert element er XPaths tilet DOM-element, der skal importeres. Eksempelsti: /path/to/node or /path/to/attribute[@attr] Bemærk! Hvis angivet, tages parametrene translate_content og translate_attributes ikke i betragtning under importen. |
Eksempel på en opsætningsfil med ekstra parametre:
"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": "/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", # translatable texts are stored in 'text' nodes of parent node 'content'
"/content/text[@value]" # translatable texts are stored in 'value' attribute of 'text' nodes
]
}
]
Definerer, om et enkelt anførselstegn skal escapes af et andet enkelt anførselstegn eller bagudvendt stråstreg i eksporterede oversættelser. You can add escape_quotes
per-file option. Gyldige værdier er: 0, 1, 2, 3. Standard er 3.
Værdierne er:
Escape special characters
Defines whether any special characters (=, :, ! og #) skal escapes med bagudvendt skråstreg i eksporterede oversættelser. Du kan tilføje escape_quote
-muligheden pr. fil.
Acceptable values are: 0, 1. Standard er 1.
Opsætningsfileksempel:
"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-integrationer kræver den samme opsætningsfil som CLI-værktøjet, hvilket betyder, at den samme struktur understøttes. Den eneste forskel er, at projektets akkreditiver af sikkerhedsmæssige årsager ikke skal lagres i filoverskriften. Der kan også benyttes to ekstra parametre.
Hver gang oversættelser commites, vises standardmeddelelsen “Nye oversættelser {fileName} ({languageName})”. Du kan benytte commit_message
-parameteren til at tilføje Git-tags (for at overspringe builds).
Eksempel:
"base_path": "/project-base-path"
"commit_message": "[ci skip]"
"files": [
{
"source" : "/resources/en/*.json",
"translation" : "/resources/%two_letters_code%/%original_file_name%"
}
]
For at erstatte standard commit-meddelelsen skal du benytte append_commit_message
-parameteren med værdien false. Du kan også tilføje to valgfrie parametre: %original_file_name% og %language% for at benytte det relevante filnavn og sprogvariablerne i relation hertil.
Eksempel:
"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%"
}
]
Som standard eksporteres alle sprogene. Har du behov for at eksportere visse bestemte sprog, så benyt parameteren export_languages
for at angive disse.
Eksempel:
"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 “,
”.
Eksempel:
"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}
Behov for hjælp til brug af Crowdin-CLI eller evt. spørgsmål? Kontakt Supportteamet.