Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Image ModifiedImage Modified Image Modified

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:

  • lot easier to read and write

  • You have to use the text and not the key in the “source” tag of the xlf file, otherwise the translator will not see any hint (e.g. variables) what to translate except the key, which makes it impossible to translate. Symfony can handle this situation by using the key from the “resname” attribute of “trans-unit” tag, but the PHPStorm Symfony Plugin will not recognize this and marks the key as “missing translation”.

  • Crowdin shows the key as “Context” if you use YAML but it does not for XLIFF


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
languagexmllinenumberstrue
{{ 'your_module.your_context.your_key' | trans }}

over

Code Block
languagexml
linenumberstrue
{% 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
linenumbers
languagexmltrue
{% for fieldNote in fieldNotes %}
	...
	<td>{{ ('field_notes.log_type.' ~ fieldNote.type) | trans({}, 'constants') }}</td>
	...
{% endfor %}

...

Just use the translator service e.g.

Code Block
languagephp
linenumberstrue
$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
languagebash
crowdin-cli --identity=.crowdin.yaml upload sources


Import translations with Crowdin CLI V3

(warning) Not yet operational

Setup

  1. Get your personal access tokens from https://crowdin.com/settings

  2. 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"

  3. Install Crowdin CLI version 3: https://support.crowdin.com/cli-tool/

Import

  1. Run


    ./psh.phar docker:crowdin-import