summaryrefslogtreecommitdiffstats
path: root/core/object/object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/object.cpp')
-rw-r--r--core/object/object.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp
index da3ca6bc61..2d9d468d38 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1527,21 +1527,21 @@ void Object::initialize_class() {
initialized = true;
}
+StringName Object::get_translation_domain() const {
+ return _translation_domain;
+}
+
+void Object::set_translation_domain(const StringName &p_domain) {
+ _translation_domain = p_domain;
+}
+
String Object::tr(const StringName &p_message, const StringName &p_context) const {
if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
}
- if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) {
- String tr_msg = TranslationServer::get_singleton()->extractable_translate(p_message, p_context);
- if (!tr_msg.is_empty() && tr_msg != p_message) {
- return tr_msg;
- }
-
- return TranslationServer::get_singleton()->tool_translate(p_message, p_context);
- }
-
- return TranslationServer::get_singleton()->translate(p_message, p_context);
+ const Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain());
+ return domain->translate(p_message, p_context);
}
String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
@@ -1553,16 +1553,8 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu
return p_message_plural;
}
- if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) {
- String tr_msg = TranslationServer::get_singleton()->extractable_translate_plural(p_message, p_message_plural, p_n, p_context);
- if (!tr_msg.is_empty() && tr_msg != p_message && tr_msg != p_message_plural) {
- return tr_msg;
- }
-
- return TranslationServer::get_singleton()->tool_translate_plural(p_message, p_message_plural, p_n, p_context);
- }
-
- return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
+ const Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(get_translation_domain());
+ return domain->translate_plural(p_message, p_message_plural, p_n, p_context);
}
void Object::_clear_internal_resource_paths(const Variant &p_var) {
@@ -1714,6 +1706,8 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages);
ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("get_translation_domain"), &Object::get_translation_domain);
+ ClassDB::bind_method(D_METHOD("set_translation_domain", "domain"), &Object::set_translation_domain);
ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion);
ClassDB::bind_method(D_METHOD("cancel_free"), &Object::cancel_free);