Reusing string catalog translations in swift packages

Setup

I have 2 swift packages and I try to use stirng catalog to manage your localizations

I would like to use some specific keys in these packages and some common ones (e.g. "ok_button_tittle")

Problem statement

I really don't like the idea of creating separate (but the same) translations in these packages

I have tried using something like

String(
            localized: "ok_button_title",
            table: "Localizable",
            bundle: .main,
            comment: "Ok button title"
)

This does use translations from the main bundle, however this does not automatically create the keys in string catalog

Question

Is there any possibility to reuse the translations from the main bundle? Maybe there is a hack to make the keys appear automatically in the correct bundle? Or is it a bug?

Hello,

Xcode's automatic string extraction always assumes that strings will be looked up from their own bundle, which is best practice for localization.

The reason looking up strings from other bundles (especially higher-level bundles such as Bundle.main) is not typically recommended is because there is no guarantee that your clients will actually have those strings defined. And Xcode cannot guarantee it because your Package could be used by clients outside of your own Xcode workspace.

When you do need one bundle to use strings defined in another, one safe way to do this is to have one bundle define these strings as usual, and then expose them to the other bundle via API.

For example, perhaps you could have an OKButton: View type in some shared target that you could then use in dependent Packages.

Reusing string catalog translations in swift packages
 
 
Q