On this page
  1. set
  2. current
  3. available
  4. name
  5. translate

rmp::lang

namespace #include <rmp/text.h>

rmp::Text and rmp::lang — the game in more than one language.

rmp::ui::button("Play");                              // translated
rmp::ui::text(rmp::Text("{count} gem|{count} gems", { { "count", gems } }));
rmp::ui::button(rmp::Text("Open", { .context = "door" }));
rmp::lang::set("es");

Every text the framework is handed is an rmp::Text. A literal written in the call becomes one by itself, and it is TRANSLATED: its own words are the key looked up in the game's tables (resources/lang.tsv, resources/lang/<code>.tsv, [lang] in raylib_multiplatform.toml), and what is not there is shown as written. A string made at runtime — a std::string, TextFormat()'s answer — is shown as it is and never looked up: it has no stable key. A value that changes goes into a placeholder instead, so the key stays the same: rmp::Text("Score: {score}", { { "score", score } }).

Placeholders are {name}; {{ and }} are a brace. A text with a number in it can have plural forms, separated by |, in the order of the language's CLDR categories: English and Spanish one|other, Russian and Polish one|few|many|other, Japanese and Chinese other alone. The first number among the arguments chooses. The language is the player's system language, the one rmp::lang::set() chose (and saved), or [lang] default; es-MX falls back to es, then to the default, then to the text as written.

Right-to-left and complex shaping (Arabic, Hebrew, the Indic scripts) are not supported: their text is drawn left to right, letter by letter.

set

void set(std::string_view code)

Change the language, everywhere at once: the next frame draws in it. "es", "es-MX", "ja". Saved, so the next run starts in it. An unknown code shows the default language's texts.

current

std::string current()

The language in use.

available

std::vector<std::string> available()

The languages a language menu offers: [lang] languages, in its order, or, with no list, every column and file the tables have.

name

std::string name(std::string_view code)

A language's own name, for that menu: the table's row "language.name" in that language's column, or the code when the table has none.

translate

std::string translate(std::string_view key, std::string_view context = {})

The text key in the current language, as rmp::Text would draw it.