Search code examples
xcodeswiftuilocalizationxcode15

Why doesn't the text from a SwiftUI Label appear in the Xcode 15 string catalog?


When I use Xcode 15 beta 3 to add a string catalog to an existing project (created with Xcode 14) and then build the current scheme, the resulting Localizable.xcstrings file doesn't contain any text from SwiftUI Label views. It does contain text from Text views, navigation bar titles, and various other views, but nothing from Label. My labels are declared like this:

Label("Hello world", systemImage: "home")

If I create an empty project using Xcode 15 beta 3 and then add a string catalog and build, the text from a Label does appear in Localizable.xcstrings.

What is stopping the text from Label appearing in the string catalog when the project was created with a previous version of Xcode?


Solution

  • The project created with Xcode 15 beta 3 has the SWIFT_EMIT_LOC_STRINGS setting defined in the project build settings. Without this setting, Xcode will only extract string literals in Text initializers. See here.

    Adding SWIFT_EMIT_LOC_STRINGS to the build settings of my existing Xcode project fixed the problem.