diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-08-25 12:11:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-25 12:11:56 +0200 |
commit | 9d8f3496e8352d982fed4ffd420f567af7a840cc (patch) | |
tree | bd0fe687c810720bd64df45b33800ef77cc09166 /core/ustring.cpp | |
parent | e968109fa7f105f21ca0158c9cc474781406bb43 (diff) | |
parent | ce3461dc88fb4abc9460328b06502890e06f50d6 (diff) |
Merge pull request #40443 from SkyLucilfer/PluralsSupport
Added plurals and context support to Translation
Diffstat (limited to 'core/ustring.cpp')
-rw-r--r-- | core/ustring.cpp | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 957caf1015..9d2d938eaf 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -4269,31 +4269,58 @@ 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; + } + 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; + } + 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 +4328,20 @@ 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; + } + return p_text_plural; +} |