Skip to content

Commit 8234465

Browse files
committed
Added a short guide about contributing code translations
1 parent d1e14b8 commit 8234465

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

best_practices.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ are two of the main tasks when handling forms. Both are too similar (most of the
320320
times, almost identical), so it's much simpler to let a single controller action
321321
handle both.
322322

323+
.. _best-practice-internationalization:
324+
323325
Internationalization
324326
--------------------
325327

contributing/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Contributing
77
code_of_conduct/index
88
code/index
99
documentation/index
10+
translations/index
1011
community/index
1112
diversity/index
1213

contributing/translations/index.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Contributing Translations
2+
=========================
3+
4+
Some Symfony Components include certain messages that must be translated to
5+
different languages. For example, if a user submits a form with a wrong value in
6+
a :doc:`TimezoneType </reference/forms/types/timezone>` field, Symfony shows by
7+
default the following error message: "This value is not a valid timezone."
8+
9+
These messages are translated into tens of languages thanks to the Symfony
10+
community. Symfony adds new messages on a regular basis, so this is an ongoing
11+
translation process and you can help us providing the missing translations.
12+
13+
How to Contribute a Translation
14+
-------------------------------
15+
16+
Imagine that you can speak both English and Swedish and want to check if there's
17+
some missing Swedish translations to contribute them.
18+
19+
**Step 1.** Translations are contributed to the oldest maintained branch of the
20+
Symfony repository. Visit the `Symfony Releases`_ page to find out which is the
21+
current oldest maintained branch.
22+
23+
If you know Git well, clone the Symfony repository and check out that branch.
24+
Otherwise, visit https://github.com/symfony/symfony and switch to that branch.
25+
26+
**Step 2.** Check out if there's some missing translation in your language.
27+
You only have to check these directories:
28+
29+
* ``src/Symfony/Component/Form/Resources/translations/``
30+
* ``src/Symfony/Component/Security/Core/Resources/translations/``
31+
* ``src/Symfony/Component/Validator/Resources/translations/``
32+
33+
Symfony uses the :ref:`XLIFF format <best-practice-internationalization>` to
34+
store translations. In this example, you are looking for missing Swedish
35+
translations, so you should look for files called ``*.se.xlf``.
36+
37+
.. note::
38+
39+
If there's no XLIFF file yet for your language, create it yourself
40+
duplicating the original English file (e.g. ``validators.en.xlf``).
41+
42+
**Step 3.** Contribute the missing translations. To do that, compare the file
43+
in your language to the equivalent file in English.
44+
45+
Imagine that you open the ``validators.sv.xlf`` and see this at the end of the file:
46+
47+
.. code-block:: xml
48+
49+
<!-- ... -->
50+
<trans-unit id="91">
51+
<source>This value should be either negative or zero.</source>
52+
<target>Detta värde bör vara antingen negativt eller noll.</target>
53+
</trans-unit>
54+
<trans-unit id="92">
55+
<source>This value is not a valid timezone.</source>
56+
<target>Detta värde är inte en giltig tidszon.</target>
57+
</trans-unit>
58+
59+
If you open the equivalent ``validators.en.xlf`` file, you can see that the
60+
English file has more messages to translate:
61+
62+
.. code-block:: xml
63+
64+
<!-- ... -->
65+
<trans-unit id="91">
66+
<source>This value should be either negative or zero.</source>
67+
<target>This value should be either negative or zero.</target>
68+
</trans-unit>
69+
<trans-unit id="92">
70+
<source>This value is not a valid timezone.</source>
71+
<target>This value is not a valid timezone.</target>
72+
</trans-unit>
73+
<trans-unit id="93">
74+
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
75+
<target>This password has been leaked in a data breach, it must not be used. Please use another password.</target>
76+
</trans-unit>
77+
<trans-unit id="94">
78+
<source>This value should be between {{ min }} and {{ max }}.</source>
79+
<target>This value should be between {{ min }} and {{ max }}.</target>
80+
</trans-unit>
81+
82+
The messages with ``id = 93`` and ``id = 94`` are missing in the Swedish file.
83+
Copy and paste the messages from the English file, translate the content
84+
inside the ``<target>`` tag and save the changes.
85+
86+
**Step 4.** Make the pull request against the Symfony GitHub repository. If you
87+
need help, check the other Symfony guides about :doc:`contributing code or docs </contributing/index>`
88+
because the process is the same.
89+
90+
.. _`Symfony Releases`: https://symfony.com/releases

0 commit comments

Comments
 (0)