Skip to content

Conversation

nirvn
Copy link
Member

@nirvn nirvn commented Sep 14, 2025

This unlocks translated projects on QFieldCloud by insuring that {project name}_{2-letter language code}.qm files are copied into the packaged project directory.

The PR also insures that sidecar translations and project plugin files properly adopt the exported project name (i.e. myproject.qgs -> myproject_cloud.qgs means the project plugin file will become myproject_cloud.qml and translation files would be myproject_de.qm, myproject_fr.qm, etc.).

Test coverage included.

Comment on lines 365 to 367
additional_project_file_name = additional_project_file_path.name

additional_project_file_relative_path = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
additional_project_file_name = additional_project_file_path.name
additional_project_file_relative_path = (
additional_project_file_name = additional_project_file_path.name
additional_project_file_relative_path = (

Just wondering if this empty line was on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was on purpose, but let's remove it if you prefer it that way.


elif additional_project_file_name.endswith(".qm"):
match = re.match(
rf"^{re.escape(str(self.original_filename)[:-4])}(_[A-Za-z][A-Za-z]\.qm)$",
Copy link
Collaborator

@suricactus suricactus Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rf"^{re.escape(str(self.original_filename)[:-4])}(_[A-Za-z][A-Za-z]\.qm)$",
rf"^{re.escape(original_filename_stem}(_[A-Za-z]{2}\.qm)$",

This is still convoluted, but slightly more readable. I would even go for:

Suggested change
rf"^{re.escape(str(self.original_filename)[:-4])}(_[A-Za-z][A-Za-z]\.qm)$",
"{}_[A-Za-z]{2}.qm".format(
re.escape(original_filename_stem),
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pre-commit force the re.escape back inside the rf"..." over here, so seems like the gods want it that way.

I did however change to [A-Za-z]{{2}} , and I'm using a variable for the original file path without the extension suffix, so we're mostly there.

Copy link
Collaborator

@suricactus suricactus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice functionality, +1 for the tests.

Code looks good. A few tiny comments on readability. Feel free to merge.

Do you consider this "QFieldCloud sensitive files", such as the plugins? Shall we add them here:
https://github.com/opengisch/QFieldCloud/blob/master/docker-app/qfieldcloud/filestorage/utils.py#L69

@nirvn
Copy link
Member Author

nirvn commented Sep 17, 2025

@suricactus , review addressed thanks.

Regarding "sensitive files", I wouldn't flag the translations as being sensitive. If you have a strong feeling about it, we can add it into the above-mentioned function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants