Skip to content

Commit 83a8587

Browse files
authored
Merge pull request #15295 from nextcloud/fix/noid/translators-string
fix(developer): add note about multiple translation strings per line
2 parents 2a14d3b + 52da74f commit 83a8587

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

developer_manual/basics/translations.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,26 @@ Especially translations strings that only contain a single word often result in
283283
The most famous example in the Nextcloud code base is ``Share`` which can which can be the verb and action ``To share something`` or the noun ``A share``.
284284
The added hints will be shown in the Transifex web-interface:
285285

286+
.. warning::
287+
288+
A ``// TRANSLATORS`` comment is only associated with the **first** translation string on the following line.
289+
If a single line of code contains two or more translation strings, the comment applies to the first one only,
290+
and the remaining strings will have no context hint. Refactor the code so that each line holds a single
291+
translation call, placing its own ``// TRANSLATORS`` comment on the line above.
292+
293+
.. code-block:: php
294+
295+
// BAD: only "Save" gets the context hint, "Cancel" has none
296+
// TRANSLATORS Confirm or discard the current changes
297+
return [$l->t('Save'), $l->t('Cancel')];
298+
299+
// GOOD: one translation per line, each with its own hint
300+
// TRANSLATORS Confirm the current changes
301+
$save = $l->t('Save');
302+
// TRANSLATORS Discard the current changes
303+
$cancel = $l->t('Cancel');
304+
return [$save, $cancel];
305+
286306
PHP
287307
"""
288308

0 commit comments

Comments
 (0)