Browse Source

Merge pull request #87191 from Mickeon/autocompletion-TranslationServer

Add autocompletion for TranslationServer
Rémi Verschelde 1 year ago
parent
commit
0a089e284b
2 changed files with 27 additions and 0 deletions
  1. 23 0
      core/string/translation.cpp
  2. 4 0
      core/string/translation.h

+ 23 - 0
core/string/translation.cpp

@@ -1012,6 +1012,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');
 					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() {
 void TranslationServer::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale);
 	ClassDB::bind_method(D_METHOD("set_locale", "locale"), &TranslationServer::set_locale);
 	ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale);
 	ClassDB::bind_method(D_METHOD("get_locale"), &TranslationServer::get_locale);

+ 4 - 0
core/string/translation.h

@@ -197,6 +197,10 @@ public:
 
 
 	void load_translations();
 	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();
 	TranslationServer();
 };
 };