init
This commit is contained in:
commit
97f78f7728
8 changed files with 218 additions and 0 deletions
44
README.md
Normal file
44
README.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
# 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.
|
Loading…
Add table
Add a link
Reference in a new issue