Localization: exclude SwiftUI preview strings from translation + CI lint (narrowed scope)#25701
Draft
jkmassel wants to merge 3 commits into
Draft
Localization: exclude SwiftUI preview strings from translation + CI lint (narrowed scope)#25701jkmassel wants to merge 3 commits into
jkmassel wants to merge 3 commits into
Conversation
Collaborator
Generated by 🚫 Danger |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32844 | |
| Version | PR #25701 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | c4c5e74 | |
| Installation URL | 21u9ec4sf0g5g |
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32844 | |
| Version | PR #25701 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | c4c5e74 | |
| Installation URL | 54o9lia2pftcg |
Text literals to Text(verbatim:)Text literals to verbatim (+ CI lint for previews)
`xcstringstool extract --SwiftUI-Text` extracts every `Text("literal")` —
including the placeholder/sample strings inside `#Preview` and
`PreviewProvider` blocks, which never ship to users. Wrap those 23 literals in
`Text(verbatim:)` so they're excluded from translation.
Scoped to preview strings; the broader non-translatable cleanup (glyphs, brand
names, developer/debug screens, the unwired Realtime feature) is deferred to a
separate PR.
Text literals to verbatim (+ CI lint for previews)Text(verbatim:) for SwiftUI preview strings + CI lint
…view`
Adds a `lint_swiftui_preview_strings` fastlane lane and a "Lint SwiftUI
Preview Strings" Buildkite step so preview strings can't regress: a `#Preview`
shipping a translatable `Text("literal")` now fails CI with the exact file:line
and the fix (wrap in `Text(verbatim:)`).
Reuses Apple's extractor as its own oracle — `xcstringstool extract
--SwiftUI-Text` tags every extracted string's `visibility`, and #Preview /
PreviewProvider literals come out as `visibility: "preview"`. No source parsing
or brace-tracking, and tautologically consistent with what extraction pulls.
Self-contained (no dependency on the #25688 catalog lane). Green on the current
tree; verified it fails on an injected preview literal.
Documents the `verbatim:` rule and the gate in docs/localization.md.
Text(verbatim:) for SwiftUI preview strings + CI lintAdversarial testing surfaced that a `#Preview` wrapped in `#if DEBUG` gets a
compound `visibility` — {"type":"conjunction","values":[{"type":"defined",
"value":"DEBUG"},"preview"]} — that the exact `== "preview"` check missed, so a
conditionally-compiled preview literal slipped through. Recurse the visibility
values (new `preview_visibility?`) so `#if`-gated previews are caught; a bare
`#if FLAG` with no preview leaf stays correctly unflagged (no new false
positives — verified green on the full tree).
Also documents the remaining by-design gaps the testing confirmed: preview-only
strings hoisted into free helper views/funcs are indistinguishable from shipping
code, and modern `String(localized:)` / `LocalizedStringResource` APIs aren't on
the `--SwiftUI-Text` surface (both latent — the cleanup is `Text("…")`-only).
|
|
||
| # Run `xcstringstool extract --SwiftUI-Text` over the files and return a sorted "file:line \"key\"" entry | ||
| # for every extracted string tagged `visibility: preview` (i.e. originating from #Preview / PreviewProvider). | ||
| def preview_localizable_text_literals(files) |
Collaborator
There was a problem hiding this comment.
| 🚫 | Metrics/AbcSize: Assignment Branch Condition size for preview_localizable_text_literals is too high. [<13, 28, 7> 31.65/17] |
|
|
||
| # Run `xcstringstool extract --SwiftUI-Text` over the files and return a sorted "file:line \"key\"" entry | ||
| # for every extracted string tagged `visibility: preview` (i.e. originating from #Preview / PreviewProvider). | ||
| def preview_localizable_text_literals(files) |
Collaborator
There was a problem hiding this comment.
| 🚫 | Metrics/CyclomaticComplexity: Cyclomatic complexity for preview_localizable_text_literals is too high. [8/7] |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Description
Narrowed focus: this PR does two tightly-related things — exclude SwiftUI preview strings from translation, and add a CI lint so they can't regress. The broader non-translatable cleanup from the original audit (glyphs, brand names, debug screens, the unwired Realtime feature) has been rolled back to a separate PR; see Deferred below.
xcstringstool extract --SwiftUI-Text(the extractor #25688's catalog lane will enable) pulls in everyText("literal"), including the placeholder/sample strings in preview blocks, which never ship to users. This PR:Modules/) inText(verbatim:)so they're excluded.Text("…")ever lands in a#Previewagain.No behavior change —
verbatim:renders these strings identically.The lint:
lint_swiftui_preview_stringsNew fastlane lane + Buildkite step (Lint SwiftUI Preview Strings, in the Linters group):
xcstringstooltags every extracted string'svisibility, and#Preview/PreviewProviderliterals come out as"visibility": "preview". No source parsing or brace-tracking, tautologically consistent with what extraction pulls, and zero false positives (preview code never ships, so a localizable literal there is always wrong).file:line+ the fix.trunktoday.Proof — the lint catches a real regression in CI
Verified on CI, not just locally. Temporarily re-introducing one preview literal and pushing it tripped the step: failing build #32839 → Lint SwiftUI Preview Strings (red in ~1 min), with the actionable output:
That demonstration commit has since been reverted, so this branch is green. (It also caught a real wiring bug: the first attempt, #32838, died in the Fastfile
before_allhook because the lint script wasn't seedingproject.env— fixed by copyingproject.env-example, same as the sibling localization lint.)Documented in
docs/localization.md.Deferred to a follow-up
The broader non-translatable cleanup the original audit covered — glyphs/dividers (
Text("·")), brand names (Text("WordPress.com")), pure interpolations (Text("@\(username)")), developer/debug-menu screens, and the unwired Realtime stats feature (~60 literals) — is not in this PR. Those are judgment calls the lint can't decide (is this glyph translatable? should this debug screen localize?), so they belong in a separate, reviewable change. Flippingswiftui: trueongenerate_strings_cataloglikewise lives in #25688's branch. Both follow once this and #25688 land.Testing instructions
No user-facing change —
Text(verbatim:)renders byte-identical for these preview placeholders.swiftc -parseclean across the changed Swift files.file:line) on an injected previewText("…").Related: #25700, #25688