summaryrefslogtreecommitdiff
path: root/core/ustring.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/ustring.cpp
parentf568cede8d8a4a3f7051afd2ae8502deb09bc157 (diff)
Added plurals and context support to Translation
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r--core/ustring.cpp61
1 files changed, 54 insertions, 7 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 957caf1015..5a310c7f95 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -4269,31 +4269,60 @@ String String::unquote() const {
}
#ifdef TOOLS_ENABLED
-String TTR(const String &p_text) {
+String TTR(const String &p_text, const String &p_context) {
if (TranslationServer::get_singleton()) {
- return TranslationServer::get_singleton()->tool_translate(p_text);
+ return TranslationServer::get_singleton()->tool_translate(p_text, p_context);
}
return p_text;
}
-String DTR(const String &p_text) {
+String TTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) {
+ if (TranslationServer::get_singleton()) {
+ return TranslationServer::get_singleton()->tool_translate_plural(p_text, p_text_plural, p_n, p_context);
+ }
+
+ // Return message based on English plural rule if translation is not possible.
+ if (p_n == 1) {
+ return p_text;
+ } else {
+ return p_text_plural;
+ }
+}
+
+String DTR(const String &p_text, const String &p_context) {
// Comes straight from the XML, so remove indentation and any trailing whitespace.
const String text = p_text.dedent().strip_edges();
if (TranslationServer::get_singleton()) {
- return TranslationServer::get_singleton()->doc_translate(text);
+ return TranslationServer::get_singleton()->doc_translate(text, p_context);
}
return text;
}
+
+String DTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) {
+ const String text = p_text.dedent().strip_edges();
+ const String text_plural = p_text_plural.dedent().strip_edges();
+
+ if (TranslationServer::get_singleton()) {
+ return TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context);
+ }
+
+ // Return message based on English plural rule if translation is not possible.
+ if (p_n == 1) {
+ return text;
+ } else {
+ return text_plural;
+ }
+}
#endif
-String RTR(const String &p_text) {
+String RTR(const String &p_text, const String &p_context) {
if (TranslationServer::get_singleton()) {
- String rtr = TranslationServer::get_singleton()->tool_translate(p_text);
+ String rtr = TranslationServer::get_singleton()->tool_translate(p_text, p_context);
if (rtr == String() || rtr == p_text) {
- return TranslationServer::get_singleton()->translate(p_text);
+ return TranslationServer::get_singleton()->translate(p_text, p_context);
} else {
return rtr;
}
@@ -4301,3 +4330,21 @@ String RTR(const String &p_text) {
return p_text;
}
+
+String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) {
+ if (TranslationServer::get_singleton()) {
+ String rtr = TranslationServer::get_singleton()->tool_translate_plural(p_text, p_text_plural, p_n, p_context);
+ if (rtr == String() || rtr == p_text || rtr == p_text_plural) {
+ return TranslationServer::get_singleton()->translate_plural(p_text, p_text_plural, p_n, p_context);
+ } else {
+ return rtr;
+ }
+ }
+
+ // Return message based on English plural rule if translation is not possible.
+ if (p_n == 1) {
+ return p_text;
+ } else {
+ return p_text_plural;
+ }
+}