Skip to content

Commit 3d02ee3

Browse files
committed
Insure that project translation as well as project plugin files adopt new project name
1 parent bcffb18 commit 3d02ee3

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

libqfieldsync/offline_converter.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************/
1818
"""
1919

20+
import re
2021
import shutil
2122
import tempfile
2223
from enum import Enum
@@ -361,11 +362,35 @@ def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915
361362
project_path = Path(project.fileName()).parent
362363
for additional_project_file in additional_project_files:
363364
additional_project_file_path = Path(additional_project_file)
364-
relative_path = additional_project_file_path.relative_to(project_path)
365+
additional_project_file_name = additional_project_file_path.name
366+
367+
additional_project_file_relative_path = (
368+
additional_project_file_path.relative_to(project_path)
369+
)
370+
365371
destination_file = self._export_filename.parent.joinpath(
366-
relative_path
372+
additional_project_file_relative_path
367373
).resolve()
368374
destination_file.parent.mkdir(parents=True, exist_ok=True)
375+
376+
if (
377+
str(additional_project_file_path)
378+
== f"{str(self.original_filename)[:-4]}.qml"
379+
):
380+
destination_file = destination_file.parent.joinpath(
381+
f"{str(export_project_filename.name)[:-4]}.qml"
382+
)
383+
384+
elif additional_project_file_name.endswith(".qm"):
385+
match = re.match(
386+
rf"^{re.escape(str(self.original_filename)[:-4])}(_[A-Za-z][A-Za-z]\.qm)$",
387+
str(additional_project_file_path),
388+
)
389+
if match:
390+
destination_file = destination_file.parent.joinpath(
391+
f"{str(export_project_filename.name)[:-4]}{match.group(1)}"
392+
)
393+
369394
shutil.copy(additional_project_file, str(destination_file))
370395

371396
# save the offline project twice so that the offline plugin can "know" that it's a relative path

0 commit comments

Comments
 (0)