From 12cb6386f6bb4e82dcc1105616181a7dc251fe02 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 4 Mar 2022 15:04:59 +0200 Subject: Improve app name and system permission message localization. Add localizable string (Dictionary) property editor and property hint. Add localized "app name" property to the project settings. Add localized permission and copyright properties to the macOS and iOS export settings. Remove some duplicated ("app name") and deprecated ("info") macOS and iOS export properties. --- editor/editor_properties_array_dict.cpp | 232 +++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 4 deletions(-) (limited to 'editor/editor_properties_array_dict.cpp') diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 61261af608..302cc9c28c 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -742,7 +742,7 @@ void EditorPropertyDictionary::_property_changed(const String &p_property, Varia emit_changed(get_edited_property(), dict, "", true); - dict = dict.duplicate(); // Duplicate, so undo/redo works better\. + dict = dict.duplicate(); // Duplicate, so undo/redo works better. object->set_dict(dict); } } @@ -805,7 +805,7 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) { emit_changed(get_edited_property(), dict, "", false); - dict = dict.duplicate(); // Duplicate, so undo/redo works better\. + dict = dict.duplicate(); // Duplicate, so undo/redo works better. object->set_dict(dict); update_property(); } @@ -814,7 +814,7 @@ void EditorPropertyDictionary::update_property() { Variant updated_val = get_edited_object()->get(get_edited_property()); if (updated_val.get_type() == Variant::NIL) { - edit->set_text("Dictionary (Nil)"); // This provides symmetry with the array property. + edit->set_text(TTR("Dictionary (Nil)")); // This provides symmetry with the array property. edit->set_pressed(false); if (vbox) { set_bottom_editor(nullptr); @@ -826,7 +826,7 @@ void EditorPropertyDictionary::update_property() { Dictionary dict = updated_val; - edit->set_text("Dictionary (size " + itos(dict.size()) + ")"); + edit->set_text(vformat(TTR("Dictionary (size %d)"), dict.size())); bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); if (edit->is_pressed() != unfolded) { @@ -1144,6 +1144,7 @@ void EditorPropertyDictionary::update_property() { if (vbox) { set_bottom_editor(nullptr); memdelete(vbox); + button_add_item = nullptr; vbox = nullptr; } } @@ -1216,3 +1217,226 @@ EditorPropertyDictionary::EditorPropertyDictionary() { change_type->connect("id_pressed", callable_mp(this, &EditorPropertyDictionary::_change_type_menu)); changing_type_index = -1; } + +///////////////////// LOCALIZABLE STRING /////////////////////////// + +void EditorPropertyLocalizableString::_property_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing) { + if (p_property.begins_with("indices")) { + int index = p_property.get_slice("/", 1).to_int(); + Dictionary dict = object->get_dict(); + Variant key = dict.get_key_at_index(index); + dict[key] = p_value; + + emit_changed(get_edited_property(), dict, "", true); + + dict = dict.duplicate(); // Duplicate, so undo/redo works better. + object->set_dict(dict); + } +} + +void EditorPropertyLocalizableString::_add_locale_popup() { + locale_select->popup_locale_dialog(); +} + +void EditorPropertyLocalizableString::_add_locale(const String &p_locale) { + Dictionary dict = object->get_dict(); + + object->set_new_item_key(p_locale); + object->set_new_item_value(String()); + dict[object->get_new_item_key()] = object->get_new_item_value(); + + emit_changed(get_edited_property(), dict, "", false); + + dict = dict.duplicate(); // Duplicate, so undo/redo works better. + object->set_dict(dict); + update_property(); +} + +void EditorPropertyLocalizableString::_remove_item(Object *p_button, int p_index) { + Dictionary dict = object->get_dict(); + + Variant key = dict.get_key_at_index(p_index); + dict.erase(key); + + emit_changed(get_edited_property(), dict, "", false); + + dict = dict.duplicate(); // Duplicate, so undo/redo works better. + object->set_dict(dict); + update_property(); +} + +void EditorPropertyLocalizableString::update_property() { + Variant updated_val = get_edited_object()->get(get_edited_property()); + + if (updated_val.get_type() == Variant::NIL) { + edit->set_text(TTR("Localizable String (Nil)")); // This provides symmetry with the array property. + edit->set_pressed(false); + if (vbox) { + set_bottom_editor(nullptr); + memdelete(vbox); + vbox = nullptr; + } + return; + } + + Dictionary dict = updated_val; + + edit->set_text(vformat(TTR("Localizable String (size %d)"), dict.size())); + + bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); + if (edit->is_pressed() != unfolded) { + edit->set_pressed(unfolded); + } + + if (unfolded) { + updating = true; + + if (!vbox) { + vbox = memnew(VBoxContainer); + add_child(vbox); + set_bottom_editor(vbox); + + property_vbox = memnew(VBoxContainer); + property_vbox->set_h_size_flags(SIZE_EXPAND_FILL); + vbox->add_child(property_vbox); + + paginator = memnew(EditorPaginator); + paginator->connect("page_changed", callable_mp(this, &EditorPropertyLocalizableString::_page_changed)); + vbox->add_child(paginator); + } else { + // Queue children for deletion, deleting immediately might cause errors. + for (int i = property_vbox->get_child_count() - 1; i >= 0; i--) { + property_vbox->get_child(i)->queue_delete(); + } + } + + int size = dict.size(); + + int max_page = MAX(0, size - 1) / page_length; + page_index = MIN(page_index, max_page); + + paginator->update(page_index, max_page); + paginator->set_visible(max_page > 0); + + int offset = page_index * page_length; + + int amount = MIN(size - offset, page_length); + + dict = dict.duplicate(); + + object->set_dict(dict); + + for (int i = 0; i < amount; i++) { + String prop_name; + Variant key; + Variant value; + + prop_name = "indices/" + itos(i + offset); + key = dict.get_key_at_index(i + offset); + value = dict.get_value_at_index(i + offset); + + EditorProperty *prop = memnew(EditorPropertyText); + + prop->set_object_and_property(object.ptr(), prop_name); + int remove_index = 0; + + String cs = key.get_construct_string(); + prop->set_label(cs); + prop->set_tooltip(cs); + remove_index = i + offset; + + prop->set_selectable(false); + prop->connect("property_changed", callable_mp(this, &EditorPropertyLocalizableString::_property_changed)); + prop->connect("object_id_selected", callable_mp(this, &EditorPropertyLocalizableString::_object_id_selected)); + + HBoxContainer *hbox = memnew(HBoxContainer); + property_vbox->add_child(hbox); + hbox->add_child(prop); + prop->set_h_size_flags(SIZE_EXPAND_FILL); + Button *edit = memnew(Button); + edit->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + hbox->add_child(edit); + edit->connect("pressed", callable_mp(this, &EditorPropertyLocalizableString::_remove_item), varray(edit, remove_index)); + + prop->update_property(); + } + + if (page_index == max_page) { + button_add_item = memnew(Button); + button_add_item->set_text(TTR("Add Translation")); + button_add_item->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + button_add_item->connect("pressed", callable_mp(this, &EditorPropertyLocalizableString::_add_locale_popup)); + property_vbox->add_child(button_add_item); + } + + updating = false; + + } else { + if (vbox) { + set_bottom_editor(nullptr); + memdelete(vbox); + button_add_item = nullptr; + vbox = nullptr; + } + } +} + +void EditorPropertyLocalizableString::_object_id_selected(const StringName &p_property, ObjectID p_id) { + emit_signal(SNAME("object_id_selected"), p_property, p_id); +} + +void EditorPropertyLocalizableString::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { + if (Object::cast_to