Skip to content

Commit

Permalink
Merge pull request #58706 from timothyqiu/property-i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Mar 10, 2022
2 parents 1c51fd4 + d6df2ff commit 7e4a8d3
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 87 deletions.
4 changes: 3 additions & 1 deletion editor/editor_feature_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/io/json.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"

Expand Down Expand Up @@ -617,7 +618,8 @@ void EditorFeatureProfileManager::_class_list_item_selected() {
property->set_editable(0, true);
property->set_selectable(0, true);
property->set_checked(0, !edited->is_class_property_disabled(class_name, name));
property->set_text(0, name.capitalize());
property->set_text(0, EditorPropertyNameProcessor::get_singleton()->process_name(name));
property->set_tooltip(0, EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(name));
property->set_metadata(0, name);
String icon_type = Variant::get_type_name(E.type);
property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type));
Expand Down
13 changes: 8 additions & 5 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "editor/doc_tools.h"
#include "editor/editor_feature_profile.h"
#include "editor/editor_node.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "multi_node_edit.h"
Expand Down Expand Up @@ -2680,10 +2681,10 @@ void EditorInspector::update_tree() {
if (dot != -1) {
String ov = property_label_string.substr(dot);
property_label_string = property_label_string.substr(0, dot);
property_label_string = property_label_string.capitalize();
property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
property_label_string += ov;
} else {
property_label_string = property_label_string.capitalize();
property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
}
}

Expand Down Expand Up @@ -2734,13 +2735,15 @@ void EditorInspector::update_tree() {
current_vbox->add_child(section);
sections.push_back(section);

String label = component;
if (capitalize_paths) {
component = component.capitalize();
label = EditorPropertyNameProcessor::get_singleton()->process_name(label);
}

Color c = sscolor;
c.a /= level;
section->setup(acc_path, component, object, c, use_folding, section_depth);
section->setup(acc_path, label, object, c, use_folding, section_depth);
section->set_tooltip(EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(component));

// Add editors at the start of a group.
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
Expand Down Expand Up @@ -2772,7 +2775,7 @@ void EditorInspector::update_tree() {
editor_inspector_array = memnew(EditorInspectorArray);

String array_label = path.contains("/") ? path.substr(path.rfind("/") + 1) : path;
array_label = property_label_string.capitalize();
array_label = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;
editor_inspector_array->setup_with_move_element_function(object, array_label, array_element_prefix, page, c, use_folding);
editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request), varray(array_element_prefix));
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#include "editor/editor_paths.h"
#include "editor/editor_plugin.h"
#include "editor/editor_properties.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_resource_picker.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_run.h"
Expand Down Expand Up @@ -5803,6 +5804,9 @@ void EditorNode::notify_settings_changed() {
}

