SwiftUI's localized string do not load from main bundle despite using the main bundle identifier (an xcode bug?)

28 Views Asked by At

I have an iOS app that uses a Framework I've created. The framework contains several SwiftUI views that display text on the screen that needs to be translated to several languages.

I've added a Localizable.xcstrings file to the Framework, and loaded the translations with the following call:

String(localized: "Text I want to be translated", table: "Localizable", bundle: Bundle(identifier: "my.FrameworkBundleIdentifier")

where my.FrameworkBundleIdentifier is replaced with the appropriate identifier.

When I compile the framework, I see the strings added to the framework's Localizable.xcstrings file, and if I run the application all the strings get properly translated. So far so good.

The thing is that I would like to get rid of the framework's Localizable.xcstrings file and have just the Localizable.xcstrings file on the main bundle, so I've tried loading the localizable strings used on the frameowk from the Localizable.xcstrings on the main bundle. In theory, I should be able to do so by using the exact same call described above but using the main bundle identifier instead of the framework one, however, when doing so XCode keeps adding the strings to the framework's Localizable.xcstrings file at compile time, and at runtime the translation from the framework texsts do not work anymore.

Am I doing anything wrong? Is that an XCode bug?

I'm using Xcode 15.3 and targeting iOS 17.2.

Any help is appreciated! Cheers, Enric

0

There are 0 best solutions below