Composed string resources detected by Strings Catalog

I am using a string resource in the following way:

let content = UNMutableNotificationContent()
content.body = NSLocalizedString("notification_body_" + String(notificationBodyId), comment: "")

And will have a number of strings defined in the strings catalog notification_body_1, notification_body_2 etc.

This works fine, but the feature of strings catalogue that is automatically grepping source code for usage of strings is inserting an entry reality_check_notification_body_ that will obviously never be used & never be translated (thus showing my translated percentage at less than 100%).

Xcode doesn't appear to provide a way for me to delete / ignore these automatically created string resources (delete button is disabled where available for manually created string resources).

Is there some other way in code I should have referenced this resource, or some workaround to remove the string from strings catalog (no doubt if I manually remove from the backing file, it will simply be re-created).

Thanks.

Xcode 15.3

Accepted Reply

Please feel free to file a feedback for any undesired behavior in Xcode.

In your specific context, you'll need to create your string key outside of NSLocalizedString() so that it doesn't get extracted in the String Catalog by Xcode:

let content = UNMutableNotificationContent()
let notificationStringKey = "notification_body_\(notificationBodyId)"
content.body = NSLocalizedString(notificationStringKey, comment: "")

Replies

Please feel free to file a feedback for any undesired behavior in Xcode.

In your specific context, you'll need to create your string key outside of NSLocalizedString() so that it doesn't get extracted in the String Catalog by Xcode:

let content = UNMutableNotificationContent()
let notificationStringKey = "notification_body_\(notificationBodyId)"
content.body = NSLocalizedString(notificationStringKey, comment: "")