Skip to content

Commit e4194df

Browse files
committed
fix: skip native Swift conditional interpolations
1 parent 3020f78 commit e4194df

7 files changed

Lines changed: 16 additions & 29 deletions

File tree

apps/.i18n/native-source.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5577,14 +5577,6 @@
55775577
"surface": "apple",
55785578
"id": "native.apple.95300e4dfd7aad42"
55795579
},
5580-
{
5581-
"kind": "ui-call",
5582-
"line": 306,
5583-
"path": "apps/ios/Sources/Design/AgentProDreamingDestination.swift",
5584-
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
5585-
"surface": "apple",
5586-
"id": "native.apple.21d92f01c5cc2412"
5587-
},
55885580
{
55895581
"kind": "ui-named-argument",
55905582
"line": 343,

apps/.i18n/native/de.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,11 +3488,6 @@
34883488
"source": "Dream diary day",
34893489
"translated": "Traumtagebuch-Tag"
34903490
},
3491-
{
3492-
"id": "native.apple.21d92f01c5cc2412",
3493-
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
3494-
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
3495-
},
34963491
{
34973492
"id": "native.apple.f0df95f0790fe675",
34983493
"source": "Connect a gateway to load dreaming entries.",

apps/.i18n/native/es.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,11 +3488,6 @@
34883488
"source": "Dream diary day",
34893489
"translated": "Día del diario de sueños"
34903490
},
3491-
{
3492-
"id": "native.apple.21d92f01c5cc2412",
3493-
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
3494-
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
3495-
},
34963491
{
34973492
"id": "native.apple.f0df95f0790fe675",
34983493
"source": "Connect a gateway to load dreaming entries.",

apps/.i18n/native/zh-CN.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,11 +3488,6 @@
34883488
"source": "Dream diary day",
34893489
"translated": "梦境日记日期"
34903490
},
3491-
{
3492-
"id": "native.apple.21d92f01c5cc2412",
3493-
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
3494-
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
3495-
},
34963491
{
34973492
"id": "native.apple.f0df95f0790fe675",
34983493
"source": "Connect a gateway to load dreaming entries.",

apps/.i18n/native/zh-TW.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,11 +3488,6 @@
34883488
"source": "Dream diary day",
34893489
"translated": "Dream diary 日期"
34903490
},
3491-
{
3492-
"id": "native.apple.21d92f01c5cc2412",
3493-
"source": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")",
3494-
"translated": "\\(day.entryCount) \\(day.entryCount == 1 ? \"entry\" : \"entries\")"
3495-
},
34963491
{
34973492
"id": "native.apple.f0df95f0790fe675",
34983493
"source": "Connect a gateway to load dreaming entries.",

scripts/native-app-i18n.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ function isTranslatableCandidate(source: string, kind: string): boolean {
176176
return false;
177177
}
178178
BUILD_SETTING_RE.lastIndex = 0;
179+
if (hasQuotedConditionalSwiftInterpolation(source)) {
180+
return false;
181+
}
179182
const isDirectUiText = kind.startsWith("ui-") || kind.startsWith("resource-");
180183
if (!isDirectUiText && (/^[a-z0-9_.:/$-]+$/u.test(source) || /^[A-Z0-9_.:/$-]+$/u.test(source))) {
181184
return false;
@@ -189,6 +192,18 @@ function isTranslatableCandidate(source: string, kind: string): boolean {
189192
return kind !== "plist-string" || /\s/u.test(source);
190193
}
191194

195+
function hasQuotedConditionalSwiftInterpolation(source: string): boolean {
196+
return (
197+
extractSwiftInterpolations(source)?.some(
198+
(interpolation) =>
199+
/\?\s*"((?:\\.|[^"\\])*)"\s*:\s*"((?:\\.|[^"\\])*)"/u.test(interpolation) ||
200+
/\bif\b[\s\S]*"((?:\\.|[^"\\])*)"[\s\S]*\belse\b[\s\S]*"((?:\\.|[^"\\])*)"/u.test(
201+
interpolation,
202+
),
203+
) ?? false
204+
);
205+
}
206+
192207
function extractSwiftInterpolations(source: string): string[] | null {
193208
const values: string[] = [];
194209
for (let index = 0; index < source.length; index += 1) {

test/scripts/native-app-i18n.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe("native app i18n inventory", () => {
9191
(entry) =>
9292
entry.source === '\\(day.entryCount) \\(day.entryCount == 1 ? "entry" : "entries")',
9393
),
94-
).toBe(true);
94+
).toBe(false);
9595
expect(
9696
entries.some(
9797
(entry) =>

0 commit comments

Comments
 (0)