-
-
Notifications
You must be signed in to change notification settings - Fork 5
Support packaging of project translation files #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nirvn
wants to merge
4
commits into
master
Choose a base branch
from
project_translation_files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,11 @@ | |
***************************************************************************/ | ||
""" | ||
|
||
import re | ||
import shutil | ||
import tempfile | ||
from enum import Enum | ||
from glob import glob | ||
from pathlib import Path | ||
from typing import Dict, List, Optional, TypedDict, Union, cast | ||
|
||
|
@@ -201,6 +203,12 @@ def _get_additional_project_files(self, project: QgsProject) -> List[str]: | |
if plugin_file.exists(): | ||
additional_project_files.append(str(plugin_file)) | ||
|
||
# Check for project translations asset | ||
for translation_file in glob( | ||
f"{str(self.original_filename)[:-4]}_[A-Za-z][A-Za-z].qm" | ||
): | ||
additional_project_files.append(str(translation_file)) | ||
|
||
return additional_project_files | ||
|
||
def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915 | ||
|
@@ -354,11 +362,45 @@ def _convert(self, project: QgsProject) -> None: # noqa: PLR0912, PLR0915 | |
project_path = Path(project.fileName()).parent | ||
for additional_project_file in additional_project_files: | ||
additional_project_file_path = Path(additional_project_file) | ||
relative_path = additional_project_file_path.relative_to(project_path) | ||
additional_project_file_name = additional_project_file_path.name | ||
additional_project_file_relative_path = ( | ||
additional_project_file_path.relative_to(project_path) | ||
) | ||
|
||
destination_file = self._export_filename.parent.joinpath( | ||
relative_path | ||
additional_project_file_relative_path | ||
).resolve() | ||
destination_file.parent.mkdir(parents=True, exist_ok=True) | ||
|
||
# Project plugins and translation files require for their file name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you see this portion of the code somehow moved to a function? I think it is a good isolated block that can be moved, the |
||
# to match that of their associated project file (e.g myproject.qgs, | ||
# myproject_bg.qm for a translation file and myproject.qml for a | ||
# project plugin). We must therefore adapt these file names to match | ||
# the generated project file name | ||
original_project_filename_without_extension = str( | ||
self.original_filename | ||
)[:-4] | ||
export_project_filename_without_extension = str( | ||
export_project_filename.name | ||
)[:-4] | ||
if ( | ||
nirvn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
str(additional_project_file_path) | ||
== f"{original_project_filename_without_extension}.qml" | ||
): | ||
destination_file = destination_file.parent.joinpath( | ||
f"{export_project_filename_without_extension}.qml" | ||
) | ||
|
||
elif additional_project_file_name.endswith(".qm"): | ||
match = re.match( | ||
rf"^{re.escape(original_project_filename_without_extension)}(_[A-Za-z]{{2}}\.qm)$", | ||
str(additional_project_file_path), | ||
) | ||
if match: | ||
destination_file = destination_file.parent.joinpath( | ||
f"{export_project_filename_without_extension}{match.group(1)}" | ||
) | ||
|
||
shutil.copy(additional_project_file, str(destination_file)) | ||
|
||
# save the offline project twice so that the offline plugin can "know" that it's a relative path | ||
|
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use the same pattern, so here also make
[A-Za-z]{2}
?