summaryrefslogtreecommitdiff
path: root/core/translation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/translation.cpp')
-rw-r--r--core/translation.cpp33
1 files changed, 0 insertions, 33 deletions
diff --git a/core/translation.cpp b/core/translation.cpp
index 191349e953..a33cd48b88 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -795,12 +795,10 @@ static const char *locale_renames[][2] = {
///////////////////////////////////////////////
Vector<String> Translation::_get_messages() const {
-
Vector<String> msgs;
msgs.resize(translation_map.size() * 2);
int idx = 0;
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
msgs.set(idx + 0, E->key());
msgs.set(idx + 1, E->get());
idx += 2;
@@ -810,12 +808,10 @@ Vector<String> Translation::_get_messages() const {
}
Vector<String> Translation::_get_message_list() const {
-
Vector<String> msgs;
msgs.resize(translation_map.size());
int idx = 0;
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
msgs.set(idx, E->key());
idx += 1;
}
@@ -824,20 +820,17 @@ Vector<String> Translation::_get_message_list() const {
}
void Translation::_set_messages(const Vector<String> &p_messages) {
-
int msg_count = p_messages.size();
ERR_FAIL_COND(msg_count % 2);
const String *r = p_messages.ptr();
for (int i = 0; i < msg_count; i += 2) {
-
add_message(r[i + 0], r[i + 1]);
}
}
void Translation::set_locale(const String &p_locale) {
-
String univ_locale = TranslationServer::standardize_locale(p_locale);
if (!TranslationServer::is_locale_valid(univ_locale)) {
@@ -856,11 +849,9 @@ void Translation::set_locale(const String &p_locale) {
}
void Translation::add_message(const StringName &p_src_text, const StringName &p_xlated_text) {
-
translation_map[p_src_text] = p_xlated_text;
}
StringName Translation::get_message(const StringName &p_src_text) const {
-
const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
if (!E)
return StringName();
@@ -869,25 +860,20 @@ StringName Translation::get_message(const StringName &p_src_text) const {
}
void Translation::erase_message(const StringName &p_src_text) {
-
translation_map.erase(p_src_text);
}
void Translation::get_message_list(List<StringName> *r_messages) const {
-
for (const Map<StringName, StringName>::Element *E = translation_map.front(); E; E = E->next()) {
-
r_messages->push_back(E->key());
}
}
int Translation::get_message_count() const {
-
return translation_map.size();
};
void Translation::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &Translation::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &Translation::get_locale);
ClassDB::bind_method(D_METHOD("add_message", "src_message", "xlated_message"), &Translation::add_message);
@@ -905,11 +891,9 @@ void Translation::_bind_methods() {
///////////////////////////////////////////////
bool TranslationServer::is_locale_valid(const String &p_locale) {
-
const char **ptr = locale_list;
while (*ptr) {
-
if (*ptr == p_locale)
return true;
ptr++;
@@ -919,7 +903,6 @@ bool TranslationServer::is_locale_valid(const String &p_locale) {
}
String TranslationServer::standardize_locale(const String &p_locale) {
-
// Replaces '-' with '_' for macOS Sierra-style locales
String univ_locale = p_locale.replace("-", "_");
@@ -937,7 +920,6 @@ String TranslationServer::standardize_locale(const String &p_locale) {
}
String TranslationServer::get_language_code(const String &p_locale) {
-
ERR_FAIL_COND_V_MSG(p_locale.length() < 2, p_locale, "Invalid locale '" + p_locale + "'.");
// Most language codes are two letters, but some are three,
// so we have to look for a regional code separator ('_' or '-')
@@ -954,7 +936,6 @@ String TranslationServer::get_language_code(const String &p_locale) {
}
void TranslationServer::set_locale(const String &p_locale) {
-
String univ_locale = standardize_locale(p_locale);
if (!is_locale_valid(univ_locale)) {
@@ -979,12 +960,10 @@ void TranslationServer::set_locale(const String &p_locale) {
}
String TranslationServer::get_locale() const {
-
return locale;
}
String TranslationServer::get_locale_name(const String &p_locale) const {
-
if (!locale_name_map.has(p_locale))
return String();
return locale_name_map[p_locale];
@@ -993,7 +972,6 @@ String TranslationServer::get_locale_name(const String &p_locale) const {
Array TranslationServer::get_loaded_locales() const {
Array locales;
for (const Set<Ref<Translation>>::Element *E = translations.front(); E; E = E->next()) {
-
const Ref<Translation> &t = E->get();
ERR_FAIL_COND_V(t.is_null(), Array());
String l = t->get_locale();
@@ -1005,7 +983,6 @@ Array TranslationServer::get_loaded_locales() const {
}
Vector<String> TranslationServer::get_all_locales() {
-
Vector<String> locales;
const char **ptr = locale_list;
@@ -1019,7 +996,6 @@ Vector<String> TranslationServer::get_all_locales() {
}
Vector<String> TranslationServer::get_all_locale_names() {
-
Vector<String> locales;
const char **ptr = locale_names;
@@ -1033,21 +1009,17 @@ Vector<String> TranslationServer::get_all_locale_names() {
}
void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
-
translations.insert(p_translation);
}
void TranslationServer::remove_translation(const Ref<Translation> &p_translation) {
-
translations.erase(p_translation);
}
void TranslationServer::clear() {
-
translations.clear();
};
StringName TranslationServer::translate(const StringName &p_message) const {
-
// Match given message against the translation catalog for the project locale.
if (!enabled)
@@ -1141,7 +1113,6 @@ StringName TranslationServer::translate(const StringName &p_message) const {
TranslationServer *TranslationServer::singleton = nullptr;
bool TranslationServer::_load_translations(const String &p_from) {
-
if (ProjectSettings::get_singleton()->has_setting(p_from)) {
Vector<String> translations = ProjectSettings::get_singleton()->get(p_from);
@@ -1151,7 +1122,6 @@ bool TranslationServer::_load_translations(const String &p_from) {
const String *r = translations.ptr();
for (int i = 0; i < tcount; i++) {
-
Ref<Translation> tr = ResourceLoader::load(r[i]);
if (tr.is_valid())
add_translation(tr);
@@ -1164,7 +1134,6 @@ bool TranslationServer::_load_translations(const String &p_from) {
}
void TranslationServer::setup() {
-
String test = GLOBAL_DEF("locale/test", "");
test = test.strip_edges();
if (test != "")
@@ -1216,7 +1185,6 @@ StringName TranslationServer::doc_translate(const StringName &p_message) const {
}
void TranslationServer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale);
@@ -1233,7 +1201,6 @@ void TranslationServer::_bind_methods() {
}
void TranslationServer::load_translations() {
-
String locale = get_locale();
_load_translations("locale/translations"); //all
_load_translations("locale/translations_" + locale.substr(0, 2));