example | ||
locale | ||
.gitignore | ||
LICENSE.md | ||
ols.json | ||
README.md |
Odin Locale Library
Note
This project targets the latest release of Odin: checked with Odin version 2024-08. Compatibilty with older version of Odin is purely casual!
An experimental Odin libray to manage locale informations.
Inspired by findlocale C library
Caution: this project is a way for me to familiarise with Odin while realising something relatively small but still potentially useful. Do not take it as an example of anything more serious than that!
Key Features:
- Detect active process locale subtags.
- Normalise the locale according to IANA indications: 'promotion' of extended language subtags to primary, removing default script indications and so on.
- Generate a localised message catalogue file name from the detected locale subtags and a file name pattern.
- Parsing the 'correct' message catalogue directly from the locale (without passing via an explicit file name), with automatic selection of the appropriate pluraliser (for 200+ most common languages).
- 'Generalise' the looked for locale message catalogue by removing locale subtags from the most specific to the most general and ultimately defaulting to 'en' locale.
- Set the major locale subtags respecting the constrains among themselves.
Limitations:
- Working under Linux is actively tested, testing under Windows is occasional and testing other OSes relies on the kindness of other users!
Installing
Project-specific installation
-
Create a directory named
libs
in the root of your project. -
Copy the
locale
directory (with all its files) of this library in the aforementionedlibs
directory by any way available to you (fromgit submodule add
to manual file copying...). -
You can now import this library in your source file as follows:
import localelib "libs/locale"
Alternatively, you may place this library wherever you want (for instance in a
git-cloned directory) and import it in your sources using the full relative path
from your sources to the library locale
directory: this will not be portable
to other machines or platforms, though (not recommended if you are developing a
library other developers may re-use)
Odin-wide installation
To make the library directly available to all your Odin projects:
-
Copy the
locale
directory (with all its files) of this library in theshared
directory of your Odin installation. -
You can now import this library in whatever Odin source file as follows:
import localelib "shared:locale"
In both cases the localelib
label can be replaced with any identifier of your
liking which does not conflict with existing identifiers.