Skip to content

#886 Localisation foundation: string catalog, UiText, CI checks - #933

Closed
ivanfenenko wants to merge 4 commits into
mainfrom
feature/886-localisation-foundation
Closed

ivanfenenko wants to merge 4 commits into
mainfrom
feature/886-localisation-foundation

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stage 1 of 3 for #886 (Localisation): the foundation. Stage 2 (extract the remaining English text, one feature area at a time) and stage 3 (translation service) will stack on this.

  • iOS String Catalog. One Localizable.xcstrings in the app target (picked up by the file-system synchronized group; no project file change).
  • iOS design-system text is localisable. New OpenCodeText type (Components/OpenCodeText.swift) replaces String text parameters on the generic components: Button, ListItem (+ status, toggle label), TopBar (+ leading/actions), SectionHeader, EmptyState, InlineNotice, Dialog (+ options, text field), StatusStack, Tag, TextInput, ServerAddressInput, OverflowMenu entries, BottomSheet (title, entries, header actions), KeyValueRow label, FilterTabs, ChoiceBadge, OptionCard, SelectableCard, DropOverlay, ActionTile, ExpandPill, ActionBar action title/tag, StartDecorator labels.
    • A string literal is a localised key ("servers.title", or an English literal as today). OpenCodeText(LocalizedStringResource(key, defaultValue:)) carries placeholders and plurals.
    • .verbatim(_:) is the explicit path for server and session content (session titles, file and project names, model/provider/agent names, server errors, transcripts). It is never looked up as a key. Developer-only surfaces (gallery, playground, highlighting lab) use it too.
    • .unlocalized(_:) marks app text that is still built as a String in code. It renders exactly like today and the hardcoded-text check counts it, so stage 2 can find it.
    • A plain String no longer compiles at these parameters, so every caller made an explicit choice. Helpers are labelled (Text(openCode:), .accessibilityLabel(openCode:)) so Text("literal") stays unambiguous.
    • Content-specific components (session list rows, chat/markdown/diff/tool/activity cards, composer state, snackbar messages) keep String and still render verbatim. Stage 2 handles them.
  • Android UiText (ui/text/UiText.kt): Resource(id, args), Plural(id, count, args), Verbatim(value). Nested UiText args are resolved first. The @Composable resolve() uses LocalResources so locale changes recompose. Lookup sits behind a small UiTextLookup interface, so it is unit-tested without Robolectric. Design-system components keep String params.
  • Key convention: iOS area.name ⇔ Android area_name (every . becomes _). Only structured keys matching /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+$/ take part; English text keys that Xcode extracts are ignored.
  • Proof screen: Settings › Servers, both platforms. It uses structured keys (servers.*, common.remove, common.cancel), a plural (servers.profile_count) and positional placeholders (servers.remove_profile, servers.remove_dialog.title_named). Profile names and hosts stay verbatim. On Android, the Screen Model state exposes profileCountLabel / removeDialogTitle as UiText. The existing iOS bottom-sheet "Close" label now uses bottom_sheet.close, matching Android's existing bottom_sheet_close.
  • Scripts:
    • scripts/check-string-keys.mjs fails on keys present on one platform only. It also fails on plural/non-plural mismatches, placeholder-count mismatches, or iOS keys without an English value. The allowlist is ANDROID_ONLY = {app_name}.
    • scripts/check-hardcoded-text.mjs prints per-file and total counts of user-facing literals in feature UI code. It skips design-system internals, gallery, developer tools and previews. It is warning-only by default; --strict exits 1 and --list prints every location.
    • Both are available as npm run strings:check / strings:hardcoded.
  • CI: new String Checks workflow on GitHub-hosted Ubuntu (plain Node, no deps or secrets, like Secret Scan). Parity fails the job. Hardcoded text adds a warning annotation and a step summary. No existing node check was wired into CI to copy, so this is a small standalone workflow.
  • Android build: isPseudoLocalesEnabled = true on debug (en-XA / ar-XB), androidResources { generateLocaleConfig = true }, and res/resources.properties with unqualifiedResLocale=en-US.

