<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.opencaching.de/index.php?action=history&amp;feed=atom&amp;title=Translation_Handling_%28Legacy%29</id>
	<title>Translation Handling (Legacy) - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.opencaching.de/index.php?action=history&amp;feed=atom&amp;title=Translation_Handling_%28Legacy%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.opencaching.de/index.php?title=Translation_Handling_(Legacy)&amp;action=history"/>
	<updated>2026-06-03T00:44:16Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Opencaching-Wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.opencaching.de/index.php?title=Translation_Handling_(Legacy)&amp;diff=7856&amp;oldid=prev</id>
		<title>Fraggle: Erstentwurf</title>
		<link rel="alternate" type="text/html" href="https://wiki.opencaching.de/index.php?title=Translation_Handling_(Legacy)&amp;diff=7856&amp;oldid=prev"/>
		<updated>2024-05-06T18:24:16Z</updated>

		<summary type="html">&lt;p&gt;Erstentwurf&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;We use crowdin for easy crowdsourced translation management of Opencaching.&lt;br /&gt;
If you are not a developer but want to help translate Opencaching just head over to https://crowdin.com/project/opencaching and start translating to your language.&lt;br /&gt;
&lt;br /&gt;
== Development Workflow and Info ==&lt;br /&gt;
We use the Translation component of the Symfony Framework to translate strings in the application. Have a look at the Symfony Book for more details. A short introduction follows below.&lt;br /&gt;
&lt;br /&gt;
Against [https://symfony.com/doc/current/best_practices/i18n.html#translation-source-file-format|Symfony Best Practice] we decided to use YAML instead of XLIFF for the following reasons:&lt;br /&gt;
* lot easier to read and write&lt;br /&gt;
* 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”.&lt;br /&gt;
* Crowdin shows the key as “Context” if you use YAML but it does not for XLIFF&lt;br /&gt;
&lt;br /&gt;
! Important to note: Always use [https://symfony.com/doc/current/best_practices/i18n.html#translation-keys|keys for translations] instead of content strings. Use descriptive placeholders e.g. &amp;quot;Hello %name%&amp;quot; instead of &amp;quot;Hello %1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Translations are stored in &amp;lt;code&amp;gt;app/Resources/translations.messages.en.yml&amp;lt;/code&amp;gt; contains all automatically extracted strings from the application, &amp;lt;code&amp;gt;constants.en.yml&amp;lt;/code&amp;gt; contains strings which can not be extracted from source or templates because they are generated dynamically. (See example below)&lt;br /&gt;
&lt;br /&gt;
! 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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Translate Strings in Twig Templates ===&lt;br /&gt;
We prefer&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{ &amp;#039;your_module.your_context.your_key&amp;#039; | trans }}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
over&lt;br /&gt;
 {% trans %}your_module.your_context.your_key{% endtrans %}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You have to specify the &amp;lt;code&amp;gt;constants&amp;lt;/code&amp;gt; domain if you need to create keys dynamically e.g.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{% for fieldNote in fieldNotes %}&lt;br /&gt;
	...&lt;br /&gt;
	&amp;lt;td&amp;gt;{{ (&amp;#039;field_notes.log_type.&amp;#039; ~ fieldNote.type) | trans({}, &amp;#039;constants&amp;#039;) }}&amp;lt;/td&amp;gt;&lt;br /&gt;
	...&lt;br /&gt;
{% endfor %}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and add your keys manually to &amp;lt;code&amp;gt;constants.en.yml&amp;lt;/code&amp;gt; because they can not be extracted automatically and would be removed from &amp;lt;code&amp;gt;messages.en.yml&amp;lt;/code&amp;gt; on the next extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Translate Strings in PHP Code ===&lt;br /&gt;
Just use the translator service e.g.&lt;br /&gt;
 $this-&amp;gt;get(&amp;#039;translator&amp;#039;)-&amp;gt;trans(&amp;#039;your_module.your_context.your_key&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Extract strings from Source and Templates ===&lt;br /&gt;
We use [https://github.com/schmittjoh/JMSTranslationBundle| JMSTranslationBundle] to extract strings from source and templates.&lt;br /&gt;
&lt;br /&gt;
The bundle is configured in &amp;lt;code&amp;gt;app/config/config.yml&amp;lt;/code&amp;gt;. To update &amp;lt;code&amp;gt;messages.en.yml&amp;lt;/code&amp;gt; just login to your VM, &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/var/www/html/htdocs&amp;lt;/code&amp;gt; and run&lt;br /&gt;
 bin/console translation:extract en --config=app&lt;br /&gt;
&lt;br /&gt;
This will add new keys and remove unused ones from &amp;lt;code&amp;gt;messages.en.yml&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
After this you have to edit &amp;lt;code&amp;gt;messages.en.yml&amp;lt;/code&amp;gt; and add the english text to the key (the bundle tags the new keys with &amp;lt;code&amp;gt;# FIXME&amp;lt;/code&amp;gt; to find them easily)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Copy Translations to and from Crowdin ===&lt;br /&gt;
==== Preparation ====&lt;br /&gt;
Make sure you have a file &amp;lt;code&amp;gt;.crowdin.yaml&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;htdocs&amp;lt;/code&amp;gt; directory and it contains the api key of the project. See [https://github.com/crowdin/crowdin-cli#split-project-configuration-and-user-credentials|crowdin-cli documentation] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Download translations ====&lt;br /&gt;
&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/var/www/html/htdocs&amp;lt;/code&amp;gt; and run&lt;br /&gt;
 crowdin-cli --identity=.crowdin.yaml download&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Upload translation source ====&lt;br /&gt;
&amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/var/www/html/htdocs&amp;lt;/code&amp;gt; and run&lt;br /&gt;
 crowdin-cli --identity=.crowdin.yaml upload sources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Import translations with Crowdin CLI V3 ==&lt;br /&gt;
! This function is not yet operable&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
* Get your personal access tokens from https://crowdin.com/settings&lt;br /&gt;
* Store your token to the environment variable &amp;lt;code&amp;gt;CROWDIN_PERSONAL_TOKEN&amp;lt;/code&amp;gt;&lt;br /&gt;
** Example for fish: &amp;lt;code&amp;gt;set -Ux CROWDIN_PERSONAL_TOKEN your_token&amp;lt;/code&amp;gt;&lt;br /&gt;
** Example for bash (in ~/.bashrc): &amp;lt;code&amp;gt;export CROWDIN_PERSONAL_TOKEN=&amp;quot;your_token&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* Install Crowdin CLI version 3: https://support.crowdin.com/cli-tool/&lt;br /&gt;
&lt;br /&gt;
=== Import ===&lt;br /&gt;
* Run &amp;lt;code&amp;gt;./psh.phar docker:crowdin-import&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Kategorie:Entwicklung]]&lt;br /&gt;
[[Kategorie:English pages]]&lt;/div&gt;</summary>
		<author><name>Fraggle</name></author>
	</entry>
</feed>