iosswiftswiftuiuikitinternationalization

Which possibility should be used for Strings, which become displayed & translated?


I'm currently reading about the possibilities, which Swift offers for translating Strings. I would like to choose the right option. Meanwhile I'm more confused, instead of becoming more sure. There are LocalizedStringKey, LocalizedStringResource and String with arguments.

Which one should I use, when I know in advance, that the String will become shown on the UI and perhaps translated?

Respectively which option is optimal for translation?


Solution

  • When dealing with localized strings in Swift, especially for UI elements, choosing the right approach is crucial. Here’s a breakdown of the options:

    1️⃣ LocalizedStringKey (Best for SwiftUI)


    2️⃣ LocalizedStringResource (Best for Performance)


    3️⃣ String with NSLocalizedString (Best for Non-SwiftUI Code)