Merge pull request #12394 from sheepandshepherd/locale_name
Add a function to get the full name of a locale [ci skip]
This commit is contained in:
commit
3842848d76
2 changed files with 17 additions and 0 deletions
|
@ -957,6 +957,12 @@ String TranslationServer::get_locale() const {
|
||||||
return locale;
|
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) {
|
void TranslationServer::add_translation(const Ref<Translation> &p_translation) {
|
||||||
|
|
||||||
translations.insert(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("set_locale", "locale"), &TranslationServer::set_locale);
|
||||||
ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_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("translate", "message"), &TranslationServer::translate);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation);
|
ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation);
|
||||||
|
@ -1147,4 +1155,9 @@ TranslationServer::TranslationServer()
|
||||||
: locale("en"),
|
: locale("en"),
|
||||||
enabled(true) {
|
enabled(true) {
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
||||||
|
for (int i = 0; locale_list[i]; ++i) {
|
||||||
|
|
||||||
|
locale_name_map.insert(locale_list[i], locale_names[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ class TranslationServer : public Object {
|
||||||
Set<Ref<Translation> > translations;
|
Set<Ref<Translation> > translations;
|
||||||
Ref<Translation> tool_translation;
|
Ref<Translation> tool_translation;
|
||||||
|
|
||||||
|
Map<String, String> locale_name_map;
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|
||||||
static TranslationServer *singleton;
|
static TranslationServer *singleton;
|
||||||
|
@ -91,6 +93,8 @@ public:
|
||||||
void set_locale(const String &p_locale);
|
void set_locale(const String &p_locale);
|
||||||
String get_locale() const;
|
String get_locale() const;
|
||||||
|
|
||||||
|
String get_locale_name(const String &p_locale) const;
|
||||||
|
|
||||||
void add_translation(const Ref<Translation> &p_translation);
|
void add_translation(const Ref<Translation> &p_translation);
|
||||||
void remove_translation(const Ref<Translation> &p_translation);
|
void remove_translation(const Ref<Translation> &p_translation);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue