Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocompletion for TranslationServer #87191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/string/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,29 @@ bool TranslationServer::is_placeholder(String &p_message, int p_index) const {
p_message[p_index + 1] == 'o' || p_message[p_index + 1] == 'x' || p_message[p_index + 1] == 'X' || p_message[p_index + 1] == 'f');
}

#ifdef TOOLS_ENABLED
void TranslationServer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
const String pf = p_function;
if (p_idx == 0) {
HashMap<String, String> *target_hash_map = nullptr;
if (pf == "get_language_name") {
target_hash_map = &language_map;
} else if (pf == "get_script_name") {
target_hash_map = &script_map;
} else if (pf == "get_country_name") {
target_hash_map = &country_name_map;
}

if (target_hash_map) {
for (const KeyValue<String, String> &E : *target_hash_map) {
r_options->push_back(E.key.quote());
}
}
}
Object::get_argument_options(p_function, p_idx, r_options);
}
#endif // TOOLS_ENABLED

void TranslationServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale);
Expand Down
4 changes: 4 additions & 0 deletions core/string/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class TranslationServer : public Object {

void load_translations();

#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
#endif // TOOLS_ENABLED

TranslationServer();
};

Expand Down
Loading