A modern internationalization (i18n) library.

✨ Overview
P-E-R-R-Y i18n
is a lightweight, header-only
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>
class DefaultLocale :
public ILocale {
public:
virtual const std::string getSignUpTitle() const = 0;
virtual const std::string getSignInTitle() const = 0;
};
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"; }
};
i18n.setLocale("en");
std::cout << i18n.getLocale()->getSignInTitle() << std::endl;
}
std::tuple< LocaleEn, LocaleEs, LocaleFr, LocaleIt > SupportedLocales
Definition SupportedLocales.hpp:23
int main()
Definition TestCXX11.cpp:92
static I18n< T > & getInstance()
Get the I18n singleton instance.
Definition I18n.hpp:46
Base interface for all locale implementations.
Definition ILocale.hpp:34
virtual const std::string languageCode() const =0
Retrieve the two-letter language code of the locale.