Skip to content

Commit b99a971

Browse files
committed
Merge pull request godotengine#103120 from lyuma/fix_translation_uid_hash
CSV import: Generate positve UID for .translation and follow renames
2 parents 17b3be9 + f2ad430 commit b99a971

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

editor/import/resource_importer_csv_translation.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,22 @@ Error ResourceImporterCSVTranslation::import(ResourceUID::ID p_source_id, const
142142
}
143143

144144
String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation";
145+
ResourceUID::ID save_id = hash64_murmur3_64(translations[i]->get_locale().hash64(), p_source_id) & 0x7FFFFFFFFFFFFFFF;
146+
bool uid_already_exists = ResourceUID::get_singleton()->has_id(save_id);
147+
if (uid_already_exists) {
148+
// Avoid creating a new file with a duplicate UID.
149+
// Always use this UID, even if the user has moved it to a different path.
150+
save_path = ResourceUID::get_singleton()->get_id_path(save_id);
151+
}
145152

146153
ResourceSaver::save(xlt, save_path);
147154
if (r_gen_files) {
148155
r_gen_files->push_back(save_path);
149156
}
150-
151-
ResourceUID::ID save_id = hash64_murmur3_64(translations[i]->get_locale().hash64(), p_source_id);
152-
ResourceSaver::set_uid(save_path, save_id);
157+
if (!uid_already_exists) {
158+
// No need to call set_uid if save_path already refers to save_id.
159+
ResourceSaver::set_uid(save_path, save_id);
160+
}
153161
}
154162

155163
return OK;

0 commit comments

Comments
 (0)