Bug 402890 - Menu items ‘Open selected files’/‘Open’ overwrites template files instead of creating translation files
Summary: Menu items ‘Open selected files’/‘Open’ overwrites template files instead of ...
Status: RESOLVED FIXED
Alias: None
Product: lokalize
Classification: Applications
Component: project management (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR major
Target Milestone: ---
Assignee: Simon Depiets
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-05 12:21 UTC by Karl Ove Hufthammer
Modified: 2020-06-28 02:11 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Ove Hufthammer 2019-01-05 12:21:01 UTC
SUMMARY
In the project view, when one right-clicks on a folder which contain a completely untranslated catalogue (i.e. one which only exists as a .pot file, not a ‘.po’ file) and selects ‘Open selected files’, the .pot file is opened instead of a .po file being created. The same thing happens when you right-click on a .pot file and selected ‘Open’.

When saving the file, the original .pot file is overwritten, making it an invalid .pot file, i.e. one containing translations.


STEPS TO REPRODUCE
1. Open a translation project which contain at least one non-translated files (e.g. use the Norwegian Nynorsk project ‘trunk/l10n-support/nn/kde-nynorsk.lokalize’ in the KDE repository).
2. Right-click on a folder which contain non-translated files (.pot files) (e.g. ‘extragear-edu’ for the Norwegian Nynorsk project) and select ‘Open selected files’
3. Navigate the one of the .pot files, edit a string and save the file.

OBSERVED RESULT
The .pot file in the template folder is opened and saved.


EXPECTED RESULT
A corresponding .po file in translation folder should be created/saved.


ADDITIONAL INFORMATION
Opening a .pot file by double-clicking on it, works fine. That is, a .po file is created in the translation folder when you save the file. And the name of tab is ‘filename.po’, not ‘filename.pot’, to reflect that you’re editing the .po translation file, not the .pot template file.

So it is only when opening files using the ‘Open selected files’ menu item in the right-click menu on a folder or the ‘Open’ menu item in the right-click menu on a file that the wrong file is opened/saved.

I set the ‘Severity’ to a ‘Major’, as this bug can lead to data-loss (overwriting template files).

I observe this bug using the latest Git version of Lokalize (Lokalize 19.03.70 – not possible to choose this version number in Bugzilla).
Comment 1 Simon Depiets 2019-03-05 14:57:01 UTC
> A corresponding .po file in translation folder should be created/saved.

How should it be named ? What should happen if there's already a .po file with that same name ? A dialog would be fine in that case ?
Comment 2 Alexander Potashev 2019-03-05 15:24:38 UTC
1. .po naming algorithm should be the same as if you clicked the same .pot template in the Project Browser tab.

2. When the .po already exists, I think it should open the existing .po file and may be display a messagebox saying something like "<p>Translation catalog %1 for the template %2 already exists. Lokalize opened the existing catalog for you.</p><p>If you wanted to create an empty catalog using the template, delete the existing catalog and try again.</p>".
(However it's a very rare case when someone creates .po file with external tools and then goes back to Lokalize to perform the same task.)
Comment 3 Karl Ove Hufthammer 2019-03-10 15:28:47 UTC
IMHO, if there already is a .po file with that name, this should be opened. It’s not necessary to show a dialogue. Basically, clicking a file opens that *catalogue*, which is always a PO file, either an automatically created file (when saved) or an existing PO file.
Comment 4 Simon Depiets 2020-06-06 15:18:37 UTC
Revisiting this now, should the .po file be next to the .pot by default and we let the user move the generated .po file by himself if he has a different folder structure?
Comment 5 Karl Ove Hufthammer 2020-06-06 17:05:36 UTC
(In reply to Simon Depiets from comment #4)
> Revisiting this now, should the .po file be next to the .pot by default and
> we let the user move the generated .po file by himself if he has a different
> folder structure?

No. The PO file structure mirrors the POT file structure. The structure is set up in the project options (root folder for the PO files, template folder for the POT files).

So if the POT file is at
~/kde/trunk/l10n-support/templates/summit/messages/kpat/kpat_mimetypes.pot

and the PO file is at
~/kde/trunk/l10n-support/nn/summit/messages/kpat/kpat_mimetypes.po

the template folder would be set to (for example)
~/kde/trunk/l10n-support/templates/summit/messages

and the root folder would be set to
~/kde/trunk/l10n-support/nn/summit/messages

Lokalize handles this perfectly file if you *click* on a single POT file (which doesn’t have a PO file). The PO file is automatically stored in the correct place, in a folder structure in the root folder mirroring the folder structure in the templates folder. It’s when you instead use the ‘Open selected files’ on a folder containing POT files that the PO files generated are stored in the wrong place (and with the wrong extension, POT instead of PO).

So perhaps the two ways of creating a PO file from a POT files doesn’t use the same code path?
Comment 6 Karl Ove Hufthammer 2020-06-06 17:18:51 UTC
BTW, note the difference between 1) *left-clicking* on a POT file and 2) *right-clicking* on a POT file and selecting ‘Open’. The former creates a PO file in the correct place. The latter overwrites the POT file (with a file containing any translations added).

Right-clicking on either multiple POT files or a folder containing POT files and selecting ‘Open selected files’ works the same way as option 2 above, i.e., it overwrites the POT files.
Comment 7 Albert Astals Cid 2020-06-08 20:43:52 UTC
@Simon so the difference is that left clicking goes through ProjectWidget::slotItemActivated that calls 
ProjectModell::beginEditing //copies POT file to PO file and returns url of the PO file
and then calls fileOpenRequested on it
while right mouse button just calls fileOpenRequested on the files themselves.

Personally i'm not totally sure that "Open" should be creating a new file, if not, we should add a new action for .pot files that is "Create .po and start editing" or something.
Comment 8 Simon Depiets 2020-06-09 00:44:07 UTC
Ok I have a better understanding of the issue now, I'll work on it
Comment 9 Simon Depiets 2020-06-28 02:11:35 UTC
Git commit ddb662f89bb06e4c828b7b5250c8ad81b6df5ba4 by Simon Depiets.
Committed on 14/06/2020 at 17:41.
Pushed by sdepiets into branch 'master'.

Harmonize file open behavior for .pot

M  +3    -3    src/project/projectmodel.h
M  +4    -1    src/project/projecttab.cpp

https://invent.kde.org/sdk/lokalize/commit/ddb662f89bb06e4c828b7b5250c8ad81b6df5ba4