|
@@ -37,12 +37,42 @@
|
|
|
#include "core/io/dir_access.h"
|
|
|
#include "core/io/marshalls.h"
|
|
|
#include "core/object/script_language.h"
|
|
|
+#include "core/string/translation.h"
|
|
|
#include "core/version.h"
|
|
|
#include "scene/resources/theme.h"
|
|
|
|
|
|
// Used for a hack preserving Mono properties on non-Mono builds.
|
|
|
#include "modules/modules_enabled.gen.h" // For mono.
|
|
|
|
|
|
+static String _get_indent(const String &p_text) {
|
|
|
+ String indent;
|
|
|
+ bool has_text = false;
|
|
|
+ int line_start = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < p_text.length(); i++) {
|
|
|
+ const char32_t c = p_text[i];
|
|
|
+ if (c == '\n') {
|
|
|
+ line_start = i + 1;
|
|
|
+ } else if (c > 32) {
|
|
|
+ has_text = true;
|
|
|
+ indent = p_text.substr(line_start, i - line_start);
|
|
|
+ break; // Indentation of the first line that has text.
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!has_text) {
|
|
|
+ return p_text;
|
|
|
+ }
|
|
|
+ return indent;
|
|
|
+}
|
|
|
+
|
|
|
+static String _translate_doc_string(const String &p_text) {
|
|
|
+ const String indent = _get_indent(p_text);
|
|
|
+ const String message = p_text.dedent().strip_edges();
|
|
|
+ const String translated = TranslationServer::get_singleton()->doc_translate(message, "");
|
|
|
+ // No need to restore stripped edges because they'll be stripped again later.
|
|
|
+ return translated.indent(indent);
|
|
|
+}
|
|
|
+
|
|
|
void DocTools::merge_from(const DocTools &p_data) {
|
|
|
for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
|
|
|
DocData::ClassDoc &c = E.value;
|
|
@@ -1289,7 +1319,7 @@ static void _write_method_doc(FileAccess *f, const String &p_name, Vector<DocDat
|
|
|
}
|
|
|
|
|
|
_write_string(f, 3, "<description>");
|
|
|
- _write_string(f, 4, m.description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 4, _translate_doc_string(m.description).strip_edges().xml_escape());
|
|
|
_write_string(f, 3, "</description>");
|
|
|
|
|
|
_write_string(f, 2, "</" + p_name + ">");
|
|
@@ -1327,11 +1357,11 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
|
|
|
_write_string(f, 0, header);
|
|
|
|
|
|
_write_string(f, 1, "<brief_description>");
|
|
|
- _write_string(f, 2, c.brief_description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 2, _translate_doc_string(c.brief_description).strip_edges().xml_escape());
|
|
|
_write_string(f, 1, "</brief_description>");
|
|
|
|
|
|
_write_string(f, 1, "<description>");
|
|
|
- _write_string(f, 2, c.description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 2, _translate_doc_string(c.description).strip_edges().xml_escape());
|
|
|
_write_string(f, 1, "</description>");
|
|
|
|
|
|
_write_string(f, 1, "<tutorials>");
|
|
@@ -1366,7 +1396,7 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
|
|
|
_write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\" overrides=\"" + p.overrides + "\"" + additional_attributes + " />");
|
|
|
} else {
|
|
|
_write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">");
|
|
|
- _write_string(f, 3, p.description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 3, _translate_doc_string(p.description).strip_edges().xml_escape());
|
|
|
_write_string(f, 2, "</member>");
|
|
|
}
|
|
|
}
|
|
@@ -1392,7 +1422,7 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
|
|
|
_write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
|
|
|
}
|
|
|
}
|
|
|
- _write_string(f, 3, k.description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 3, _translate_doc_string(k.description).strip_edges().xml_escape());
|
|
|
_write_string(f, 2, "</constant>");
|
|
|
}
|
|
|
|
|
@@ -1412,7 +1442,7 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
|
|
|
_write_string(f, 2, "<theme_item name=\"" + ti.name + "\" data_type=\"" + ti.data_type + "\" type=\"" + ti.type + "\">");
|
|
|
}
|
|
|
|
|
|
- _write_string(f, 3, ti.description.strip_edges().xml_escape());
|
|
|
+ _write_string(f, 3, _translate_doc_string(ti.description).strip_edges().xml_escape());
|
|
|
|
|
|
_write_string(f, 2, "</theme_item>");
|
|
|
}
|