Change translation remaps if files are moved
This commit is contained in:
parent
119b2874c3
commit
897d02e2a0
|
@ -6877,6 +6877,7 @@ EditorNode::EditorNode() {
|
|||
filesystem_dock->connect("inherit", callable_mp(this, &EditorNode::_inherit_request));
|
||||
filesystem_dock->connect("instance", callable_mp(this, &EditorNode::_instantiate_request));
|
||||
filesystem_dock->connect("display_mode_changed", callable_mp(this, &EditorNode::_save_docks));
|
||||
project_settings->connect_filesystem_dock_signals(filesystem_dock);
|
||||
|
||||
// Scene: Top left.
|
||||
dock_slot[DOCK_SLOT_LEFT_UR]->add_child(SceneTreeDock::get_singleton());
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_translation_parser.h"
|
||||
#include "editor/filesystem_dock.h"
|
||||
#include "editor/pot_generator.h"
|
||||
#include "scene/gui/control.h"
|
||||
|
||||
|
@ -379,6 +380,62 @@ void LocalizationEditor::_update_pot_file_extensions() {
|
|||
}
|
||||
}
|
||||
|
||||
void LocalizationEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) {
|
||||
p_fs_dock->connect("files_moved", callable_mp(this, &LocalizationEditor::_filesystem_files_moved));
|
||||
}
|
||||
|
||||
void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const String &p_new_file) {
|
||||
// Update remaps if the moved file is a part of them.
|
||||
Dictionary remaps;
|
||||
bool remaps_changed = false;
|
||||
|
||||
if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/translation_remaps")) {
|
||||
remaps = ProjectSettings::get_singleton()->get("internationalization/locale/translation_remaps");
|
||||
}
|
||||
|
||||
// Check for the keys.
|
||||
if (remaps.has(p_old_file)) {
|
||||
PackedStringArray remapped_files = remaps[p_old_file];
|
||||
remaps.erase(p_old_file);
|
||||
remaps[p_new_file] = remapped_files;
|
||||
remaps_changed = true;
|
||||
print_verbose(vformat("Changed remap key \"%s\" to \"%s\" due to a moved file.", p_old_file, p_new_file));
|
||||
}
|
||||
|
||||
// Check for the Array elements of the values.
|
||||
Array remap_keys = remaps.keys();
|
||||
for (int i = 0; i < remap_keys.size(); i++) {
|
||||
PackedStringArray remapped_files = remaps[remap_keys[i]];
|
||||
bool remapped_files_updated = false;
|
||||
|
||||
for (int j = 0; j < remapped_files.size(); j++) {
|
||||
// Find the first ':' after 'res://'.
|
||||
int splitter_pos = remapped_files[j].find(":", remapped_files[j].find("/"));
|
||||
String res_path = remapped_files[j].substr(0, splitter_pos);
|
||||
|
||||
if (res_path == p_old_file) {
|
||||
String locale_name = remapped_files[j].substr(splitter_pos + 1);
|
||||
// Replace the element at that index.
|
||||
remapped_files.insert(j, p_new_file + ":" + locale_name);
|
||||
remapped_files.remove_at(j + 1);
|
||||
remaps_changed = true;
|
||||
remapped_files_updated = true;
|
||||
print_verbose(vformat("Changed remap value \"%s\" to \"%s\" of key \"%s\" due to a moved file.", res_path + ":" + locale_name, remapped_files[j], remap_keys[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (remapped_files_updated) {
|
||||
remaps[remap_keys[i]] = remapped_files;
|
||||
}
|
||||
}
|
||||
|
||||
if (remaps_changed) {
|
||||
ProjectSettings::get_singleton()->set_setting("internationalization/locale/translation_remaps", remaps);
|
||||
update_translations();
|
||||
emit_signal("localization_changed");
|
||||
}
|
||||
}
|
||||
|
||||
void LocalizationEditor::update_translations() {
|
||||
if (updating_translations) {
|
||||
return;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "scene/gui/tree.h"
|
||||
|
||||
class EditorFileDialog;
|
||||
class FileSystemDock;
|
||||
|
||||
class LocalizationEditor : public VBoxContainer {
|
||||
GDCLASS(LocalizationEditor, VBoxContainer);
|
||||
|
@ -81,6 +82,8 @@ class LocalizationEditor : public VBoxContainer {
|
|||
void _pot_generate(const String &p_file);
|
||||
void _update_pot_file_extensions();
|
||||
|
||||
void _filesystem_files_moved(const String &p_old_file, const String &p_new_file);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
@ -88,6 +91,7 @@ protected:
|
|||
public:
|
||||
void add_translation(const String &p_translation);
|
||||
void update_translations();
|
||||
void connect_filesystem_dock_signals(FileSystemDock *p_fs_dock);
|
||||
|
||||
LocalizationEditor();
|
||||
};
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
|
||||
ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr;
|
||||
|
||||
void ProjectSettingsEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) {
|
||||
localization_editor->connect_filesystem_dock_signals(p_fs_dock);
|
||||
}
|
||||
|
||||
void ProjectSettingsEditor::popup_project_settings() {
|
||||
// Restore valid window bounds or pop up at default size.
|
||||
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "project_settings", Rect2());
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include "editor/shader_globals_editor.h"
|
||||
#include "scene/gui/tab_container.h"
|
||||
|
||||
class FileSystemDock;
|
||||
|
||||
class ProjectSettingsEditor : public AcceptDialog {
|
||||
GDCLASS(ProjectSettingsEditor, AcceptDialog);
|
||||
|
||||
|
@ -120,6 +122,7 @@ public:
|
|||
TabContainer *get_tabs() { return tab_container; }
|
||||
|
||||
void queue_save();
|
||||
void connect_filesystem_dock_signals(FileSystemDock *p_fs_dock);
|
||||
|
||||
ProjectSettingsEditor(EditorData *p_data);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue