diff options
author | Micky <micheledevita2@gmail.com> | 2024-01-14 21:47:06 +0100 |
---|---|---|
committer | Micky <micheledevita2@gmail.com> | 2024-02-29 20:43:19 +0100 |
commit | ffd498c57d943879e4d417422e473943bd373c40 (patch) | |
tree | 1ec326f1723f598e9b5f57308caa9f57ce0d8224 | |
parent | 26b1fd0d842fa3c2f090ead47e8ea7cd2d6515e1 (diff) | |
download | redot-engine-ffd498c57d943879e4d417422e473943bd373c40.tar.gz |
Add autocompletion for TranslationServer
-rw-r--r-- | core/string/translation.cpp | 23 | ||||
-rw-r--r-- | core/string/translation.h | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 829c9bf777..4a0ce27904 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -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); diff --git a/core/string/translation.h b/core/string/translation.h index 3f9dbcc476..3910176021 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -185,6 +185,10 @@ public: 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(); }; |