mirror of
https://github.com/monero-project/monero.git
synced 2024-12-25 21:19:27 +00:00
i18n: allow language to be passed as a parameter
If empty, it will still be fetched from the environment
This commit is contained in:
parent
0d09e15a1c
commit
0c1dae32b4
2 changed files with 7 additions and 5 deletions
|
@ -45,7 +45,7 @@ static std::map<std::string,std::string> i18n_entries;
|
||||||
// #define i18n_log(x) do { std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl; std::cout << std::flush; } while(0)
|
// #define i18n_log(x) do { std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl; std::cout << std::flush; } while(0)
|
||||||
#define i18n_log(x) ((void)0)
|
#define i18n_log(x) ((void)0)
|
||||||
|
|
||||||
static std::string get_language()
|
std::string i18n_get_language()
|
||||||
{
|
{
|
||||||
const char *e;
|
const char *e;
|
||||||
|
|
||||||
|
@ -111,9 +111,9 @@ static std::string utf8(const unsigned char *data, uint32_t len)
|
||||||
return std::string((const char *)data,len);
|
return std::string((const char *)data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i18n_set_language(const char *directory, const char *base)
|
int i18n_set_language(const char *directory, const char *base, std::string language)
|
||||||
{
|
{
|
||||||
std::string language, filename, contents;
|
std::string filename, contents;
|
||||||
const unsigned char *data;
|
const unsigned char *data;
|
||||||
size_t datalen;
|
size_t datalen;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
@ -128,7 +128,8 @@ int i18n_set_language(const char *directory, const char *base)
|
||||||
if (!directory || !base)
|
if (!directory || !base)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
language = get_language();
|
if (language.empty())
|
||||||
|
language = i18n_get_language();
|
||||||
filename = std::string(directory) + "/" + base + "_" + language + ".qm";
|
filename = std::string(directory) + "/" + base + "_" + language + ".qm";
|
||||||
i18n_log("Loading translations for language " << language);
|
i18n_log("Loading translations for language " << language);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
|
|
||||||
#define QT_TRANSLATE_NOOP(context,str) i18n_translate(str,context)
|
#define QT_TRANSLATE_NOOP(context,str) i18n_translate(str,context)
|
||||||
|
|
||||||
int i18n_set_language(const char *directory, const char *base);
|
std::string i18n_get_language();
|
||||||
|
int i18n_set_language(const char *directory, const char *base, std::string language = std::string());
|
||||||
const char *i18n_translate(const char *str, const std::string &context);
|
const char *i18n_translate(const char *str, const std::string &context);
|
||||||
static inline std::string get_default_i18n_context() { return std::string(); }
|
static inline std::string get_default_i18n_context() { return std::string(); }
|
||||||
static inline const char *tr(const char *str) { return i18n_translate(str,get_default_i18n_context()); }
|
static inline const char *tr(const char *str) { return i18n_translate(str,get_default_i18n_context()); }
|
||||||
|
|
Loading…
Reference in a new issue