Nextcloud's translation system is powered by `Transifex <https://explore.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://explore.transifex.com/nextcloud/>`_ just follow the setup section below.
Translation tool
----------------
..note::
The tool-based translation currently only supports repositories hosted on ``github.com``. If your app is hosted elsewhere, you can try to follow the :ref:`manual-translation` instead.
The `translation tool <https://github.com/nextcloud/docker-ci/tree/master/translations/translationtool>`_ scrapes the source code for method calls to ``t()``
or ``n()`` to extract the strings that should be translated. If you check
in minified JS code for example then those method names are also quite
common and could cause wrong extractions. For this reason we allow to
specify a list of files that the translation tool will not scrape for
strings. You simply need to add a file named :file:`.l10nignore` into
the root folder of your app and specify the files one per line::
# compiled vue templates
js/bruteforcesettings.js
Setup of the transifex sync
---------------------------
Transifex configuration ``.tx/config``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To setup the transifex sync within the Nextcloud community you need to add first the
transifex config to your app folder at :file:`.tx/config` (please replace ``MYAPP`` with your apps id):
After sending the invitation, please `open a ticket using the "Request translations" template <https://github.com/nextcloud/docker-ci/issues/new/choose>`_.
for default and stable branches. If you do that, you need to grant the
`@nextcloud-bot <https://github.com/nextcloud-bot>`_``admin`` permissions and allow administrators to bypass the protection.
This feature however is only possible for repositories owned by organizations, not in repositories owned by individuals!
You can `create your own organization <https://docs.github.com/en/organizations/collaborating-with-groups-in-organizations/creating-a-new-organization-from-scratch>`_
If you need help just `open a ticket with the request <https://github.com/nextcloud/docker-ci/issues/new/choose>`_
and we can also guide you through the steps.
.._manual-translation:
Manual translation
------------------
If Transifex is not the right choice or the app is not accepted for translation,
generate the gettext strings by yourself by executing our
..sectionauthor:: Bernhard Posselt <dev@bernhard-posselt.com>, Kristof Hamann
Nextcloud provides mechanisms for internationalization (make an application translatable) and localization (add translations for specific languages). This section provides detailed instructions for both aspects.
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).
PHP
---
PHP Backend
-----------
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:
@@ -16,18 +18,10 @@ If localized strings are used in the backend code, simply inject the ``\OCP\IL10
..code-block:: php
<?php
namespace OCA\MyApp\Service;
use OCP\IL10N;
class AuthorService {
/** @var IL10N */
private $l;
public function __construct(IL10N $l) {
$this->l = $l;
public function __construct(
private \OCP\IL10N $l,
) {
}
…
@@ -38,13 +32,12 @@ Strings can then be translated in the following way:
..code-block:: php
<?php
…
class AuthorService {
…
public function getLanguageCode() {
// Get the language code of the current language
return $this->l->getLanguageCode();
}
@@ -61,32 +54,14 @@ Strings can then be translated in the following way:
public function getAuthors($count, $city) {
// Translation with plural
return $this->l->n(
'%n author is currently in the city %1$s', // singular string
'%n authors are currently in the city %1$s', // plural string
'%n author is currently in the city %1$s', // singular string
'%n authors are currently in the city %1$s', // plural string
$count, // number to decide which plural to use
[$city] // further parameters are possible
);
}
}
Correct plurals
^^^^^^^^^^^^^^^
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.
For the right date format use ``<?php p($l->l('date', time()));?>``.
// Text with a placeholder
<div><?php p($l->t('Show files of %1$s', [$user])); ?></div>
// Date string
<em><?php p($l->l('date', time())); ?></em>
JavaScript / TypeScript / Vue
-----------------------------
JavaScript
----------
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:
There are global functions ``t()`` and ``n()`` available for translating strings in javascript code.
If your app is build, you can import the translation functions from the `@nextcloud/l10n package <https://github.com/nextcloud-libraries/nextcloud-l10n>`_.
They differ a bit in terms of usage compared to php:
* First argument is the appId e.g. ``'myapp'``
* Placeholders (apart from the count in plurals) use single-mustache brackets with meaning-full descriptors.
@@ -146,30 +119,110 @@ There are global functions **t()** and **n()** available for translating strings
t('myapp', '{name} is available. Get {linkstart}more information{linkend}', {name: 'Nextcloud 16', linkstart: '<a href="...">', linkend: '</a>'});
n('myapp', 'Import %n calendar into {collection}', 'Import %n calendars into {collection}', selectionLength, {collection: 'Nextcloud'});
Guidelines
----------
Please also look through the following hints to improve your strings and make them better translatable by the community
and therefore improving the experience for non-english users.
Important notes
---------------
Dos and Don'ts
^^^^^^^^^^^^^^
Please also look through the following steps to improve your strings and make them better translatable by others
..list-table::
:header-rows:1
* - Bad
- Good
- Description
* - ``´`` or ``’``
- ``'``
- Use ascii single quote
* - ``Loading...``
- ``Loading …``
- | Use unicode triple-dot character.
| Add a space before the triple-dot when trimming a sentence instead of a word.
* - Don't
- Do not
- Using the spelled out version is easier to understand and makes translating easier.
* - Won't
- Will not
- Using the spelled out version is easier to understand and makes translating easier.
* - Can not
- Cannot
- Using the combined version is easier to understand and makes translating easier.
* - id
- ID
- Full uppercase for shortcutting "identifier"
* - Users
- Accounts / People
- Use **accounts** when you refer to a profile/entity. Use **people** when referring to humans.
* - Admin / Administrator
- Administration
- | Refer to administration as a non-human organizational entity
| instead of a single or multiple persons.
* - Headline
- Headline:
- Include colons ``:`` in the translations as some languages add a space before the colon.
* - | " Leading space"
| "Trailing space "
- | "No leading space"
| "No trailing space"
- | Leading or trailing spaces mostly indicate that strings are concatenated.
| For translators it is often helpful to have all the content in a single translation,
| as order and references between words and sentences might get lost otherwise.
* - "Error:" $error
- "Error: %s"
- Instead of concatenating errors or part messages, make them a proper placeholder
Correct plurals
^^^^^^^^^^^^^^^
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.
/* BEST: Simple string with undefined plural not using any number in the string */
t('myapp', 'Import calendars')
Improving your translations
^^^^^^^^^^^^^^^^^^^^^^^^^^^
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.
Bad example:
Starting with the following example, improving it step by step:
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.
Translators will translate:
* Select file from
* local filesystem
* ' or '
* cloud
* ``Select file from``
* ``local filesystem``
* ``or`` (with leading and trailing whitespace)
* ``cloud``
Translating these individual strings results in ``local filesystem`` and ``cloud`` losing case. The two white spaces surrounding ``or`` will get lost while translating as well. For languages that have a different grammatical order it prevents the translators from reordering the sentence components.
@@ -179,13 +232,21 @@ So the following code is a bit better, but suffers from another issue:
<?php p($l->t('Select file from <a href="#" id="browselink">local filesystem</a> or <a href="#" id="cloudlink">cloud</a>'));?>
Step 2: HTML Markup
"""""""""""""""""""
In this case the translators can re-arrange as they like, but have to deal with your markup and can mess it up easily. It is better to **keep the markup out** of your code, so the following translation is even better:
..code-block:: php
<?php p($l->t('Select file from %slocal filesystem%s or %scloud%s', ['<a href="#" id="browselink">', '</a>', '<a href="#" id="cloudlink">', '</a>']));?>
But there is one last problem with this. In case the language has to turn things around, your code will still insert the parameters in the given order and they can not re-order them. To prevent this last hurdle simply **use positioned placeholders** like ``%1$s``:
But there is one last problem with this.
Step 3: Placeholders
""""""""""""""""""""
In case the language has to turn things around, your code will still insert the parameters in the given order and they can not re-order them. To prevent this last hurdle simply **use positioned placeholders** like ``%1$s``:
..code-block:: php
@@ -198,9 +259,13 @@ This allows translators to have the cloudlink before the browselink in case the
Provide context hints for translators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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:
In case some translation strings may be translated wrongly because they have multiple meanings.
Especially translations strings that only contain a single word often result in problems.
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``.
The added hints will be shown in the Transifex web-interface:
**PHP**
PHP
"""
..code-block:: php
@@ -213,14 +278,16 @@ In case some translation strings may be translated wrongly because they have mul
</li>
</ul>
**Javascript**
JavaScript / TypeScript
"""""""""""""""""""""""
..code-block:: javascript
// 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
var copyNameLocalized = t('files', 'copy');
**Vue**
Vue
"""
This covers vue html templates in vue sfc components.
For vue js code, see the javascript section.
@@ -232,21 +299,24 @@ For vue js code, see the javascript section.
{{ t('forms', 'Required') }}
</NcActionCheckbox>
**C++ (Qt)**
C++ (Qt) / Desktop client
"""""""""""""""""""""""""
..code-block:: c++
//: Example text: "Progress of sync process. Shows the currently synced filename"
@@ -256,123 +326,9 @@ For vue js code, see the javascript section.
Adding translations
-------------------
Nextcloud's translation system is powered by `Transifex <https://explore.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://explore.transifex.com/nextcloud/>`_ just follow the setup section below.
The steps how to set up translations for an app have been moved to it's own page in the "App development" chapter: :ref:`Translation setup`
Translation tool
^^^^^^^^^^^^^^^^
Testing translations
--------------------
The translation tool scrapes the source code for method calls to **t()**
or **n()** to extract the strings that should be translated. If you check
in minified JS code for example then those method names are also quite
common and could cause wrong extractions. For this reason we allow to
specify a list of files that the translation tool will not scrape for
strings. You simply need to add a file named :file:`.l10nignore` into
the root folder of your app and specify the files one per line::
# compiled vue templates
js/bruteforcesettings.js
Setup of the transifex sync
^^^^^^^^^^^^^^^^^^^^^^^^^^^
To setup the transifex sync within the Nextcloud community you need to add first the
transifex config to your app folder at :file:`.tx/config` (please replace **MYAPP** with your apps id):
After sending the invitation, please `open a ticket using the "Request translations" template <https://github.com/nextcloud/docker-ci/issues/new/choose>`_.
The bot will run every night and only push commits to the following branches branch once there is an update to the translation:
* main
* master
* stableX (X being the recent 3 versions of Nextcloud Server)
You can overwrite this list by creating a file ``.tx/backport`` in your repository with the following content::
develop stable
That would sync the translations for the branches (``main`` and ``master`` are added automatically):
but that is only possible for repositories owned by organizations.
You can `create your own organization <https://docs.github.com/en/organizations/collaborating-with-groups-in-organizations/creating-a-new-organization-from-scratch>`_
If you need help just `open a ticket with the request <https://github.com/nextcloud/docker-ci/issues/new/choose>`_
and we can also guide you through the steps.
.._manual-translation:
Manual translation
^^^^^^^^^^^^^^^^^^
If Transifex is not the right choice or the app is not accepted for translation,
generate the gettext strings by yourself by executing our
The translation tool requires **gettext**, installable via::
apt-get install gettext
The above tool generates a template that can be used to translate all strings
of an app. This template is located in the folder :file:`translationfiles/template/` with the
name :file:`myapp.pot`. It can be used by your favored translation tool which
then creates a :file:`.po` file. The :file:`.po` file needs to be placed in a
folder named like the language code with the app name as filename - for example
:file:`translationfiles/es/myapp.po`. After this step the tool needs to be invoked to
transfer the po file into our own fileformat that is more easily readable by
the server code::
translationtool.phar convert-po-files
Now the following folder structure is available::
myapp/l10n
|-- es.js
|-- es.json
myapp/translationfiles
|-- es
| |-- myapp.po
|-- templates
|-- myapp.pot
You then just need the :file:`.json` and :file:`.js` files for a working localized app.
You can use the query parameter ``forceLanguage`` to force a specific language for a web request (API or frontend). See :ref:`Forcing language for a given call<api-force-language>`.
This API allows you to listen to :doc:`Nextcloud events <../../../basics/events>`.
This API allows you to listen to :ref:`Nextcloud events <Events>`.
Currently only a **limited** number of events are supported.
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.