We use crowdin for easy crowdsourced translation management of Opencaching.
...
Info |
---|
Against Symfony Best Practice we decided to use YAML instead of XLIFF for the following reasons:
|
Note |
---|
Always use keys for translations instead of content strings. Use descriptive placeholders e.g. "Hello %name%" instead of "Hello %1". |
Translations are stored in app/Resources/translations
. messages.en.yml
contains all automatically extracted strings from the application, constants.en.yml
contains strings which can not be extracted from source or templates because they are generated dynamically. (See example below)
Warning |
---|
Do not manually edit other languages than *.en.yml and do not add them to the git repository. They are managed by crowdin an will be overwritten. |
...
We prefer
Code Block | ||||
---|---|---|---|---|
| ||||
{{ 'your_module.your_context.your_key' | trans }} |
over
Code Block | ||||
---|---|---|---|---|
| ||||
{% trans %}your_module.your_context.your_key{% endtrans %} |
...
You have to specify the constants
domain if you need to create keys dynamically e.g.
Code Block | ||||
---|---|---|---|---|
| ||||
{% for fieldNote in fieldNotes %} ... <td>{{ ('field_notes.log_type.' ~ fieldNote.type) | trans({}, 'constants') }}</td> ... {% endfor %} |
...
Just use the translator service e.g.
Code Block | ||||
---|---|---|---|---|
| ||||
$this->get('translator')->trans('your_module.your_context.your_key') |
...
Make sure you have a file .crowdin.yaml
in in the htdocs
directory and it contains the api key of the project. See crowdin-cli documentation for details.
Download translations
...
Code Block | ||
---|---|---|
| ||
crowdin-cli --identity=.crowdin.yaml upload sources |
Import translations with Crowdin CLI V3
Not yet operational
Setup
Get your personal access tokens from https://crowdin.com/settings
Store your token to the environment variable
CROWDIN_PERSONAL_TOKEN
Example for fish:set -Ux CROWDIN_PERSONAL_TOKEN your_token
Example for bash (in ~/.bashrc):export CROWDIN_PERSONAL_TOKEN="your_token"
Install Crowdin CLI version 3: https://support.crowdin.com/cli-tool/
Import
Run
./psh.phar docker:crowdin-import