Set default localization bundle for SwiftUI etc

When using a localized SPM package, one needs to specify the bundle in order to use the correct resources at run time like this:

.., bundle: .module).

Without specifying the bundle, the code defaults to the main bundle (.., bundle: .main).

This makes sense when only few resources are in a specific bundle.

For cases that a package provides fully localized UI, it would be nice to define a default bundle.
Or at least make it check the .module bundle by default.

Is there any way to make that work? Or anything planned like that?

I can't speak to the future of SwiftUI APIs specifically since SwiftUI is a closed source framework developed by Apple that isn't governed by the Swift open source project.

That being said, on the open source side, you may be interested in this Foundation proposal: swift-foundation/Proposals/0024-CurrentBundle.md at main · swiftlang/swift-foundation · GitHub. In Swift 6.2 this added a #bundle macro which represents the "current" bundle (.module in packages, .main in an app, etc.) and discusses how it's the first step towards improving some of the problems you're likely finding with defaulting to the .main bundle. Perhaps using #bundle might help a little bit in your situation.

1 Like

Oh, that is it! Now I remember seeing this before. Thanks!

1 Like