From 291f6d3115b47903e86fdc67573fb55a1ed772a2 Mon Sep 17 00:00:00 2001 From: tetrapod00 <145553014+tetrapod00@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:45:26 -0700 Subject: [PATCH] Online docs now open in the editor language --- core/SCsub | 2 +- doc/classes/EditorSettings.xml | 6 ++++ editor/editor_node.cpp | 3 +- editor/editor_settings.cpp | 37 +++++++++++++++++++++++++ editor/editor_settings.h | 1 + editor/export/project_export.cpp | 3 +- editor/plugins/script_editor_plugin.cpp | 6 ++-- editor/plugins/text_shader_editor.cpp | 3 +- 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/core/SCsub b/core/SCsub index c8267ae96002..8188044bb265 100644 --- a/core/SCsub +++ b/core/SCsub @@ -189,7 +189,7 @@ def version_info_builder(target, source, env): #define VERSION_MODULE_CONFIG "{module_config}" #define VERSION_WEBSITE "{website}" #define VERSION_DOCS_BRANCH "{docs_branch}" -#define VERSION_DOCS_URL "https://docs.godotengine.org/en/" VERSION_DOCS_BRANCH +#define VERSION_DOCS_URL "https://docs.godotengine.org/" """.format(**env.version_info) ) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 7f017f39de91..22c5e71d522c 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -702,6 +702,12 @@ If [code]true[/code], the mouse's additional side buttons will be usable to navigate in the script editor's file history. Set this to [code]false[/code] if you're using the side buttons for other purposes (such as a push-to-talk button in a VoIP program). + + If [member interface/editor/override_online_docs_language] is true, then the online docs will open in this language. + + + If [code]true[/code], the online docs will open in the language specified in [member interface/editor/online_docs_language]. If [code]false[/code], then the online docs will open in the default editor language specified in [member interface/editor/editor_language]. If the default editor language does not have an online translation, the English translation will be opened. + The preferred monitor to display the project manager. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f154cbd1e2a9..5b0fb4aab2c7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3185,7 +3185,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { command_palette->open_popup(); } break; case HELP_DOCS: { - OS::get_singleton()->shell_open(VERSION_DOCS_URL "/"); + String doc_url = EditorSettings::get_singleton()->get_online_docs_url(); + OS::get_singleton()->shell_open(doc_url); } break; case HELP_FORUM: { OS::get_singleton()->shell_open("https://forum.godotengine.org/"); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 36fbd9131321..66a09b3f87be 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -397,7 +397,12 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { best = "en"; } + // These are the languages with a translation for the online docs + String docs_lang_hint = "en,cs,de,es,fr,it,ja,ko,pl,pt-br,ru,uk,zh-cn,zh-tw"; + EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/override_online_docs_language", false, ""); + EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/online_docs_language", "en", docs_lang_hint); } /* Interface */ @@ -1144,6 +1149,38 @@ void EditorSettings::setup_language() { load_extractable_translations(lang); } +String EditorSettings::get_online_docs_url() { + String language = EditorSettings::get_singleton()->get_setting("interface/editor/editor_language"); + bool override = EditorSettings::get_singleton()->get_setting("interface/editor/override_online_docs_language"); + String override_language = EditorSettings::get_singleton()->get_setting("interface/editor/online_docs_language"); + + Vector doc_languages; + doc_languages.push_back("en"); + doc_languages.push_back("cs"); + doc_languages.push_back("de"); + doc_languages.push_back("es"); + doc_languages.push_back("fr"); + doc_languages.push_back("it"); + doc_languages.push_back("ja"); + doc_languages.push_back("ko"); + doc_languages.push_back("pl"); + doc_languages.push_back("pt-br"); + doc_languages.push_back("ru"); + doc_languages.push_back("uk"); + doc_languages.push_back("zh-cn"); + doc_languages.push_back("zh-tw"); + + if (override && (doc_languages.find(override_language) > 0)) { + language = override_language; + } else if (!(doc_languages.find(language) > 0)) { + language = "en"; + } + + // The translated online docs only use version "4.x", not "4.3" or "latest" or "stable". + String version = (language == "en") ? VERSION_DOCS_BRANCH : "4.x"; + return vformat(VERSION_DOCS_URL "/%s/%s/", language, version); +} + void EditorSettings::setup_network() { List local_ip; IP::get_singleton()->get_local_addresses(&local_ip); diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 6338f9105c58..709a81cd6ab2 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -134,6 +134,7 @@ class EditorSettings : public Resource { static void create(); void setup_language(); + String get_online_docs_url(); void setup_network(); static void save(); static void destroy(); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 03e9fba12d7c..f89b37b41065 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -553,7 +553,8 @@ void ProjectExportDialog::_enc_filters_changed(const String &p_filters) { } void ProjectExportDialog::_open_key_help_link() { - OS::get_singleton()->shell_open(vformat("%s/contributing/development/compiling/compiling_with_script_encryption_key.html", VERSION_DOCS_URL)); + String doc_url = EditorSettings::get_singleton()->get_online_docs_url(); + OS::get_singleton()->shell_open(vformat("%s/contributing/development/compiling/compiling_with_script_encryption_key.html", doc_url)); } void ProjectExportDialog::_enc_pck_changed(bool p_pressed) { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 93c8ae5438bc..23f4710a504f 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1367,12 +1367,14 @@ void ScriptEditor::_menu_option(int p_option) { const HashMap::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(eh->get_class()); native_class_doc = E && !E->value.is_script_doc; } + + String doc_url_base = EditorSettings::get_singleton()->get_online_docs_url(); if (native_class_doc) { String name = eh->get_class().to_lower(); - String doc_url = vformat(VERSION_DOCS_URL "/classes/class_%s.html", name); + String doc_url = vformat("%s/classes/class_%s.html", doc_url_base, name); OS::get_singleton()->shell_open(doc_url); } else { - OS::get_singleton()->shell_open(VERSION_DOCS_URL "/"); + OS::get_singleton()->shell_open(doc_url_base); } } break; case WINDOW_NEXT: { diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 0ff7aaa3fe46..4a52d74c4339 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -727,7 +727,8 @@ void TextShaderEditor::_menu_option(int p_option) { code_editor->remove_all_bookmarks(); } break; case HELP_DOCS: { - OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/shader_reference/index.html", VERSION_DOCS_URL)); + String doc_url = EditorSettings::get_singleton()->get_online_docs_url(); + OS::get_singleton()->shell_open(vformat("%s/tutorials/shaders/shader_reference/index.html", doc_url)); } break; } if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) {