'Is it possible to use bundle from a different package when calling localizedUserNotificationString

My app had its localization resources (*.lproj files) in the Main bundle. So I was able to use localizedUserNotificationString as expected.

I have since modularized the app and the resources have now moved to a new SPM package for shared resources. After this change localizedUserNotificationString has stopped formatting strings from arguments.

I had to replace

NSString.localizedUserNotificationString(forKey: title, arguments: args)

with

String(format: String.localizationHelper(title), arguments: titleArgs ?? [])

Where the localizationHelper is defined in the resources package to use the correct bundle.

func localizationHelper(key: String) {
    return NSLocalizedString(key, tableName: nil, bundle: .module, value: "", comment: "")
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source