2023-01-21 00:27:52 +00:00
|
|
|
# Translation with gettext
|
|
|
|
|
|
|
|
## As a developer
|
|
|
|
|
|
|
|
Extract messages to be translated from the source files and into a Portable Object Template file:
|
2023-03-09 00:35:30 +00:00
|
|
|
```shell
|
|
|
|
xgettext --from-code=UTF-8 --no-wrap -d messages -p locales/ *.php */*.php */*/*.php
|
2023-01-21 00:27:52 +00:00
|
|
|
mv locales/messages.po locales/messages.pot
|
|
|
|
```
|
|
|
|
|
|
|
|
Merge messages into existing Portable Objects:
|
2023-03-09 00:35:30 +00:00
|
|
|
```shell
|
2023-01-21 00:27:52 +00:00
|
|
|
msgmerge --no-wrap locales/fr/C/LC_MESSAGES/messages.po locales/messages.pot -o locales/fr/C/LC_MESSAGES/messages.po
|
|
|
|
```
|
|
|
|
|
|
|
|
## As a translator
|
|
|
|
|
|
|
|
### To start a new translation
|
|
|
|
|
2023-03-09 00:35:30 +00:00
|
|
|
```shell
|
2023-01-21 00:27:52 +00:00
|
|
|
mkdir -p locales/fr/C/LC_MESSAGES/
|
|
|
|
msginit -i locales/messages.pot -o locales/fr/C/LC_MESSAGES/messages.po
|
|
|
|
```
|
|
|
|
|
|
|
|
### To translate
|
|
|
|
|
|
|
|
Edit `locales/fr/C/LC_MESSAGES/messages.po` using either
|
|
|
|
* any text editor
|
2023-03-09 00:35:30 +00:00
|
|
|
* dedicated translation software like [Poedit](https://poedit.net/), [KDE's Lokalize](https://apps.kde.org/lokalize/) or [GNOME Translation Editor](https://wiki.gnome.org/Apps/Gtranslator).
|
2023-01-21 00:27:52 +00:00
|
|
|
|
|
|
|
## As an administrator
|
|
|
|
|
|
|
|
To compile Portable Objects into Machine Objects:
|
2023-03-09 00:35:30 +00:00
|
|
|
```shell
|
2023-01-21 00:27:52 +00:00
|
|
|
msgfmt locales/fr/C/LC_MESSAGES/messages.po -o locales/fr/C/LC_MESSAGES/messages.mo
|
|
|
|
```
|
|
|
|
|
|
|
|
Machine Objects files are kept in cache by the Gettext extension, so PHP-FPM needs to be restarted to update translations.
|