You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Added plurals and context support to Translation
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user