Overview
Project Goals
gettext-header is a modern C++26 reimplementation of the GNU gettext
runtime library (libintl). It provides:
A C++ header-only library — just
#include <gettext/gettext.hpp>, no linking required. All functions live in theintlnamespace.A C-compatible shared library (
libintl.so) — drop-in replacement for GNU gettext’slibintl.A C-compatible static library (
libintl.a) — for static linking.A msgfmt replacement — compiles
.pofiles to.mobinary format, replacing the need for GNU gettext tools.
Architecture
The library is structured as:
include/
gettext/
gettext.hpp ← Public C++ API (intl:: namespace)
detail/
mo_parser.hpp ← MO binary file reader
po_parser.hpp ← PO text file parser
plural_eval.hpp ← Plural-Forms expression evaluator
catalog.hpp ← In-memory translation catalog
locale_resolver.hpp ← Locale/env var resolution
charset.hpp ← iconv charset conversion
mo_writer.hpp ← MO binary file writer
libintl.h ← C API header
src/
libintl.cpp ← C API implementation
msgfmt.cpp ← msgfmt tool
Data Flow
When intl::gettext("Hello") is called:
The current domain and locale are resolved from global state and environment variables (
LANGUAGE,LC_ALL,LC_MESSAGES,LANG).A
.mofile path is constructed:<base_dir>/<locale>/LC_MESSAGES/<domain>.moThe MO file is loaded into memory and parsed.
The msgid is looked up via hash table or binary search.
For plural forms, the
Plural-Formsexpression is evaluated.The translated string is returned, or the original msgid if not found.
License
GNU Affero General Public License v3 (AGPL-3.0).