mirror of
https://github.com/monero-project/monero.git
synced 2025-06-21 22:24:09 -04:00
Embed the translation files in the binary
If a translation file exists in a "translations" directory located in the same directory as the binary, it is used in priority (this can be useful when working on translations as you don't have to recompile the whole program all the time), and if no such file is found the embedded translation file is used (if it exists).
This commit is contained in:
parent
319163d276
commit
db2bc96512
4 changed files with 174 additions and 13 deletions
|
@ -35,6 +35,7 @@
|
|||
#include "file_io_utils.h"
|
||||
#include "common/util.h"
|
||||
#include "common/i18n.h"
|
||||
#include "translation_files.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "i18n"
|
||||
|
@ -62,6 +63,7 @@ std::string i18n_get_language()
|
|||
e = "en";
|
||||
|
||||
std::string language = e;
|
||||
language = language.substr(0, language.find("."));
|
||||
std::transform(language.begin(), language.end(), language.begin(), tolower);
|
||||
return language;
|
||||
}
|
||||
|
@ -137,25 +139,40 @@ int i18n_set_language(const char *directory, const char *base, std::string langu
|
|||
i18n_log("Loading translations for language " << language);
|
||||
|
||||
boost::system::error_code ignored_ec;
|
||||
if (!boost::filesystem::exists(filename, ignored_ec)) {
|
||||
if (boost::filesystem::exists(filename, ignored_ec)) {
|
||||
if (!epee::file_io_utils::load_file_to_string(filename, contents)) {
|
||||
i18n_log("Failed to load translations file: " << filename);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
i18n_log("Translations file not found: " << filename);
|
||||
const char *underscore = strchr(language.c_str(), '_');
|
||||
if (underscore) {
|
||||
std::string fallback_language = std::string(language, 0, underscore - language.c_str());
|
||||
filename = std::string(directory) + "/" + base + "_" + fallback_language + ".qm";
|
||||
i18n_log("Not found, loading translations for language " << fallback_language);
|
||||
if (!boost::filesystem::exists(filename, ignored_ec)) {
|
||||
i18n_log("Translations file not found: " << filename);
|
||||
filename = std::string(base) + "_" + language + ".qm";
|
||||
if (!find_embedded_file(filename, contents)) {
|
||||
i18n_log("Embedded translations file not found: " << filename);
|
||||
const char *underscore = strchr(language.c_str(), '_');
|
||||
if (underscore) {
|
||||
std::string fallback_language = std::string(language, 0, underscore - language.c_str());
|
||||
filename = std::string(directory) + "/" + base + "_" + fallback_language + ".qm";
|
||||
i18n_log("Loading translations for language " << fallback_language);
|
||||
if (boost::filesystem::exists(filename, ignored_ec)) {
|
||||
if (!epee::file_io_utils::load_file_to_string(filename, contents)) {
|
||||
i18n_log("Failed to load translations file: " << filename);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
i18n_log("Translations file not found: " << filename);
|
||||
filename = std::string(base) + "_" + fallback_language + ".qm";
|
||||
if (!find_embedded_file(filename, contents)) {
|
||||
i18n_log("Embedded translations file not found: " << filename);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!epee::file_io_utils::load_file_to_string(filename, contents)) {
|
||||
i18n_log("Failed to load translations file: " << filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = (const unsigned char*)contents.c_str();
|
||||
datalen = contents.size();
|
||||
idx = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue