Fix CSV translation not updating after reimport #107410
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up to #96921.
One of the known issues is updating CSV translations don't update preview text in the editor.
Fix updating CSV translation files not updating preview text in the editor
Unlike
.po
files, importing a.csv
file as translations does not "import" the file as any resource. The.translation
files are extra files generated during the "import as nothing" process.A non-imported resource file is only reloaded if the file's last modified time change. I think this logic was only considering external changes to resource files since the editor hooks into the resource saving process, tracking the file's last modified time automatically. So the newly generated
.translation
files won't be reloaded as the file's last modified time is always up-to-date.Fortunately,Resource
tracks its last modified time too. So we can compare the file's last modified time with the cached resource's last modified time.This PR forces a reload of the resource caches corresponding to the generated files at the end of the import process.
Only update translation when necessary
Currently,
NOTIFICATION_TRANSLATION_CHANGED
is propagated in the editing scene tree whenever project settings change. This is unnecessary and could make the stuttering worse if the editing scene is very complex.In this PR, when project settings change, the notification is propagated only if the translation file set of the currently previewing locale is changed.
In order to compare
HashSet
equality, I addedoperator{==,!=}
for it and related tests.Simplify the preview toggle logic
Originally, the translation preview PR turns translation preview on/off by updating the editing scene root's auto translation mode. Later, this was changed to disabling the entire translation domain for identifier-based translation.
The change made changing auto translation mode unnecessary, but this fact was made less obvious by some optimization logic :(
Here is a test project with a demo scene showing translatable texts from PO and CSV files: test-4.zip