summaryrefslogtreecommitdiffstats
path: root/core/object.cpp
diff options
context:
space:
mode:
authorSkyJJ <jjchai01@hotmail.com>2020-07-16 10:52:06 +0200
committerSkyJJ <jjchai01@hotmail.com>2020-08-19 03:01:51 +0200
commitc0d837a2ea9ca888f673485c4b9d8d9ae1936375 (patch)
treecf83368d74441ebc422952e60eafdc92fce2f203 /core/object.cpp
parentf568cede8d8a4a3f7051afd2ae8502deb09bc157 (diff)
downloadredot-engine-c0d837a2ea9ca888f673485c4b9d8d9ae1936375.tar.gz
Added plurals and context support to Translation
Diffstat (limited to 'core/object.cpp')
-rw-r--r--core/object.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/core/object.cpp b/core/object.cpp
index ff6d4a666f..9d38f36009 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1432,12 +1432,23 @@ void Object::initialize_class() {
initialized = true;
}
-StringName Object::tr(const StringName &p_message) const {
+StringName Object::tr(const StringName &p_message, const StringName &p_context) const {
if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
}
+ return TranslationServer::get_singleton()->translate(p_message, p_context);
+}
- return TranslationServer::get_singleton()->translate(p_message);
+String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
+ if (!_can_translate || !TranslationServer::get_singleton()) {
+ // Return message based on English plural rule if translation is not possible.
+ if (p_n == 1) {
+ return p_message;
+ } else {
+ return p_message_plural;
+ }
+ }
+ return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
}
void Object::_clear_internal_resource_paths(const Variant &p_var) {
@@ -1578,7 +1589,8 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation);
ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages);
- ClassDB::bind_method(D_METHOD("tr", "message"), &Object::tr);
+ ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(""));
ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion);