Skip to content
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

translations: Add more validation, fix many formatting errors #620

Merged

Conversation

deltragon
Copy link
Collaborator

@deltragon deltragon commented Aug 4, 2024

Fixes #618.
Partially addresses #608.

This PR strongly expands validate_po.py, which now checks the following:

  • Translated files have no incorrect placeholders, which would lead to runtime errors.
    There were multiple such cases, including:
    • Unnamed placeholder missing in translation (this was the issue in CI failing due to invalid translations #618)
    • Placeholder in translation broken (eg. % instead of %s, d% instead of %d in RTL languages)
    • Named placeholder in translation that does not exist in original (eg. %(translated_name)s instead of %(name)s)
  • Named placeholders are used for plural forms.
    This is not a runtime error on its own - however, many languages translate singular forms with words ("one hour") instead of numbers ("1 hour"). When using unnamed placeholders, this leads to a runtime error again.
  • At most one unnamed placeholder is used.
    This means that translations can reorder the sentence as needed.
  • The template (.pot) file contains all translatable strings.

Additionally, this PR

  • fixes all cases that violated the (old and new) checks
  • adds the #, python-format annotation to strings with placeholders, so Weblate can also validate them
  • adds a method to extract the translatable strings into the template file (python validate_po.py --extract) - which also adds/preserves the annotation strings
  • adds all missing translatable strings to the template, or marks them as not translatable

Once this PR is merged, we need to document the new python validate_po.py --extract helper in our contributing guidelines, so if someone adds a new translation they will know to run the tool.

@archisman-panigrahi
Copy link
Collaborator

archisman-panigrahi commented Aug 4, 2024

so if someone adds a new translation they will know to run the tool

@deltragon You are referring to someone adding translation directly via git, bypassing weblate, right?

Also, do you know if the translation you fixed will be automatically sent to weblate? I don't want weblate to automatically overwrite the broken translation you had fixed

@archisman-panigrahi
Copy link
Collaborator

I tested that it works. I could not test whether the translations work properly without runtime errors (as my computer's language is English), but I trust your skills.

I approve merging.
Please let me know if this is ready for merging.

@archisman-panigrahi
Copy link
Collaborator

  • python validate.py --extract

You mean validate_po.py, right?

@deltragon
Copy link
Collaborator Author

You mean validate_po.py, right?

Thanks, corrected the typo.

@deltragon
Copy link
Collaborator Author

You are referring to someone adding translation directly via git, bypassing weblate, right?

No, I mean when someone adds a new translatable string in python or glade. In #569, this was done without adding the strings to the .pot/.po files - with this, they would know what to run to make sure the strings are translatable.

Also, do you know if the translation you fixed will be automatically sent to weblate? I don't want weblate to automatically overwrite the broken translation you had fixed

Yes, they will be - or rather, Weblate will complain about a conflict, if there is one, that can be resolved manually. I have access to pull the changes into Weblate and resolve the conflict if needed.

Please let me know if this is ready for merging.

Thanks! This is ready from my side.

@archisman-panigrahi archisman-panigrahi merged commit 670cfc4 into slgobinath:master Aug 4, 2024
1 check passed
@deltragon deltragon deleted the fix-persian-translations branch August 4, 2024 20:53
@archisman-panigrahi
Copy link
Collaborator

I guess now we need to push from GitHub to Weblate.

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.

CI failing due to invalid translations
2 participants