libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiTextTranslator.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiTextTranslator.h
5 ***************************************************************************/
6#pragma once
7
8#include <cstdint>
9#include <cstddef>
10
16{
17 public:
21 constexpr GuiTextTranslator() : magic(MAGIC), head(nullptr) {}
23
28 bool loadLanguage(const uint8_t* buffer, size_t size);
29
33 const char* getText(const char* msgid) const;
34
36 void clear();
37
38 private:
39 static constexpr uint32_t MAGIC = 0x47545254; // "GTRT": a live, intact translator
40
41 struct MSG
42 {
43 uint32_t id = 0;
44 char* msgstr = nullptr;
45 MSG* next = nullptr;
46 };
47
48 uint32_t magic; // MAGIC while alive; checked on lookup so a stomped object is caught early
49 MSG* head;
50
52 static uint32_t hashString(const char* str);
53 static char* expandEscape(const char* str);
54
56 const char* memFGets(char* dst, int maxlen, const char* src, const char* eof) const;
57
60 [[noreturn]] static void fatalCorruption(const GuiTextTranslator* self, const void* bad,
61 const void* from, uint32_t magicSeen);
63 void checkIntegrity(const MSG* node, const MSG* prev) const;
64
65 MSG* findMessage(uint32_t id) const;
66 MSG* setMessage(const char* msgid, const char* msgstr);
67};
Hashed msgid -> UTF-8 string table loaded from a single binary .lang blob (see loadLanguage()).
const char * getText(const char *msgid) const
Retrieves the translated UTF-8 string for a given ASCII message ID.
constexpr GuiTextTranslator()
constexpr on purpose: an instance defined at namespace scope is then constant-initialized (it is laid...
bool loadLanguage(const uint8_t *buffer, size_t size)
Loads and parses a translation file from a memory buffer.
void clear()
Clears the current translation dictionary and frees memory.