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

Viewed 41

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: "")
}

0 Answers
Related