Skip to content

Commit 3c483e4

Browse files
committed
Make editor language setting default to Auto
1 parent 0fdbf05 commit 3c483e4

File tree

8 files changed

+76
-32
lines changed

8 files changed

+76
-32
lines changed

doc/classes/EditorInterface.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@
9696
Returns the edited (current) scene's root [Node].
9797
</description>
9898
</method>
99+
<method name="get_editor_language" qualifiers="const">
100+
<return type="String" />
101+
<description>
102+
Returns the language used for the editor interface.
103+
</description>
104+
</method>
99105
<method name="get_editor_main_screen" qualifiers="const">
100106
<return type="VBoxContainer" />
101107
<description>

doc/classes/EditorSettings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@
880880
During a drag-and-drop, this is how long to wait over a UI element before it triggers a reaction (e.g. a section unfolds to show nested items).
881881
</member>
882882
<member name="interface/editor/editor_language" type="String" setter="" getter="">
883-
The language to use for the editor interface.
883+
The language to use for the editor interface. If set to [b]Auto[/b], the language is automatically determined based on the system locale.
884884
Translations are provided by the community. If you spot a mistake, [url=https://contributing.godotengine.org/en/latest/documentation/translation/index.html]contribute to editor translations on Weblate![/url]
885885
</member>
886886
<member name="interface/editor/editor_screen" type="int" setter="" getter="">

editor/editor_interface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ float EditorInterface::get_editor_scale() const {
442442
return EDSCALE;
443443
}
444444

445+
String EditorInterface::get_editor_language() const {
446+
return EditorSettings::get_singleton()->get_language();
447+
}
448+
445449
bool EditorInterface::is_node_3d_snap_enabled() const {
446450
return Node3DEditor::get_singleton()->is_snap_enabled();
447451
}
@@ -846,6 +850,7 @@ void EditorInterface::_bind_methods() {
846850
ClassDB::bind_method(D_METHOD("is_multi_window_enabled"), &EditorInterface::is_multi_window_enabled);
847851

848852
ClassDB::bind_method(D_METHOD("get_editor_scale"), &EditorInterface::get_editor_scale);
853+
ClassDB::bind_method(D_METHOD("get_editor_language"), &EditorInterface::get_editor_language);
849854

850855
ClassDB::bind_method(D_METHOD("is_node_3d_snap_enabled"), &EditorInterface::is_node_3d_snap_enabled);
851856
ClassDB::bind_method(D_METHOD("get_node_3d_translate_snap"), &EditorInterface::get_node_3d_translate_snap);

editor/editor_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class EditorInterface : public Object {
131131
bool is_multi_window_enabled() const;
132132

133133
float get_editor_scale() const;
134+
String get_editor_language() const;
134135

135136
bool is_node_3d_snap_enabled() const;
136137
real_t get_node_3d_translate_snap() const;

editor/inspector/editor_property_name_processor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_tooltip_styl
5959
}
6060

6161
bool EditorPropertyNameProcessor::is_localization_available() {
62-
return EditorSettings::get_singleton() && EDITOR_GET("interface/editor/editor_language") != "en";
62+
return EditorSettings::get_singleton() && EditorSettings::get_singleton()->get_language() != "en";
6363
}
6464

6565
String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const {

editor/settings/editor_settings.cpp

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ void EditorSettings::_set_initialized() {
363363
initialized = true;
364364
}
365365

366+
LocalVector<String> _get_skipped_locales() {
367+
// Skip locales if Text server lack required features.
368+
LocalVector<String> locales_to_skip;
369+
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
370+
locales_to_skip.push_back("ar"); // Arabic
371+
locales_to_skip.push_back("fa"); // Persian
372+
locales_to_skip.push_back("ur"); // Urdu
373+
}
374+
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
375+
locales_to_skip.push_back("he"); // Hebrew
376+
}
377+
if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
378+
locales_to_skip.push_back("bn"); // Bengali
379+
locales_to_skip.push_back("hi"); // Hindi
380+
locales_to_skip.push_back("ml"); // Malayalam
381+
locales_to_skip.push_back("si"); // Sinhala
382+
locales_to_skip.push_back("ta"); // Tamil
383+
locales_to_skip.push_back("te"); // Telugu
384+
}
385+
return locales_to_skip;
386+
}
387+
366388
void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
367389
_THREAD_SAFE_METHOD_
368390
// Sets up the editor setting with a default value and hint PropertyInfo.
@@ -381,36 +403,18 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
381403
/* Languages */
382404

