P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches

Translation lookup, one catalogue per language. More...

Collaboration diagram for i18n:

Concepts

concept  IsTuple
 Using is_tuple specialisation this concept verify if it's a tuple.
concept  DerivedFrom
 DerivedFrom is accept supportedLocal class only.
concept  LocaleInterface
 Concept to constrain template parameters to valid locale interface and implementation.

Classes

class  I18n< T, typename >
 Internationalization manager for a specific locale type. More...
class  ILocale
 Base interface for all locale implementations. More...
struct  is_derived_from< T, B >
 Trait to check if a type T derives from a base B. More...
struct  all_derived< Base, Derived >
 Trait to check if all types in a pack are derived from a base type. More...
struct  all_derived< Base >
 If the pack of Derived types is empty, we trivially return true. This stops the recursion. More...
struct  all_derived< Base, First, Rest... >
 Uses std::is_base_of to check that First inherits from Base. Recursively evaluates the remaining Rest... types via all_derived. More...
struct  is_tuple< T >
 Detect whether a type is a std::tuple or not. More...
struct  is_tuple< std::tuple< Args... > >
 Trait to detect whether a type is a std::tuple. More...
struct  index_sequence< I >
 Base Type to represent a sequence of compile time indice. More...
struct  make_index_sequence_impl< N, I >
 recursive template to generate the sequence More...
struct  make_index_sequence_impl< 0, I... >
 when N = 0, stop recursion and define the type alias More...

Detailed Description

Translation lookup, one catalogue per language.

Two implementations behind the same surface : cxx11 and cxx20.

i18n

🌍 P-E-R-R-Y i18n

A modern internationalization (i18n) library.

Build Docs License


✨ Overview

P-E-R-R-Y i18n is a lightweight, header-only C++11 C++20 library for internationalization.
It provides a clean, type-safe way to define and switch between language locales at runtime.

Core goals:

  • 🧩 Strongly typed locales using concepts and type traits
  • ⚙️ System locale detection (macOS & Linux)
  • 🔄 Runtime locale switching
  • 🚀 Zero dependencies, header-only, C++20 concepts
  • ✅ Unit-tested with GoogleTest

🧱 Features

  • Detects the system locale (fr, en, es, …)
  • Fallback chain (system → en → first registered)
  • Singleton pattern for shared locale management
  • Compile-time locale registration with setSupportedLocales
  • Works with tuples or parameter packs

🧩 Example

#include "I18n.hpp"
#include "ILocale.hpp"
#include <tuple>
// Define your base locale interface
class DefaultLocale : public ILocale {
public:
virtual const std::string getSignUpTitle() const = 0;
virtual const std::string getSignInTitle() const = 0;
};
// Define concrete implementations
class LocaleEn : public DefaultLocale {
public:
const std::string languageCode() const override { return "en"; }
const std::string getSignUpTitle() const override { return "Sign Up"; }
const std::string getSignInTitle() const override { return "Sign In"; }
};
class LocaleFr : public DefaultLocale {
public:
const std::string languageCode() const override { return "fr"; }
const std::string getSignUpTitle() const override { return "Inscription"; }
const std::string getSignInTitle() const override { return "Connexion"; }
};
using SupportedLocales = std::tuple<LocaleEn, LocaleFr>
// Usage
int main() {
i18n.setSupportedLocales<SupportedLocales>();
//cpp `i18n.setSupportedLocales<LocaleEn, LocaleFr>();`
//set Locale over the default one -> 1st: system, 2nd: "en", 3rd: 1st_one
i18n.setLocale("en");
std::cout << i18n.getLocale()->getSignInTitle() << std::endl;
}
static I18n< T > & getInstance()
Get the I18n singleton instance.
Definition I18n.hpp:49
Base interface for all locale implementations.
Definition ILocale.hpp:37