Repository navigation
Add String(localized:) and String.LocalizationValue for Android - #38
Merged
Merged
Conversation
Implements the missing Foundation String(localized:table:bundle:locale:comment:), String(localized:defaultValue:...) and String(localized: LocalizedStringResource) on Android on top of AndroidStringInterpolation and AndroidLocalizedString, so native modules no longer need a per-module NSLocalizedString shim (skiptools/skip#538). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ple table The linux-gnu host pass of skip export compiles native modules against Foundation that also lacks String(localized:), so provide it on every non-Darwin platform, backed by Foundation.Bundle outside Android. The sample strings move from .xcstrings to en.lproj/Localizable.strings because the swift.org toolchain with Xcode 16.4 copies .xcstrings without compiling it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marcprux
approved these changes
Oct 5, 2026
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.
Fixes skiptools/skip#538.
Native modules on Android have no
String(localized:): swift-foundation on non-Darwin platforms doesn't shipString.LocalizationValueor theString(localized:)initializers. Today every module that wants them adds its ownNSLocalizedStringshim, and it has to be per-module because it calls the module-internallet NSLocalizedString = AndroidLocalizedString()generated inBundle_Support.swift. String interpolation insideString(localized:)also can't work through such a shim: the shim receives the already-interpolated string as the lookup key.This adds the missing API to
SkipAndroidBridge, built on the existingAndroidStringInterpolationandAndroidLocalizedString:String.LocalizationValue(AndroidLocalizationValue)String(localized:table:bundle:locale:comment:)String(localized:defaultValue:table:bundle:locale:comment:)String(localized: LocalizedStringResource)Notes:
bundle:is typedAndroidBundle?, sobundle: .moduleresolves the module's synthesizedBundle.module(declared onAndroidBundlevia the generatedBundletypealias).%as%%only when the string is interpolated ("100% done"→"100% done","\(n)% done"→"%lld%% done"). Verified against Darwin Foundation.AndroidBundle. On other hosts, such as the linux-gnu host pass ofskip export, it usesFoundation.Bundle. Darwin, including a Robolectric host on macOS, keeps Foundation's implementation..xcstringsare not handled, matching the transpiledString(localized:)in skip-foundation.Testing
testStringLocalizedsample test with anen.lproj/Localizable.strings(a.xcstringsis copied uncompiled by the swift.org toolchain with Xcode 16.4): literal keys, keys containing%, interpolation with positional arguments, untranslated fallback,defaultValue:, dynamic keys. It passes on macOS, where Foundation's implementation produces the same expected values. It is skipped on Robolectric on a macOS host, which runs Foundation's implementation and doesn't read theAndroidBundlestrings.swift test(macOS + Robolectric) green;skip android buildgreen.🤖 Generated with Claude Code