Checks

  • Android ./gradlew :app:assembleDebug: pass (rerun after rebasing on current main).
  • Android unit tests: UiTextTest 8/8 and ServersUiStateTest 3/3 pass. Full testDebugUnitTest before the rebase: 3098 run, 3 failed, all unrelated to this change. Two are number-format assertions (2.5s vs 2,5s) that fail on a machine with a German number locale (SessionChatStepRailTest, SessionChatTimelineBlocksTest). One is the known-flaky SseRecoveryFaultOracleTest; a different case failed on each run.
  • Android ktlintCheck / lintDebug: still fail on existing debt (CI soft-fails them). Nothing reported in the files this PR adds or changes, except the existing ModifierParameter warning on the unchanged ServersScreen signature.
  • iOS build (Debug, iPhone 17 simulator): pass after the rebase.
  • iOS OpenCode MobileTests, full target before the rebase: 3031/3031 pass, including the new OpenCodeTextTests. These check catalog lookup, plural, placeholder, verbatim-never-looked-up and fallback.
    • After the rebase, the full run had 10 "crashed with signal kill" restarts while machine load was around 150.
    • Rerunning those suites serially: everything passed except 3 SseRecoveryFaultOracleTests timing cases.
    • That suite then passed 23/23 on its own rerun.
  • node scripts/check-string-keys.mjs: pass (11 shared keys; 12 Android names, 11 iOS structured keys, app_name allowlisted).
  • node scripts/check-hardcoded-text.mjs: 1053 findings (warning only).
    • Android: 409 literals in 46 files.
    • iOS: 644 in 55 files (534 literals, 110 .unlocalized).
  • Pseudo-locale verification (follow-up commits 6a282eb9, e96873b0):
    • Found and fixed on both platforms: "Active" badge and top bar "Back" label were not keyed (now servers.status_active / top_bar.back), and the Back arrow did not flip in right-to-left.
    • Android: the lone top bar subtitle no longer uses the 220dp cap (it clipped the profile count under en-XA); the cap stays when a status follows, as in Session Chat.
    • Servers screen, remove dialog, plural and placeholders pass on both platforms; Android per-app language setting lists the app; iOS server content (profile names) is never looked up or transformed.
    • After the fixes: UiTextTest, ServersUiStateTest, ConnectionProfileListMetaTest, OpenCodeTextTests and related iOS suites pass; key parity passes with 13 shared keys.
  • English text is unchanged apart from the Servers top bar subtitle on Android, which now uses the full width. Literals now go through the catalog, which falls back to the same English text, and content stays verbatim.

Evidence

Screenshots in the evidence comments, both against scenario-harness fixture data:

Issue

#886. This is stage 1 of 3; stage 2 (extraction) and stage 3 (translation service) will follow as stacked pull requests.

