39 lines
1.2 KiB
Markdown
39 lines
1.2 KiB
Markdown
|
# Memo to work with gettext
|
||
|
|
||
|
## As a developer
|
||
|
|
||
|
Extract messages to be translated from the source files and into a Portable Object Template file:
|
||
|
```shell
|
||
|
xgettext --from-code=UTF-8 --no-wrap -d messages -p locales/ *.php */*.php */*/*.php
|
||
|
mv locales/messages.po locales/messages.pot
|
||
|
```
|
||
|
|
||
|
Merge messages into existing Portable Objects:
|
||
|
```shell
|
||
|
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
|
||
|
|
||
|
```shell
|
||
|
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
|
||
|
* 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).
|
||
|
|
||
|
## As an administrator
|
||
|
|
||
|
To compile Portable Objects into Machine Objects:
|
||
|
```shell
|
||
|
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 PHP gettext extension, so PHP-FPM needs to be restarted to update translations.
|