Localizable Strings from a framework not shown in Widget

I have a in-house framework that I share between the main app and the widget.

The framework contains some localized strings.

These strings show up in correct language in the main app but on the widget they only show up in English.

I'm guessing the localized strings from the framework are not getting bundled in the widget extension.

Anybody with the same problem?

Accepted Reply

Answering my own question hoping it will help somebody else in the future:

Make sure you specify the bundle argument in NSLocalizedString. Otherwise it will default to Bundle.main. You need to use the bundle of your shared framework for the correct strings to be used.

Replies

Answering my own question hoping it will help somebody else in the future:

Make sure you specify the bundle argument in NSLocalizedString. Otherwise it will default to Bundle.main. You need to use the bundle of your shared framework for the correct strings to be used.
The best-practice we recommend here is:
  1. Have your framework export a new macro / function ex: FWLocalizedString that calls NSLocalizedStringFromTableInBundle (Objective-C) or the sets the bundle argument in NSLocalizedString (Swift) to your framework bundle

  2. Use FWLocalizedString for all localized strings within your framework

  3. In your framework target, add FWLocalizedString to the "Localized String Macro Names" build setting

Now, when you export for localization all FWLocalizedString calls will be extracted in the framework target—but not from the application or widget target.

  • Is there documentation on this somewhere? I don't see any reference to it in developer.apple.com.

Add a Comment