44 lines
1.6 KiB
Markdown
44 lines
1.6 KiB
Markdown
# 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
|
|
|
|
```d
|
|
import gettext;
|
|
import gettext_syslocale;
|
|
|
|
void main(string[] args) {
|
|
mixin(gettext.main);
|
|
initializeSystemLocale(args[0].baseName);
|
|
writeln(tr!"Hello, world!");
|
|
}
|
|
```
|
|
|
|
1. Include `mixin(gettext.main)` in your `main` function.
|
|
2. Call `initializeSystemLocale` with the program name (e.g., `args[0].baseName`).
|
|
3. Use `tr` for translatable strings, as provided by the `gettext` library.
|
|
|
|
## Requirements
|
|
|
|
- D compiler (e.g., DMD, LDC).
|
|
- The `gettext` library for D, including the `mofile` 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.
|