Skip to content

Commit

Permalink
Merge pull request #53207 from o01eg/virtual-translation-3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Sep 29, 2021
2 parents acb748e + cddabf2 commit 01ae488
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,10 @@ void Translation::add_message(const StringName &p_src_text, const StringName &p_
translation_map[p_src_text] = p_xlated_text;
}
StringName Translation::get_message(const StringName &p_src_text) const {
if (get_script_instance()) {
return get_script_instance()->call("_get_message", p_src_text);
}

const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
if (!E) {
return StringName();
Expand Down Expand Up @@ -904,6 +908,8 @@ void Translation::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_messages"), &Translation::_set_messages);
ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages);

BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_message", PropertyInfo(Variant::STRING, "src_message")));

ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_messages", "_get_messages");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale");
}
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/Translation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<link>https://docs.godotengine.org/en/3.4/tutorials/i18n/locales.html</link>
</tutorials>
<methods>
<method name="_get_message" qualifiers="virtual">
<return type="String" />
<argument index="0" name="src_message" type="String" />
<description>
Virtual method to override [method get_message].
</description>
</method>
<method name="add_message">
<return type="void" />
<argument index="0" name="src_message" type="String" />
Expand Down

0 comments on commit 01ae488

Please sign in to comment.