summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-10-25 09:25:44 +0200
committerGitHub <noreply@github.com>2017-10-25 09:25:44 +0200
commit3842848d767d2be5e528690fcec9c266eeb2bfc5 (patch)
treefae40d6ebbd4c688c84f25569299bf8ff43c5d59
parent552ed07cfd2fce1f885b5a7739a0c086ab8c1589 (diff)
parent1cd40be4915490e2185aaa0a1ff7de55950e078e (diff)
Merge pull request #12394 from sheepandshepherd/locale_name
Add a function to get the full name of a locale [ci skip]
-rw-r--r--core/translation.cpp13
-rw-r--r--core/translation.h4
2 files changed, 17 insertions, 0 deletions
diff --git a/core/translation.cpp b/core/translation.cpp
index 27e3b202d0..54dbaf6ed5 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -957,6 +957,12 @@ 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];
+}
+
void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
translations.insert(p_translation);
@@ -1122,6 +1128,8 @@ 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);
+ ClassDB::bind_method(D_METHOD("get_locale_name", "locale"), &TranslationServer::get_locale_name);
+
ClassDB::bind_method(D_METHOD("translate", "message"), &TranslationServer::translate);
ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation);
@@ -1147,4 +1155,9 @@ TranslationServer::TranslationServer()
: locale("en"),
enabled(true) {
singleton = this;
+
+ for (int i = 0; locale_list[i]; ++i) {
+
+ locale_name_map.insert(locale_list[i], locale_names[i]);
+ }
}
diff --git a/core/translation.h b/core/translation.h
index cf59583ad6..5fec1d9f45 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -73,6 +73,8 @@ class TranslationServer : public Object {
Set<Ref<Translation> > translations;
Ref<Translation> tool_translation;
+ Map<String, String> locale_name_map;
+
bool enabled;
static TranslationServer *singleton;
@@ -91,6 +93,8 @@ public:
void set_locale(const String &p_locale);
String get_locale() const;
+ String get_locale_name(const String &p_locale) const;
+
void add_translation(const Ref<Translation> &p_translation);
void remove_translation(const Ref<Translation> &p_translation);