LOCALIZED_STRING_MACRO_NAMES for Swift package targets?

I have a custom localisation function in my project that enforces the inclusion of the bundle parameter (specifically so that Swift packages are forced to include the Bundle.module value).

While migrating to String Catalogs, I noticed that my custom localisation function wasn't being recognised by the automatic extraction that the Swift compiler is doing, but only in my Swift package targets.

Is there a way to set something like LOCALIZED_STRING_MACRO_NAMES in Swift Packages?

Answered by Developer Tools Engineer in 794176022

There is not a way to set build settings like this in Swift Packages.

One alternative would be to define something like this:

func myPackageLocalizedString(_ key: String.LocalizationValue) -> String {
    return String(localized: key, bundle: Bundle.module)
}

Strings using this method would be extracted without needing to define any custom macro names. However when doing that you lose the ability to customize the localization comment or table name from callers of your function. (Though comments can still be added directly from the String Catalog Editor.)

We would welcome enhancement requests in both of these areas.

Accepted Answer

There is not a way to set build settings like this in Swift Packages.

One alternative would be to define something like this:

func myPackageLocalizedString(_ key: String.LocalizationValue) -> String {
    return String(localized: key, bundle: Bundle.module)
}

Strings using this method would be extracted without needing to define any custom macro names. However when doing that you lose the ability to customize the localization comment or table name from callers of your function. (Though comments can still be added directly from the String Catalog Editor.)

We would welcome enhancement requests in both of these areas.

LOCALIZED_STRING_MACRO_NAMES for Swift package targets?
 
 
Q