Skip to content

Commit 5e4d716

Browse files
committed
fix(apple): preserve localized static labels
1 parent d3e6d1f commit 5e4d716

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

apps/ios/Sources/Gateway/GatewayQuickSetupSheet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct GatewayQuickSetupSheet: View {
121121
self.gatewayController.gateways.first
122122
}
123123

124-
private func fullRowToggle(_ title: String, isOn: Binding<Bool>) -> some View {
124+
private func fullRowToggle(_ title: LocalizedStringKey, isOn: Binding<Bool>) -> some View {
125125
Toggle(title, isOn: isOn)
126126
.contentShape(Rectangle())
127127
.overlay {

apps/ios/WatchApp/Sources/WatchInboxView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ private struct WatchCompactMetric: View {
760760
}
761761

762762
private struct WatchPrimaryLabel: View {
763-
let title: String
763+
let title: LocalizedStringKey
764764

765765
var body: some View {
766766
HStack(spacing: 7) {
@@ -809,7 +809,7 @@ private struct WatchPageRail: View {
809809
}
810810

811811
private struct WatchSecondaryLabel: View {
812-
let title: String
812+
let title: LocalizedStringKey
813813

814814
var body: some View {
815815
Text(self.title)
@@ -829,7 +829,7 @@ private struct WatchSecondaryLabel: View {
829829
}
830830

831831
private struct WatchSecondaryButton: View {
832-
let title: String
832+
let title: LocalizedStringKey
833833
let action: () -> Void
834834

835835
var body: some View {
@@ -911,7 +911,7 @@ private struct WatchActionCard: View {
911911
}
912912

913913
private struct WatchDecisionButton: View {
914-
let title: String
914+
let title: LocalizedStringKey
915915
let color: Color
916916
let action: () -> Void
917917

scripts/apple-app-i18n.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mkdir, readFile, writeFile } from "node:fs/promises";
22
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
3+
import { fileURLToPath, pathToFileURL } from "node:url";
44
import { NATIVE_I18N_LOCALES } from "./native-app-i18n.ts";
55

66
const HERE = path.dirname(fileURLToPath(import.meta.url));
@@ -12,6 +12,17 @@ const APPLE_LOCALE_DIRECTORIES: Record<string, string> = {
1212
"zh-CN": "zh-Hans",
1313
"zh-TW": "zh-Hant",
1414
};
15+
const LOCALIZED_WRAPPER_CONTRACTS: Record<string, string[]> = {
16+
"apps/ios/Sources/Gateway/GatewayQuickSetupSheet.swift": [
17+
"fullRowToggle(_ title: LocalizedStringKey",
18+
],
19+
"apps/ios/WatchApp/Sources/WatchInboxView.swift": [
20+
"private struct WatchPrimaryLabel: View {\n let title: LocalizedStringKey",
21+
"private struct WatchSecondaryLabel: View {\n let title: LocalizedStringKey",
22+
"private struct WatchSecondaryButton: View {\n let title: LocalizedStringKey",
23+
"private struct WatchDecisionButton: View {\n let title: LocalizedStringKey",
24+
],
25+
};
1526

1627
const CATALOGS = [
1728
{
@@ -100,6 +111,15 @@ function stringsLiteral(value: string): string {
100111

101112
export async function checkAppleAppI18n() {
102113
let checked = 0;
114+
for (const [sourcePath, contracts] of Object.entries(LOCALIZED_WRAPPER_CONTRACTS)) {
115+
const source = await readFile(path.join(ROOT, sourcePath), "utf8");
116+
const missing = contracts.filter((contract) => !source.includes(contract));
117+
if (missing.length) {
118+
throw new Error(
119+
`Apple i18n wrapper ${sourcePath} bypasses localized string lookup: ${missing.join(", ")}`,
120+
);
121+
}
122+
}
103123
for (const spec of CATALOGS) {
104124
const catalogPath = path.join(ROOT, spec.path);
105125
const catalog = JSON.parse(await readFile(catalogPath, "utf8")) as Catalog;
@@ -185,7 +205,7 @@ export async function compileMacosLocalizations(outputDir: string) {
185205
}
186206
}
187207

188-
if (process.argv[1] && import.meta.url === `file://${path.resolve(process.argv[1])}`) {
208+
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
189209
const [command, flag, value] = process.argv.slice(2);
190210
if (command === "check") {
191211
await checkAppleAppI18n();

0 commit comments

Comments
 (0)