You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: developer_manual/basics/front-end/l10n.rst
+44-18Lines changed: 44 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,10 @@ Translation
5
5
.. sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>, Kristof Hamann
6
6
7
7
Nextcloud provides mechanisms for internationalization (make an application translatable) and localization (add translations for specific languages). This section provides detailed instructions for both aspects.
8
-
9
-
10
-
Make text translatable
11
-
----------------------
12
-
13
8
In order to make your app translatable (internationalization), you should use Nextcloud's methods for translating strings. They are available for both the server-side (PHP, Templates) as well as for the client-side (JavaScript).
14
9
15
-
16
10
PHP
17
-
^^^
11
+
---
18
12
19
13
If localized strings are used in the backend code, simply inject the ``\OCP\IL10N`` class into your service via type hinting it in the constructor. You will automatically get the language object containing the translations of your app:
20
14
@@ -24,7 +18,7 @@ If localized strings are used in the backend code, simply inject the ``\OCP\IL10
24
18
<?php
25
19
namespace OCA\MyApp\Service;
26
20
27
-
use \OCP\IL10N;
21
+
use OCP\IL10N;
28
22
29
23
30
24
class AuthorService {
@@ -76,24 +70,54 @@ Strings can then be translated in the following way:
76
70
}
77
71
78
72
Correct plurals
79
-
"""""""""""""""
73
+
^^^^^^^^^^^^^^^
80
74
81
75
If you use a plural, you **must** also use the ``%n`` placeholder. The placeholder defines the plural and the word without the number preceding is wrong. If you don't know/have a number for your translation, e.g. because you don't know how many items are going to be selected, just use an undefined plural. They exist in every language and have one form. They do not follow the normal plural pattern.
In every template the global variable **$l** can be used to translate the strings using its methods **t()** and **n()**:
99
123
@@ -108,7 +132,7 @@ For the right date format use ``<?php p($l->l('date', time()));?>``.
108
132
109
133
110
134
JavaScript
111
-
^^^^^^^^^^
135
+
----------
112
136
113
137
There are global functions **t()** and **n()** available for translating strings in javascript code. They differ a bit in terms of usage compared to php:
114
138
@@ -125,12 +149,12 @@ There are global functions **t()** and **n()** available for translating strings
125
149
126
150
127
151
Important notes
128
-
^^^^^^^^^^^^^^^
152
+
---------------
129
153
130
154
Please also look through the following steps to improve your strings and make them better translatable by others
131
155
132
156
Improving your translations
133
-
"""""""""""""""""""""""""""
157
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
134
158
135
159
You shall **never split** sentences and **never concatenate** two translations (e.g. "Enable" and "dark mode" can not be combined to "Enable dark mode", because languages might have to use different cases)! Translators lose the context and they have no chance to possibly re-arrange words/parts as needed.
136
160
@@ -169,8 +193,10 @@ But there is one last problem with this. In case the language has to turn things
169
193
170
194
This allows translators to have the cloudlink before the browselink in case the language is e.g. right-to-left.
171
195
172
-
Hints
173
-
"""""
196
+
.. _Hints:
197
+
198
+
Provide context hints for translators
199
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174
200
175
201
In case some translation strings may be translated wrongly because they have multiple meanings, you can add hints which will be shown in the Transifex web-interface:
176
202
@@ -226,8 +252,6 @@ Adding translations
226
252
227
253
Nextcloud's translation system is powered by `Transifex <https://www.transifex.com/nextcloud/>`_. To start translating sign up and enter a group. If your community app should be translated by the `Nextcloud community on Transifex <https://www.transifex.com/nextcloud/nextcloud/dashboard/>`_ just follow the setup section below.
228
254
229
-
230
-
231
255
Translation tool
232
256
^^^^^^^^^^^^^^^^
233
257
@@ -248,7 +272,9 @@ Setup of the transifex sync
248
272
^^^^^^^^^^^^^^^^^^^^^^^^^^^
249
273
250
274
To setup the transifex sync within the Nextcloud community you need to add first the
251
-
transifex config to your app folder at :file:`.tx/config` (please replace **MYAPP** with your apps id)::
275
+
transifex config to your app folder at :file:`.tx/config` (please replace **MYAPP** with your apps id):
0 commit comments