Skip to content

Add ObjCFormatCheck for Objective-C format strings#18590

Open
anshkr95 wants to merge 21 commits intoWeblateOrg:mainfrom
anshkr95:main
Open

Add ObjCFormatCheck for Objective-C format strings#18590
anshkr95 wants to merge 21 commits intoWeblateOrg:mainfrom
anshkr95:main

Conversation

@anshkr95
Copy link
Copy Markdown

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 #18339

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
@anshkr95 anshkr95 requested a review from nijel as a code owner March 23, 2026 14:28
@nijel
Copy link
Copy Markdown
Member

nijel commented Mar 23, 2026

Thanks, there are still a few bits missing:

  • The check needs to be registered in CHECK_LIST.
  • The documentation and changelog entry are missing.
  • The check should come with a test case verifying that it actually works as desired.

"weblate.checks.format.PHPFormatCheck",
"weblate.checks.format.CFormatCheck",
"weblate.checks.format.PerlFormatCheck",
"weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The patch is messed up here.

@nijel nijel added this to the 5.17 milestone Mar 23, 2026
@nijel nijel requested a review from Copilot March 23, 2026 16:30
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_MATCH and registers a new objc-format rule in FLAG_RULES.
  • Adds ObjCFormatCheck (a BasePrintfCheck specialization) 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.format.PHPFormatCheck",
"weblate.checks.format.CFormatCheck",
"weblate.checks.format.PerlFormatCheck",
"weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck",
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
"weblate.checks.format.ObjCFormatCheckweblate.checks.format.PerlFormatCheck",
"weblate.checks.format.ObjCFormatCheck",
"weblate.checks.format.PerlFormatCheck",

Copilot uses AI. Check for mistakes.
Comment on lines +630 to +635
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.")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +630 to +635
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.")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@anshkr95 anshkr95 requested a review from AliceVisek as a code owner March 23, 2026 16:51
@anshkr95
Copy link
Copy Markdown
Author

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should use link to the check.

.. check:: objc-format

Checks whether Objective-C format strings (like ``%@`` or ``%1$@``)
match between source and translation.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

version_added is missing here.

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.
@anshkr95
Copy link
Copy Markdown
Author

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

  • Added version_added = "5.17" to ObjCFormatCheck class

docs/changes.rst

  • Updated changelog with proper ref link: :ref:check-objc-format``
  • Resolved merge conflicts

docs/user/checks.rst

  • Extended documentation with detailed examples
  • Added Apple's official reference link
  • Positioned correctly before auto-generated checks

The documentation now renders correctly and follows the proper structure (preview attached).

image

Thank you for your patience and guidance. Please let me know if further changes are needed.

Thanks!

@anshkr95
Copy link
Copy Markdown
Author

@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>`_



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 %@")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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.

Support Apple/iOS-specific (ObjectiveC and Swift) placeholders format checks

3 participants