Export Localizations vs Swift Packages

In regular projects, there is an "Export Localizations" option in the Product menu, but for Swift Packages, this is not available.

Adding local Swift Packages as dependencies of a regular project and using Export Localizations on the regular project doesn't include the Localizable strings from the Packages' sources either.

The command-line version (xcodebuild -exportLocalizations) has the same restrictions.

Is there a way to export NSLocalizedString occurrences to an xliff for Swift Packages? Or are we supposed to do things manually for now?

Update: I've worked around it for now:

  • use genstrings to export NSLocalizedStrings occurrences in each local package to Localizable.strings files
  • add a dummy framework target to the project, but don't embed it in the application
  • add all Localizable.strings files to the project and add them to the dummy framework

From then on, "Export Localizations" also includes the packages' localizable strings in the exported xliff file.

Please use Feedback Assistant to file a request for using localization export / import with Swift packages in Xcode. Thanks!

I have created a request for this. FB9632052 (Xcode import/export of Localizations for Swift Packages)

We will use the workaround mentioned below in the meantime.

Xcode 14 added support for this.

However, in case this helps anyone else, one detail I didn't realize at first is that you have to add the defaultLocalization: to your Package() initializer in your Package.swift file. Otherwise, it doesn't think your package is localizable, and skips it.

let package = Package(
    name: "MyLocalPakcages",
    defaultLocalization: "en",
    platforms: [
        .iOS(.v15),
        […]

And then, in Xcode 14, the export fails because by default it tries to build with an old macOS SDK, which doesn't know about all the new SwiftUI stuff. So I had to add this to my Package.swift file too:

    platforms: [
        .iOS(.v15), // or whatever you might have
        .macOS("99.0"),  // <-- This is the important part to get it to not build with the old macOS SDK
    ],
Export Localizations vs Swift Packages
 
 
Q