Crate glossa

source ·
Expand description


Glossa is a language localisation library.



It can be divided into two categories.

  • Const map: Load localisation data efficiently through constant data.
    • Description: Convert configuration files into constant (const fn) Rust code at compile time and read constant data at runtime.
    • Pros: Efficient
    • Cons:
      • Requires codegen, which may result in some redundant code after expansion.
      • Currently only supports simple key-value (K-V) pairs.
  • Flunt
    • Description: Manage Fluent resources at runtime.
    • Pros: Fluent syntax may be more suitable for localisation.
    • Cons: Requires more resources than const map.

The former is just the simple K-V pair that uses some const maps from phf to store data. Because it’s simple, it’s efficient.

The two types of functionalities are independent of each other.

There are some functions that need to be used with glossa-codegen, which will not be described in detail here. If you want to find out more, go to the git repository for this project.


In fact, you should use your own localisation resources rather than glossa’s built-in locales().

It displays different content for different languages. If no relevant text is found, then it will automatically use the fallback chain.

    use glossa::{locales, GetText};
    let msg = locales().get_or_default("error", "text-not-found");
    let hello = locales()
        .get("test", "👋🌐")
        .expect("No localised text found. (map: test, key: 👋🌐)");





  • Load the localised resources of the HashMap.


  • Get text from localised resources.


  • The function creates a OnceCell named RES that can hold an instance of MapLoader. The OnceCell is used to ensure that the MapLoader instance is created only once and subsequent calls to locales return the same instance.

Type Definitions

  • Language Identifier
  • The default error type is GlossaError<'map>