1.6 KiB
1.6 KiB
gettext_syslocale
A D module that extends the gettext
library to support system locale detection and standard GNU/Linux translation paths.
Overview
The gettext_syslocale
module enhances the gettext
library by automatically selecting the system locale from environment variables (LC_ALL
, LC_MESSAGES
, LANG
) and loading translation .mo
files from standard GNU/Linux paths (/usr/share/locale/<language>/LC_MESSAGES/<programName>.mo
). It prioritizes full language codes (e.g., ru_RU
) before falling back to short codes (e.g., ru
).
Features
- Automatically detects the system locale.
- Searches for
.mo
files in/usr/share/locale/<language>/LC_MESSAGES/<programName>.mo
. - Checks full language codes (e.g.,
ru_RU
) before short codes (e.g.,ru
).
Usage
import gettext;
import gettext_syslocale;
void main(string[] args) {
mixin(gettext.main);
initializeSystemLocale(args[0].baseName);
writeln(tr!"Hello, world!");
}
- Include
mixin(gettext.main)
in yourmain
function. - Call
initializeSystemLocale
with the program name (e.g.,args[0].baseName
). - Use
tr
for translatable strings, as provided by thegettext
library.
Requirements
- D compiler (e.g., DMD, LDC).
- The
gettext
library for D, including themofile
module. .mo
translation files in/usr/share/locale/<language>/LC_MESSAGES/
.
Installation
Add gettext_syslocale.d
to your project and ensure the gettext
library is available. Compile with a D compiler supporting the gettext
library.
License
Boost License 1.0, consistent with the gettext
library.