Skip to content

Commit 01ae488

Browse files
authored
Merge pull request #53207 from o01eg/virtual-translation-3.x
2 parents acb748e + cddabf2 commit 01ae488

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

core/translation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,10 @@ void Translation::add_message(const StringName &p_src_text, const StringName &p_
871871
translation_map[p_src_text] = p_xlated_text;
872872
}
873873
StringName Translation::get_message(const StringName &p_src_text) const {
874+
if (get_script_instance()) {
875+
return get_script_instance()->call("_get_message", p_src_text);
876+
}
877+
874878
const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
875879
if (!E) {
876880
return StringName();
@@ -904,6 +908,8 @@ void Translation::_bind_methods() {
904908
ClassDB::bind_method(D_METHOD("_set_messages"), &Translation::_set_messages);
905909
ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages);
906910

911+
BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_message", PropertyInfo(Variant::STRING, "src_message")));
912+
907913
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_messages", "_get_messages");
908914
ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale");
909915
}

doc/classes/Translation.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
<link>https://docs.godotengine.org/en/3.4/tutorials/i18n/locales.html</link>
1212
</tutorials>
1313
<methods>
14+
<method name="_get_message" qualifiers="virtual">
15+
<return type="String" />
16+
<argument index="0" name="src_message" type="String" />
17+
<description>
18+
Virtual method to override [method get_message].
19+
</description>
20+
</method>
1421
<method name="add_message">
1522
<return type="void" />
1623
<argument index="0" name="src_message" type="String" />

0 commit comments

Comments
 (0)