Add ObjCFormatCheck for Objective-C format strings#18590
Add ObjCFormatCheck for Objective-C format strings#18590anshkr95 wants to merge 21 commits intoWeblateOrg:mainfrom
Conversation
Adds support for Objective-C format string checks (%@ and %1$@). - Added OBJC_PRINTF_MATCH regex pattern - Added objc-format entry in FLAG_RULES - Added ObjCFormatCheck class extending BasePrintfCheck Closes WeblateOrg#18339
|
Thanks, there are still a few bits missing:
|
…checks/tests/test_format.py Add test cases for ObjCFormatCheck verifying %@ and %1$@ placeholders.
for more information, see https://pre-commit.ci
weblate/checks/models.py
Outdated
| "weblate.checks.format.PHPFormatCheck", | ||
| "weblate.checks.format.CFormatCheck", | ||
| "weblate.checks.format.PerlFormatCheck", | ||
| "weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck", |
|
There was a problem hiding this comment.
Pull request overview
Adds a new quality check to validate Objective-C/iOS-style printf placeholders (notably %@ and positional variants like %1$@) so that Weblate can detect placeholder mismatches between source and translation.
Changes:
- Introduces
OBJC_PRINTF_MATCHand registers a newobjc-formatrule inFLAG_RULES. - Adds
ObjCFormatCheck(aBasePrintfCheckspecialization) to expose the new behavior as a quality check. - Updates the checks registry (
CHECK_LIST) to include the new check (currently with a broken entry that needs fixing).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
weblate/checks/models.py |
Registers the new check in the global checks list (but the new entry is currently concatenated/invalid). |
weblate/checks/format.py |
Adds the Objective-C printf regex + flag rule and defines ObjCFormatCheck. |
weblate/checks/models.py
Outdated
| "weblate.checks.format.PHPFormatCheck", | ||
| "weblate.checks.format.CFormatCheck", | ||
| "weblate.checks.format.PerlFormatCheck", | ||
| "weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck", |
There was a problem hiding this comment.
The CHECK_LIST entry looks accidentally concatenated: "weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck" is not a valid import path and will prevent checks from loading. Split this into two separate strings (ObjCFormatCheck and PerlFormatCheck), preserving the existing list order.
| "weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck", | |
| "weblate.checks.format.ObjCFormatCheck", | |
| "weblate.checks.format.PerlFormatCheck", |
| class ObjCFormatCheck(BasePrintfCheck): | ||
| """Check for Objective-C format string.""" | ||
|
|
||
| check_id = "objc_format" | ||
| name = gettext_lazy("Objective-C format") | ||
| description = gettext_lazy("Objective-C format string does not match source.") |
There was a problem hiding this comment.
No tests are added for the new Objective-C placeholder behavior (e.g. %@ and %1$@) even though this module already has a dedicated format-check test suite. Please add unit tests covering matching, missing/extra placeholders, and positional reordering for objc-format.
| class ObjCFormatCheck(BasePrintfCheck): | ||
| """Check for Objective-C format string.""" | ||
|
|
||
| check_id = "objc_format" | ||
| name = gettext_lazy("Objective-C format") | ||
| description = gettext_lazy("Objective-C format string does not match source.") |
There was a problem hiding this comment.
As implemented, ObjCFormatCheck will only run when the objc-format flag is present on a unit. If the intent is to resolve #18339 for iOS .strings / .stringsdict by default, wire this flag into the relevant file format(s) via their check_flags so users don’t have to set it manually.
Added ObjCFormatTest class to test ObjC format strings.
for more information, see https://pre-commit.ci
Add Objective-C format check documentation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
for more information, see https://pre-commit.ci
|
Hi @nijel , I've resolved the merge conflicts in docs/changes.rst. The PR is now up to date and ready for the final checks. Thanks! |
docs/changes.rst
Outdated
| * Improved LLM interfaces for better reliability. | ||
| * Improved logic for adding monolingual plurals in :doc:`/formats/gettext`. | ||
| * Improved error messages in some of the :ref:`api` endpoints. | ||
| * Added check for Objective-C format strings. |
docs/user/checks.rst
Outdated
| .. check:: objc-format | ||
|
|
||
| Checks whether Objective-C format strings (like ``%@`` or ``%1$@``) | ||
| match between source and translation. |
There was a problem hiding this comment.
The section will appear in the generated file, just extend the documentation.
|
|
||
| check_id = "objc_format" | ||
| name = gettext_lazy("Objective-C format") | ||
| description = gettext_lazy("Objective-C format string does not match source.") |
fix: add version_added to ObjCFormatCheck
fix: use ref link for objc-format in changelog
Clarify Objective-C format string check description and add version info.
|
Hi @nijel , I sincerely apologize for the messy iterations and merge conflicts. I should have reviewed the structure and standards more carefully before submitting. I've now resolved all the issues: weblate/checks/format.py
docs/changes.rst
docs/user/checks.rst
The documentation now renders correctly and follows the proper structure (preview attached).
Thank you for your patience and guidance. Please let me know if further changes are needed. Thanks! |
|
@nijel Could you please review when you have time? Thanks! |
| `Objective-C String Format Specifiers <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html>`_ | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
This really should be in the generated file, but I've just realized that our documentation on this is outdated (see #18724). make -C docs update-docs should update it.
| self.check_fail("Hello %@", "Hello %s") | ||
| self.check_fail("Total: %d", "Total: %@") | ||
| self.check_fail("Missing %@", "Missing") | ||
| self.check_fail("Hello", "Hello %@") |
There was a problem hiding this comment.
This really should use existing attributes logic for the basic testing. Adding other tests is okay, but using existing fine-grained tests is better starting point.

Adds support for Objective-C format string checks (%@ and %1$@).
Closes #18339