fix: skip native Swift conditional interpolations

This commit is contained in:
Shakker
2026-07-02 16:32:22 +01:00
parent 3020f7817e
commit e4194df270
7 changed files with 16 additions and 29 deletions
-8
View File
@@ -5577,14 +5577,6 @@
"surface": "apple",
"id": "native.apple.95300e4dfd7aad42"
},
{
"kind": "ui-call",
"line": 306,
"path": "apps/ios/Sources/Design/AgentProDreamingDestination.swift",
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
"surface": "apple",
"id": "native.apple.21d92f01c5cc2412"
},
{
"kind": "ui-named-argument",
"line": 343,
-5
View File
@@ -3488,11 +3488,6 @@
"source": "Dream diary day",
"translated": "Traumtagebuch-Tag"
},
{
"id": "native.apple.21d92f01c5cc2412",
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
},
{
"id": "native.apple.f0df95f0790fe675",
"source": "Connect a gateway to load dreaming entries.",
-5
View File
@@ -3488,11 +3488,6 @@
"source": "Dream diary day",
"translated": "Día del diario de sueños"
},
{
"id": "native.apple.21d92f01c5cc2412",
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
},
{
"id": "native.apple.f0df95f0790fe675",
"source": "Connect a gateway to load dreaming entries.",
-5
View File
@@ -3488,11 +3488,6 @@
"source": "Dream diary day",
"translated": "梦境日记日期"
},
{
"id": "native.apple.21d92f01c5cc2412",
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
},
{
"id": "native.apple.f0df95f0790fe675",
"source": "Connect a gateway to load dreaming entries.",
-5
View File
@@ -3488,11 +3488,6 @@
"source": "Dream diary day",
"translated": "Dream diary 日期"
},
{
"id": "native.apple.21d92f01c5cc2412",
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
},
{
"id": "native.apple.f0df95f0790fe675",
"source": "Connect a gateway to load dreaming entries.",
+15
View File
@@ -176,6 +176,9 @@ function isTranslatableCandidate(source: string, kind: string): boolean {
return false;
}
BUILD_SETTING_RE.lastIndex = 0;
if (hasQuotedConditionalSwiftInterpolation(source)) {
return false;
}
const isDirectUiText = kind.startsWith("ui-") || kind.startsWith("resource-");
if (!isDirectUiText && (/^[a-z0-9_.:/$-]+$/u.test(source) || /^[A-Z0-9_.:/$-]+$/u.test(source))) {
return false;
@@ -189,6 +192,18 @@ function isTranslatableCandidate(source: string, kind: string): boolean {
return kind !== "plist-string" || /\s/u.test(source);
}
function hasQuotedConditionalSwiftInterpolation(source: string): boolean {
return (
extractSwiftInterpolations(source)?.some(
(interpolation) =>
/\?\s*"((?:\\.|[^"\\])*)"\s*:\s*"((?:\\.|[^"\\])*)"/u.test(interpolation) ||
/\bif\b[\s\S]*"((?:\\.|[^"\\])*)"[\s\S]*\belse\b[\s\S]*"((?:\\.|[^"\\])*)"/u.test(
interpolation,
),
) ?? false
);
}
function extractSwiftInterpolations(source: string): string[] | null {
const values: string[] = [];
for (let index = 0; index < source.length; index += 1) {
+1 -1
View File
@@ -91,7 +91,7 @@ describe("native app i18n inventory", () => {
(entry) =>
entry.source === '\\(day.entryCount) \\(day.entryCount == 1 ? "entry" : "entries")',
),
).toBe(true);
).toBe(false);
expect(
entries.some(
(entry) =>