Skip to content

Commit e1dfad2

Browse files
committed
docs(design): split translator hints between writing guide and translations ref
Move code examples for TRANSLATORS comments to basics/translations.rst (the implementation reference) and keep only prose guidelines in design/writing.rst. Cross-link both directions so neither page duplicates the other. - writing.rst: strip code blocks from Translator comments and Placeholders sections; add cross-refs to translations.rst - translations.rst: improve PHP/JS/Vue TRANSLATORS examples (Vue template uses <!-- --> above element, add multi-line PHP pattern); add ref label improving-translations for cross-linking Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 4573c24 commit e1dfad2

2 files changed

Lines changed: 37 additions & 60 deletions

File tree

developer_manual/basics/translations.rst

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ JS Example:
220220
/* BEST: Simple string with undefined plural not using any number in the string */
221221
t('myapp', 'Import calendars')
222222
223+
.. _improving-translations:
224+
223225
Improving your translations
224226
^^^^^^^^^^^^^^^^^^^^^^^^^^^
225227

@@ -284,37 +286,49 @@ The added hints will be shown in the Transifex web-interface:
284286
PHP
285287
"""
286288

289+
Place the comment on the line before the ``->t()`` or ``->n()`` call:
290+
291+
.. code-block:: php
292+
293+
// TRANSLATORS Will be shown inside a popup and asks the user to add a new file
294+
p($l->t('Add new file'));
295+
296+
// TRANSLATORS The placeholder refers to the software product name, e.g. "Add to your Nextcloud"
297+
$l->t('Add to your %s', [$productName]);
298+
299+
For multi-line context or example output, use consecutive comment lines:
300+
287301
.. code-block:: php
288302
289-
<ul id="translations">
290-
<li id="add-new">
291-
<?php
292-
// TRANSLATORS Will be shown inside a popup and asks the user to add a new file
293-
p($l->t('Add new file'));
294-
?>
295-
</li>
296-
</ul>
303+
// TRANSLATORS
304+
// Indicates when a calendar event will happen, shown on invitation emails.
305+
// Output example: "In 1 hour on July 1, 2024 for the entire day"
306+
$l->t('In %1$s on %2$s for the entire day', [$relativeTime, $date]);
297307
298308
JavaScript / TypeScript
299309
"""""""""""""""""""""""
300310

311+
Place the comment on the line before the ``t()`` or ``n()`` call:
312+
301313
.. code-block:: javascript
302314
303-
// TRANSLATORS name that is appended to copied files with the same name, will be put in parenthesis and appended with a number if it is the second+ copy
315+
// TRANSLATORS: name that is appended to copied files, will be put in parenthesis with a number for the second+ copy
304316
var copyNameLocalized = t('files', 'copy');
305317
318+
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days"
319+
t('files_reminders', 'We will remind you of this file {relativeDueDate}', { relativeDueDate })
320+
306321
Vue
307322
"""
308323

309-
This covers vue html templates in vue sfc components.
310-
For vue js code, see the javascript section.
324+
In the ``<template>`` block, use an HTML comment on the line above the element:
311325

312326
.. code-block:: html
313327

314-
<NcActionCheckbox :checked="isRequired">
315-
<!-- TRANSLATORS Making this question necessary to be answered when submitting to a form -->
316-
{{ t('forms', 'Required') }}
317-
</NcActionCheckbox>
328+
<!-- TRANSLATORS: Making this question necessary to be answered when submitting to a form -->
329+
<span>{{ t('forms', 'Required') }}</span>
330+
331+
In the ``<script>`` block, use the same ``//`` style as JavaScript.
318332

319333
C++ (Qt) / Desktop client
320334
"""""""""""""""""""""""""

developer_manual/design/writing.rst

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -102,63 +102,26 @@ Placeholders and variables
102102

103103
When a string contains a variable (file name, user name, count), keep the surrounding text short and natural.
104104
Make sure the string still makes sense in all languages — word order differs across languages, so avoid splitting a sentence across two separate strings.
105+
For implementation details and code examples, see :ref:`improving-translations` in the translations reference.
105106

106-
.. code-block:: php
107-
108-
// Good — full sentence in one string, variable embedded
109-
$l->t('Shared with %s', [$userName]);
110-
111-
// Avoid — concatenation breaks translation
112-
$l->t('Shared with ') . $userName;
107+
.. _translator-comments:
113108

114109
Translator comments
115110
-------------------
116111

117-
When a string is ambiguous or contains placeholders, add a ``TRANSLATORS`` comment on the line immediately before the translatable string.
112+
When a string is ambiguous or contains placeholders, add a ``TRANSLATORS`` comment immediately before the translatable call.
118113
The comment is extracted by the translation tooling and shown to translators in Transifex.
119114

120-
**When to add one:**
115+
Add one when:
121116

122117
- The string is ambiguous out of context (e.g. a single word with multiple meanings).
123-
- The string contains a placeholder — explain what the placeholder will be replaced with and give an example value where helpful.
118+
- The string contains a placeholder — explain what it will be replaced with and give an example value.
124119
- The string describes a UI element or workflow that is not obvious from the text alone.
125120

126-
**PHP** — place the comment on the line before the ``->t()`` call:
127-
128-
.. code-block:: php
129-
130-
// TRANSLATORS The placeholder refers to the software product name, e.g. "Add to your Nextcloud"
131-
$l->t('Add to your %s', [$productName]);
132-
133-
**JavaScript / TypeScript** — same rule, line before the ``t()`` call:
134-
135-
.. code-block:: javascript
136-
137-
// TRANSLATORS: This is the number of hidden files or folders
138-
const hiddenSummary = n('files', '%n hidden', '%n hidden', hidden)
139-
140-
// TRANSLATORS: {relativeDueDate} will be replaced with a relative time, e.g. "2 hours ago" or "in 3 days"
141-
t('files_reminders', 'We will remind you of this file {relativeDueDate}', { relativeDueDate })
142-
143-
**Vue template** — use an HTML comment on the line above the element:
144-
145-
.. code-block:: html
146-
147-
<!-- TRANSLATORS: Background using a single color -->
148-
<span>{{ t('theming', 'Plain background') }}</span>
149-
150-
In the ``<script>`` block of a Vue file, use the same ``//`` style as JavaScript.
151-
152-
**Multi-line** — use when the context needs more than one sentence or lists example output:
153-
154-
.. code-block:: php
155-
156-
// TRANSLATORS
157-
// Indicates when a calendar event will happen, shown on invitation emails.
158-
// Output example: "In 1 hour on July 1, 2024 for the entire day"
159-
$l->t('In %1$s on %2$s for the entire day', [$relativeTime, $date]);
121+
Keep comments factual and brief. State what the placeholder contains and where the string appears.
122+
Do not repeat the string itself.
160123

161-
Keep comments factual and brief. State what the placeholder contains and where the string appears. Do not repeat the string itself.
124+
For syntax examples in PHP, JavaScript, Vue, and other platforms, see :ref:`Hints`.
162125

163126
Translatable strings
164127
--------------------

0 commit comments

Comments
 (0)