An Odin package to manage locale
Find a file
2024-08-14 19:55:46 +02:00
example Version 0.2.0: 2024-07-07 17:28:00 +02:00
locale Version 0.2.0: 2024-07-07 17:28:00 +02:00
.gitignore Version 0.2.0: 2024-07-07 17:28:00 +02:00
LICENSE.md Refactor to use array indices rather than literal strings in the Locale fields. 2024-05-06 17:24:38 +02:00
ols.json Initial commit 2024-04-22 08:21:23 +02:00
README.md Update README.md 2024-08-14 19:55:46 +02:00

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

  1. Create a directory named libs in the root of your project.

  2. Copy the locale directory (with all its files) of this library in the aforementioned libs directory by any way available to you (from git submodule add to manual file copying...).

  3. 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:

  1. Copy the locale directory (with all its files) of this library in the shared directory of your Odin installation.

  2. 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.