-
Notifications
You must be signed in to change notification settings - Fork 2.5k
i18n
Wrap translatable strings with _()
e.g. _('string to translate')
and the i18n-scan.pl
and friends will correctly identify these strings as they do with all the existing translations.
If you have multi line strings you can split them with concatenation:
var mystr = _('this string will translate ' +
'correctly even though it is ' +
'a multi line string!);
You may also use line continuations \
syntax:
var mystr = _('this string will translate \
correctly even though it is \
a multi line string');
Usually if you have multiple sentences you may with to use a line break and you need to use the `
HTML tag:
var mystr = _('Port number.<br />' +
'E.g. 80 for HTTP');
To simplify a job for translators it may be better to split into separate keys without the `
:
var mystr = _('Port number.') + <br />' +
_('E.g. 80 for HTTP');
If you have links in then try to move attributes out of a translation key like:
var mystr = _('For further information <a %s>check the wiki</a>')
.format('href="https://openwrt.org/docs/" target="_blank" rel="noreferrer"')
This will generate a full link with HTML For further information <a href="https://openwrt.org/docs/" target="_blank" rel="noreferrer">check the wiki</a>
. The noreferrer
is important when making a link that is opened in a new tab (target="_blank"
).
Use the <%: text to translate %>
as documented on Templates
As hinted at in the Templates doc, %: is actually invoking a translate()
function. In most controller contexts, this is already available for you, but if necessary, is available for include in luci.i18n.translate
Translations are saved in the folder po/
within each individual LuCI component directory, e.g. applications/luci-app-firewall/po/
.
You find the reference in po/templates/<package>.pot
.
The actual translation files can be found at po/[lang]/[package].po
.
In order to use the commands below you need to have the gettext
utilities (msgcat
, msgfmt
, msgmerge
) installed on your system.
On Debian/Ubuntu you can install with sudo apt install gettext
.
If you want to rebuild the translations after you made changes to a package this is an easy way:
./build/i18n-scan.pl applications/[application] > applications/[application]/po/templates/[application_basename].pot
./build/i18n-update.pl applications/[application]/po
Example:
./build/i18n-scan.pl applications/luci-app-firewall > applications/luci-app-firewall/po/templates/firewall.pot
./build/i18n-update.pl applications/luci-app-firewall/po
note that the directory argument can be omitted for i18n-update.pl
to update all apps.
Some packages share translation files, in this case you need to scan through all their folders. The first command from above should then be:
./build/i18n-scan.pl applications/[package-1] applications/[package-2] applications/[package-n] > [location of shared template]/[application].pot
Note: The translation catalog for the base system covers multiple components, use the following commands to update it:
./build/mkbasepot.sh
./build/i18n-update.pl
The *.po
files are big so Luci needs them in a compact compiled LMO format.
Luci reads *.lmo
translations from /usr/lib/lua/luci/i18n/
folder.
E.g. luci-app-acl
has a Arabic translation in luci-i18n-acl-ar
package that installs /usr/lib/lua/luci/i18n/acl.ar.lmo
file.
In order to quickly convert a single .po
file to .lmo
file for testing on the target system use the po2lmo
utility.
You will need to compile it from the luci-base
module:
$ cd modules/luci-base/src/
$ make po2lmo
$ ./po2lmo
Usage: ./po2lmo input.po output.lmo
Now you can compile and upload translation:
./po2lmo ../../../applications/luci-app-acl/po/ar/acl.po ./acl.ar.lmo
scp ./acl.ar.lmo [email protected]:/usr/lib/lua/luci/i18n/
You can change language in System /Language and Style and check the translation.