EditorNode::EditorNode() {
EditorPropertyNameProcessor *epnp = memnew(EditorPropertyNameProcessor);
add_child(epnp);

Input::get_singleton()->set_use_accumulated_input(true);
Resource::_get_local_scene_func = _resource_get_edited_scene;

Expand Down Expand Up @@ -6025,6 +6029,7 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/editor/save_on_focus_loss", false);
EDITOR_DEF("interface/editor/show_update_spinner", false);
EDITOR_DEF("interface/editor/update_continuously", false);
EDITOR_DEF("interface/editor/translate_properties", true);
EDITOR_DEF_RST("interface/scene_tabs/restore_scenes_on_load", true);
EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
EDITOR_DEF_RST("interface/inspector/default_float_step", 0.001);
Expand Down
121 changes: 121 additions & 0 deletions editor/editor_property_name_processor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*************************************************************************/
/* editor_property_name_processor.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#include "editor_property_name_processor.h"

#include "editor_settings.h"

EditorPropertyNameProcessor *EditorPropertyNameProcessor::singleton = nullptr;

String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const {
String capitalized_string = p_name.capitalize();

// Fix the casing of a few strings commonly found in editor property/setting names.
for (Map<String, String>::Element *E = capitalize_string_remaps.front(); E; E = E->next()) {
capitalized_string = capitalized_string.replace(E->key(), E->value());
}

return capitalized_string;
}

String EditorPropertyNameProcessor::process_name(const String &p_name) const {
const String capitalized_string = _capitalize_name(p_name);
if (EDITOR_GET("interface/editor/translate_properties")) {
return TTRGET(capitalized_string);
}
return capitalized_string;
}

String EditorPropertyNameProcessor::make_tooltip_for_name(const String &p_name) const {
const String capitalized_string = _capitalize_name(p_name);
if (EDITOR_GET("interface/editor/translate_properties")) {
return capitalized_string;
}
return TTRGET(capitalized_string);
}

EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;

// The following initialization is parsed in `editor/translations/extract.py` with a regex.
// The map name and value definition format should be kept synced with the regex.
capitalize_string_remaps["2d"] = "2D";
capitalize_string_remaps["3d"] = "3D";
capitalize_string_remaps["Adb"] = "ADB";
capitalize_string_remaps["Bptc"] = "BPTC";
capitalize_string_remaps["Bvh"] = "BVH";
capitalize_string_remaps["Csg"] = "CSG";
capitalize_string_remaps["Cpu"] = "CPU";
capitalize_string_remaps["Db"] = "dB";
capitalize_string_remaps["Dof"] = "DoF";
capitalize_string_remaps["Dpi"] = "DPI";
capitalize_string_remaps["Etc"] = "ETC";
capitalize_string_remaps["Fbx"] = "FBX";
capitalize_string_remaps["Fps"] = "FPS";
capitalize_string_remaps["Fov"] = "FOV";
capitalize_string_remaps["Fs"] = "FS";
capitalize_string_remaps["Fxaa"] = "FXAA";
capitalize_string_remaps["Ggx"] = "GGX";
capitalize_string_remaps["Gdscript"] = "GDScript";
capitalize_string_remaps["Gles 2"] = "GLES2";
capitalize_string_remaps["Gles 3"] = "GLES3";
capitalize_string_remaps["Gi Probe"] = "GI Probe";
capitalize_string_remaps["Hdr"] = "HDR";
capitalize_string_remaps["Hidpi"] = "hiDPI";
capitalize_string_remaps["Ik"] = "IK";
capitalize_string_remaps["Ios"] = "iOS";
capitalize_string_remaps["Kb"] = "KB";
capitalize_string_remaps["Msaa"] = "MSAA";
capitalize_string_remaps["Macos"] = "macOS";
capitalize_string_remaps["Opentype"] = "OpenType";
capitalize_string_remaps["Png"] = "PNG";
capitalize_string_remaps["Pvs"] = "PVS";
capitalize_string_remaps["Pvrtc"] = "PVRTC";
capitalize_string_remaps["S 3 Tc"] = "S3TC";
capitalize_string_remaps["Sdfgi"] = "SDFGI";
capitalize_string_remaps["Srgb"] = "sRGB";
capitalize_string_remaps["Ssao"] = "SSAO";
capitalize_string_remaps["Ssl"] = "SSL";
capitalize_string_remaps["Ssh"] = "SSH";
capitalize_string_remaps["Sdk"] = "SDK";
capitalize_string_remaps["Tcp"] = "TCP";
capitalize_string_remaps["Uv 1"] = "UV1";
capitalize_string_remaps["Uv 2"] = "UV2";
capitalize_string_remaps["Vram"] = "VRAM";
capitalize_string_remaps["Vsync"] = "V-Sync";
capitalize_string_remaps["Vector 2"] = "Vector2";
capitalize_string_remaps["Webrtc"] = "WebRTC";
capitalize_string_remaps["Websocket"] = "WebSocket";
}

EditorPropertyNameProcessor::~EditorPropertyNameProcessor() {
singleton = nullptr;
}
58 changes: 58 additions & 0 deletions editor/editor_property_name_processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*************************************************************************/
/* editor_property_name_processor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#ifndef EDITOR_PROPERTY_NAME_PROCESSOR_H
#define EDITOR_PROPERTY_NAME_PROCESSOR_H

#include "scene/main/node.h"

class EditorPropertyNameProcessor : public Node {
GDCLASS(EditorPropertyNameProcessor, Node);

static EditorPropertyNameProcessor *singleton;

Map<String, String> capitalize_string_remaps;

String _capitalize_name(const String &p_name) const;

public:
static EditorPropertyNameProcessor *get_singleton() { return singleton; }

// Capitalize & localize property path segments.
String process_name(const String &p_name) const;

// Make tooltip string for names processed by process_name().
String make_tooltip_for_name(const String &p_name) const;

EditorPropertyNameProcessor();
~EditorPropertyNameProcessor();
};

#endif // EDITOR_PROPERTY_NAME_PROCESSOR_H
4 changes: 3 additions & 1 deletion editor/editor_sectioned_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "editor_sectioned_inspector.h"

#include "editor/editor_property_name_processor.h"
#include "editor/editor_scale.h"

class SectionedInspectorFilter : public Object {
Expand Down Expand Up @@ -259,7 +260,8 @@ void SectionedInspector::update_category_list() {
if (!section_map.has(metasection)) {
TreeItem *ms = sections->create_item(parent);
section_map[metasection] = ms;
ms->set_text(0, sectionarr[i].capitalize());
ms->set_text(0, EditorPropertyNameProcessor::get_singleton()->process_name(sectionarr[i]));
ms->set_tooltip(0, EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(sectionarr[i]));
ms->set_metadata(0, metasection);
ms->set_selectable(0, false);
}
Expand Down
4 changes: 3 additions & 1 deletion editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "editor/editor_file_system.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/gui/margin_container.h"
Expand Down Expand Up @@ -430,8 +431,9 @@ void EditorSettingsDialog::_update_shortcuts() {
} else {
section = shortcuts->create_item(root);

String item_name = section_name.capitalize();
String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name);
section->set_text(0, item_name);
section->set_tooltip(0, EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(section_name));
section->set_selectable(0, false);
section->set_selectable(1, false);
section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
Expand Down
Loading

0 comments on commit 7e4a8d3

Please sign in to comment.