looper/backends/ui/imgui/translation.h

26 lines
1.1 KiB
C
Raw Normal View History

2023-07-24 23:13:47 -07:00
#pragma once
#include <libintl.h>
#include <string>
#include <vector>
// Based on the code found in gettext.h, but without any additional things we don't need.
2023-07-24 23:13:47 -07:00
inline static const char *gettext_ctx(const char *ctx, const char *msgid) {
std::string msg_ctxt_id = (std::string(ctx) + std::string("\004") + std::string(msgid));
const char *translation = gettext(msg_ctxt_id.c_str());
if (std::string(translation) == msg_ctxt_id) {
2023-07-24 23:13:47 -07:00
return msgid;
} else {
return translation;
}
}
#define _TR(str) gettext(str)
#define _TR_CTX(ctx, str) gettext_ctx(ctx, str)
#define _TRS(str) std::string(_TR(str))
#define _TRS_CTX(ctx, str) std::string(_TR_CTX(ctx, str))
#define _TRIS(icon, str) (std::string(icon) + _TRS(str))
#define _TRI(icon, str) _TRIS(icon, str).c_str()
#define _TRIS_CTX(icon, ctx, str) (std::string(icon) + _TRS_CTX(ctx, str))
2023-07-25 07:56:56 -07:00
#define _TRI_CTX(icon, ctx, str) _TRIS_CTX(icon, ctx, str).c_str()
#define CURRENT_LANGUAGE setlocale(LC_MESSAGES, NULL)
// The value required to set the operating system's default language.
#define DEFAULT_LANG ""
#define SET_LANG(lang) setlocale(LC_MESSAGES, lang)