383405
{
384-
String lang_hint = ";en/[en] English";
385-
String host_lang = OS::get_singleton()->get_locale();
386-
387-
// Skip locales if Text server lack required features.
388-
Vector<String> locales_to_skip;
389-
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
390-
locales_to_skip.push_back("ar"); // Arabic
391-
locales_to_skip.push_back("fa"); // Persian
392-
locales_to_skip.push_back("ur"); // Urdu
393-
}
394-
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
395-
locales_to_skip.push_back("he"); // Hebrew
396-
}
397-
if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
398-
locales_to_skip.push_back("bn"); // Bengali
399-
locales_to_skip.push_back("hi"); // Hindi
400-
locales_to_skip.push_back("ml"); // Malayalam
401-
locales_to_skip.push_back("si"); // Sinhala
402-
locales_to_skip.push_back("ta"); // Tamil
403-
locales_to_skip.push_back("te"); // Telugu
404-
}
406+
String lang_hint;
407+
const String host_lang = OS::get_singleton()->get_locale();
405408

409+
// Skip locales which we can't render properly.
410+
const LocalVector<String> locales_to_skip = _get_skipped_locales();
406411
if (!locales_to_skip.is_empty()) {
407412
WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
408413
}
409414

410-
String best;
415+
String best = "en";
411416
int best_score = 0;
412417
for (const String &locale : get_editor_locales()) {
413-
// Skip locales which we can't render properly (see above comment).
414418
// Test against language code without regional variants (e.g. ur_PK).
415419
String lang_code = locale.get_slicec('_', 0);
416420
if (locales_to_skip.has(lang_code)) {
@@ -427,11 +431,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
427431
best_score = score;
428432
}
429433
}
430-
if (best_score == 0) {
431-
best = "en";
432-
}
434+
lang_hint = vformat(";auto/Auto (%s);en/[en] English", TranslationServer::get_singleton()->get_locale_name(best)) + lang_hint;
433435

434-
EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
436+
EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", "auto", lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
435437
}
436438

437439
// Asset library
@@ -1329,7 +1331,7 @@ void EditorSettings::create() {
13291331
}
13301332

13311333
void EditorSettings::setup_language(bool p_initial_setup) {
1332-
String lang = _EDITOR_GET("interface/editor/editor_language");
1334+
String lang = get_language();
13331335
if (p_initial_setup) {
13341336
String lang_ov = Main::get_locale_override();
13351337
if (!lang_ov.is_empty()) {
@@ -1851,6 +1853,35 @@ float EditorSettings::get_auto_display_scale() {
18511853
#endif // defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
18521854
}
18531855

1856+
String EditorSettings::get_language() const {
1857+
const String language = has_setting("interface/editor/editor_language") ? get("interface/editor/editor_language") : "auto";
1858+
if (language != "auto") {
1859+
return language;
1860+
}
1861+
1862+
// Skip locales which we can't render properly.
1863+
const LocalVector<String> locales_to_skip = _get_skipped_locales();
1864+
const String host_lang = OS::get_singleton()->get_locale();
1865+
1866+
String best = "en";
1867+
int best_score = 0;
1868+
for (const String &locale : get_editor_locales()) {
1869+
// Test against language code without regional variants (e.g. ur_PK).
1870+
String lang_code = locale.get_slicec('_', 0);
1871+
if (locales_to_skip.has(lang_code)) {
1872+
continue;
1873+
}
1874+
1875+
int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
1876+
if (score > 0 && score >= best_score) {
1877+
best = locale;
1878+
best_score = score;
1879+
}
1880+
}
1881+
1882+
return best;
1883+
}
1884+
18541885
// Shortcuts
18551886

18561887
void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {

editor/settings/editor_settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class EditorSettings : public Resource {
186186
Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
187187
String get_editor_layouts_config() const;
188188
static float get_auto_display_scale();
189+
String get_language() const;
189190

190191
void _add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut);
191192
void add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut);

modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static Process LaunchBuild(BuildInfo buildInfo, Action<string?>? stdOutH
4141
startInfo.UseShellExecute = false;
4242
startInfo.CreateNoWindow = true;
4343
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"]
44-
= ((string)editorSettings.GetSetting("interface/editor/editor_language")).Replace('_', '-');
44+
= ((string)EditorInterface.Singleton.GetEditorLanguage()).Replace('_', '-');
4545

4646
if (OperatingSystem.IsWindows())
4747
{
@@ -111,7 +111,7 @@ private static Process LaunchPublish(BuildInfo buildInfo, Action<string?>? stdOu
111111
startInfo.RedirectStandardError = true;
112112
startInfo.UseShellExecute = false;
113113
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"]
114-
= ((string)editorSettings.GetSetting("interface/editor/editor_language")).Replace('_', '-');
114+
= ((string)EditorInterface.Singleton.GetEditorLanguage()).Replace('_', '-');
115115

116116
if (OperatingSystem.IsWindows())
117117
{

0 commit comments

Comments
 (0)