Problem with localising a Swift package

I am using Xcode 15 and working on a localised app. I use the new String Catalogs feature which works great for my app. In my app I created some local package like Apple has done it in the Backyard Birds example. However the translations I did in the package's String Catalog won’t be used in the app. What am I doing wrong?

Answered by RayWo in 763017022

When you use resources from a localised framework, make sure to use methods with the bundle: parameter! Even in the framework itself.

Instead of using String(localized: "some String") use String(localized: "some String", bundle: Bundle.module). Same goes for Color, NSDataAsset and so on. This fixed my issue.

Hi, would you have example code? For instance, are you passing the package as a bundle parameter?

To be honest, I don’t know what you mean by that.

I have the exact same problem ☹️ The app translates as expected for 90%, but one view (that is implemented through a local package) does not.

In the local package manifest: _// swift-tools-version:5.9 _ and defaultLocalization: "en" were added

Under myPackage/Sources/myTarget/Resources: A string catalog with the default name 'Localizable' was added

When I compile the package's String catalog gets filled with all the new Text() items from the view and I can provide translation for them.

Accepted Answer

When you use resources from a localised framework, make sure to use methods with the bundle: parameter! Even in the framework itself.

Instead of using String(localized: "some String") use String(localized: "some String", bundle: Bundle.module). Same goes for Color, NSDataAsset and so on. This fixed my issue.

Problem with localising a Swift package
 
 
Q