Skip to content

Commit 68dbd30

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
docs(design): add translator comments section to UX writing guide
Explains when and how to write TRANSLATORS comments in PHP, JS/TS, Vue templates, and Vue script blocks, with examples from the server codebase. Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent b27f8cf commit 68dbd30

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

developer_manual/design/writing.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,55 @@ Make sure the string still makes sense in all languages — word order differs a
111111
// Avoid — concatenation breaks translation
112112
$l->t('Shared with ') . $userName;
113113
114+
Translator comments
115+
-------------------
116+
117+
When a string is ambiguous or contains placeholders, add a ``TRANSLATORS`` comment on the line immediately before the translatable string.
118+
The comment is extracted by the translation tooling and shown to translators in Transifex.
119+
120+
**When to add one:**
121+
122+
- 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.
124+
- The string describes a UI element or workflow that is not obvious from the text alone.
125+
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]);
160+
161+
Keep comments factual and brief. State what the placeholder contains and where the string appears. Do not repeat the string itself.
162+
114163
Translatable strings
115164
--------------------
116165

0 commit comments

Comments
 (0)