framework
framework copied to clipboard
Provide a package text domain loader
Description
In order to smooth package development and provide l10n and i18n support using gettext methods, it would be best that the framework defines a common function in order to load .mo
files.
Methods like load_plugin_textdomain
do not work as they require the package to be installed as a plugin. So instead, we should use the general function load_textdomain
and provide a generic package structure where to store the translation files. For example inside a package resources/languages
directory.
Now I'm not sure about best practice for the filename. Two options come to mind:
- Compose the file name using the "domain name" and "locale" like so:
textdomain-en_US.mo
- Organize by subdirectory using the "locale" and each directory contains one file based on domain:
en_US/textdomain.mo
The first option will contain all files into one languages
directory while the second options will contains many subdirectories based on locale with one file into each.
First option
+-- languages/
| +-- textdomain-en_US.mo
| +-- textdomain-en_US.po
| +-- textdomain-fr_FR.mo
| +-- textdomain-fr_FR.po
Second option
+-- languages/
| +-- en_US/
| +-- textdomain.mo
| +-- textdomain.po
| +-- fr_FR/
| +--textdomain.mo
| +--textdomain.po