|
| 1 | +.. _Translation setup: |
| 2 | + |
| 3 | +================= |
| 4 | +Translation setup |
| 5 | +================= |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +Translation tool |
| 10 | +---------------- |
| 11 | + |
| 12 | +.. note:: |
| 13 | + |
| 14 | + 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. |
| 15 | + |
| 16 | +The `translation tool <https://github.com/nextcloud/docker-ci/tree/master/translations/translationtool>`_ scrapes the source code for method calls to ``t()`` |
| 17 | +or ``n()`` to extract the strings that should be translated. If you check |
| 18 | +in minified JS code for example then those method names are also quite |
| 19 | +common and could cause wrong extractions. For this reason we allow to |
| 20 | +specify a list of files that the translation tool will not scrape for |
| 21 | +strings. You simply need to add a file named :file:`.l10nignore` into |
| 22 | +the root folder of your app and specify the files one per line:: |
| 23 | + |
| 24 | + # compiled vue templates |
| 25 | + js/bruteforcesettings.js |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +Setup of the transifex sync |
| 30 | +--------------------------- |
| 31 | + |
| 32 | +Transifex configuration ``.tx/config`` |
| 33 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 34 | + |
| 35 | +To setup the transifex sync within the Nextcloud community you need to add first the |
| 36 | +transifex config to your app folder at :file:`.tx/config` (please replace ``MYAPP`` with your apps id): |
| 37 | + |
| 38 | +.. code-block:: ini |
| 39 | +
|
| 40 | + [main] |
| 41 | + host = https://www.transifex.com |
| 42 | + lang_map = hu_HU: hu, nb_NO: nb, sk_SK: sk, th_TH: th, ja_JP: ja, bg_BG: bg, cs_CZ: cs, fi_FI: fi |
| 43 | +
|
| 44 | + [o:nextcloud:p:nextcloud:r:{{APPID}}] |
| 45 | + file_filter = translationfiles/<lang>/{{APPID}}.po |
| 46 | + source_file = translationfiles/templates/{{APPID}}.pot |
| 47 | + source_lang = en |
| 48 | + type = PO |
| 49 | +
|
| 50 | +Then create a folder :file:`l10n` and a file :file:`l10n/.gitkeep` to create an |
| 51 | +empty folder which later holds the translations. |
| 52 | + |
| 53 | +Branch selection ``.tx/backport`` |
| 54 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 55 | + |
| 56 | +The bot will run every night and only push commits to the following branches branch once there is an update to the translation: |
| 57 | + |
| 58 | +* main |
| 59 | +* master |
| 60 | +* stableX (X being the recent 3 versions of Nextcloud Server) |
| 61 | + |
| 62 | +You can overwrite this list by creating a file ``.tx/backport`` in your repository with the following content:: |
| 63 | + |
| 64 | + develop stable |
| 65 | + |
| 66 | +That would sync the translations for the branches (``main`` and ``master`` are added automatically): |
| 67 | + |
| 68 | +* main |
| 69 | +* master |
| 70 | +* develop |
| 71 | +* stable |
| 72 | + |
| 73 | +Excluding files ``.l10nignore`` |
| 74 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 75 | + |
| 76 | +Add one more file called :file:`.l10nignore` in root of the repository and the files and folders to ignore for translations. |
| 77 | +This should be used to exclude files that create false-positive translations, such as: |
| 78 | + |
| 79 | +- Compiled JavaScript files ``js/`` |
| 80 | +- 3rd-party PHP dependencies ``vendor/`` |
| 81 | +- Non-shipped files and documentation ``docs/`` |
| 82 | + |
| 83 | +Validate source strings |
| 84 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 85 | + |
| 86 | +After finishing the setup, you can validate the translation source strings which outlines some common mistakes. |
| 87 | +Clone the `nextcloud/docker-ci <https://github.com/nextcloud/docker-ci/>`_ repository and afterwards run the following script: |
| 88 | + |
| 89 | +.. code:: sh |
| 90 | +
|
| 91 | + bash translations/validateSyncSetup.sh Owner Repository |
| 92 | +
|
| 93 | +Repository permissions |
| 94 | +^^^^^^^^^^^^^^^^^^^^^^ |
| 95 | +Now the GitHub account `@nextcloud-bot <https://github.com/nextcloud-bot>`_ needs to get ``write`` access to your repository. |
| 96 | +You can invite it from your repository settings:: |
| 97 | + |
| 98 | + https://github.com/<user-name>/<repo-name>/settings/access |
| 99 | + |
| 100 | +After sending the invitation, please `open a ticket using the "Request translations" template <https://github.com/nextcloud/docker-ci/issues/new/choose>`_. |
| 101 | + |
| 102 | +.. attention:: |
| 103 | + |
| 104 | + In general you should enable the |
| 105 | + `protected branches feature <https://help.github.com/articles/configuring-protected-branches/>`_ |
| 106 | + for default and stable branches. If you do that, you need to grant the |
| 107 | + `@nextcloud-bot <https://github.com/nextcloud-bot>`_ ``admin`` permissions and allow administrators to bypass the protection. |
| 108 | + This feature however is only possible for repositories owned by organizations, not in repositories owned by individuals! |
| 109 | + You can `create your own organization <https://docs.github.com/en/organizations/collaborating-with-groups-in-organizations/creating-a-new-organization-from-scratch>`_ |
| 110 | + |
| 111 | +If you need help just `open a ticket with the request <https://github.com/nextcloud/docker-ci/issues/new/choose>`_ |
| 112 | +and we can also guide you through the steps. |
| 113 | + |
| 114 | +.. _manual-translation: |
| 115 | + |
| 116 | +Manual translation |
| 117 | +------------------ |
| 118 | + |
| 119 | +If Transifex is not the right choice or the app is not accepted for translation, |
| 120 | +generate the gettext strings by yourself by executing our |
| 121 | +`translation tool <https://github.com/nextcloud/docker-ci/tree/master/translations/translationtool>`_ |
| 122 | +in the app folder:: |
| 123 | + |
| 124 | + |
| 125 | + cd /srv/http/nextcloud/apps/myapp |
| 126 | + translationtool.phar create-pot-files |
| 127 | + |
| 128 | +The translation tool requires ``gettext``, installable via:: |
| 129 | + |
| 130 | + apt-get install gettext |
| 131 | + |
| 132 | +The above tool generates a template that can be used to translate all strings |
| 133 | +of an app. This template is located in the folder :file:`translationfiles/template/` with the |
| 134 | +name :file:`myapp.pot`. It can be used by your favored translation tool such |
| 135 | +as `Poedit <https://poedit.net>`_. It then creates a :file:`.po` file. |
| 136 | +The :file:`.po` file needs to be placed in a folder named like the language code |
| 137 | +with the app name as filename - for example :file:`translationfiles/es/myapp.po`. |
| 138 | +After this step the tool needs to be invoked to transfer the po file into our |
| 139 | +own fileformat that is more easily readable by the server code:: |
| 140 | + |
| 141 | + translationtool.phar convert-po-files |
| 142 | + |
| 143 | +Now the following folder structure is available:: |
| 144 | + |
| 145 | + myapp/l10n |
| 146 | + |-- es.js |
| 147 | + |-- es.json |
| 148 | + myapp/translationfiles |
| 149 | + |-- es |
| 150 | + | |-- myapp.po |
| 151 | + |-- templates |
| 152 | + |-- myapp.pot |
| 153 | + |
| 154 | +You then just need the :file:`.json` and :file:`.js` files for a working localized app. |
0 commit comments