Risks / Follow-ups

  • Stage 2:
    • Extract the remaining text and migrate the content-specific iOS components and snackbar messages.
    • Replace .unlocalized with catalog keys.
    • Turn on --strict once the count reaches zero.
  • When the project is next built in the Xcode IDE, Xcode will add English-text keys it extracts from Text("…") literals to Localizable.xcstrings. The parity check ignores them, but expect catalog churn in the first stage-2 commits.
  • Not verified:
    • Android Compose screenshot tests and the iOS static analyzer (xcodebuild analyze).
    • The Servers screen against a real (non-harness) server.
    • The "0 profiles" and iOS plural "other" states on screen (covered by unit tests).
  • iOS double-length mode shows the plural format string raw (#@value@ %#@value@); this is how Apple's pseudo-language doubles format strings, not a catalog bug. English resolves normally.
  • Stage 2 also covers: back arrows outside the top bar (sheets, Session Chat) that should mirror in right-to-left, and the Home servers sheet headers.
  • No pixel snapshot tests ran on iOS: the unit target has no committed reference images, only the on-demand evidence renderer.
  • gitleaks was not installed locally; the Secret Scan workflow covers it.
  • The hardcoded-text check is line-based. It can miss text built in helpers, and it counts some developer-tools text in feature folders (for example Settings › Developer Tools rows).

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@ivanfenenko
ivanfenenko marked this pull request as ready for review November 1, 2026 22:40

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review: no finding that 2+ of 3 passes agreed on.

4 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/Components/List/OpenCodeSectionHeader.swift:69 medium: Section header label bypasses live localization (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Components/Input/OpenCodeTextInput.swift:147 medium: Text-field hint resolved to String loses locale tracking (muse-spark-1.3-contributor)
  • scripts/check-hardcoded-text.mjs:135 low: Text empty-state titles that are now localized keys rely on the fallback mechanism at runtime (glm-5.3-flash)
  • scripts/check-hardcoded-text.mjs:94 low: Preview tracking never exits for single-line or indented-closing previews, silently skipping the rest of the file (deepseek-v4.1-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.107

@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Android · harness fixture data · pseudo-locales en-XA / ar-XB

Debug build on an API 36 emulator against the scenario harness (fixture profiles only). The per-app locale was set with cmd locale set-app-locales. Fixes found during this check are in 6a282eb: the top-bar Back arrow now mirrors in RTL, the "Active" badge and the Back label are keyed, and the 220dp subtitle cap only applies when a status follows the subtitle. Before the fix, the en-XA profile count was cut off.

Step Screenshot
English, 1 profile (plural one) English, one profile
English, 2 profiles (plural other) English, two profiles
English remove dialog (%1$s name) English remove dialog
en-XA Servers en-XA Servers
en-XA remove dialog en-XA remove dialog
ar-XB Servers (RTL, Back mirrored) ar-XB Servers
ar-XB remove dialog ar-XB remove dialog
System › App language (generateLocaleConfig) System app language
System › App info › Language row System app info

@ivanfenenko

ivanfenenko commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

iOS · harness fixture data · pseudo-languages double-length / RTL / missing-string

iPhone 17 simulator, Debug build at e96873b, connected to the scenario harness. Launch args: double-length -NSDoubleLocalizedStrings YES; RTL -AppleTextDirection YES -NSForceRightToLeftWritingDirection YES; missing-string -NSShowNonLocalizedStrings YES (uppercases text missing from the catalog).

Settings › Servers Remove dialog (placeholder)
English Servers, English Remove dialog, English
Double-length Servers, double-length Remove dialog, double-length
Right-to-left Servers, RTL Remove dialog, RTL
Missing-string Servers, missing-string Remove dialog, missing-string
Home, double-length Home, missing-string
Home, double-length Home, missing-string
  • Servers: every string resolves from the catalog (nothing uppercased in missing-string mode). The profile name and host stay verbatim in every mode, and no text clips at double length.
  • Fixed in e96873b: the "Active" badge and the top bar's Back label were English literals missing from the catalog (they showed as ACTIVE / BACK). They now use servers.status_active / top_bar.back. The Back arrow now points right in RTL. The double-length shots were taken before the fix, so the arrow and keys there are pre-fix; the text is the same.
  • Plural: 1 Connection Profile (one) is shown. Double-length mode renders the plural as #@value@ %#@value@, and numeric formats like Home's count badge as lld 0. That is Apple's pseudo-language doubling the raw format string; the compiled .stringsdict is standard Xcode output and resolves normally. The "other" plural form was not reached (the harness seeds one profile).
  • Home: the server name "Fixture server" is verbatim and never uppercased or doubled. New session is an English literal not yet in the catalog, and live, All projects and 2 projects come from content components that still take String. All of this is stage 2.

# Conflicts:
#	ios/OpenCode Mobile/OpenCode Mobile/UI/Playground/SessionChatPlaygroundView.swift
#	ios/OpenCode Mobile/OpenCode Mobile/UI/SessionChat/SessionChatView.swift
… bar subtitle

- Servers' Active badge and the top bar Back label come from strings.xml
  (servers_status_active, top_bar_back) with matching catalog keys.
- The top bar Back arrow flips in right-to-left layouts.
- The 220dp subtitle cap only applies when a status follows it, so a plain
  subtitle such as the profile count uses the full width, as on iOS.
- The Servers "Active" badge and the top bar's default Back label use the
  servers.status_active and top_bar.back catalog keys instead of English
  literals, so the Servers screen has no text missing from the catalog.
- The top bar Back arrow flips in right-to-left layouts.
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Superseded by #975, which combines the whole #886 localisation stack into one pull request against main. Review and merge happen there.

@ivanfenenko ivanfenenko closed this Nov 3, 2026
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.

1 participant