How to create localizable XCode previews

To preview localizable content within a XCode preview, use an environment variable or pass a language code to an object that holds localizable information.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 08/15/2024 at 14:59
Last Updated on 08/30/2024 at 13:18
<p>Two flowers that represent SwiftUI and XCode side by side. Beneath them sits the text "Localizable Previews."</p>

To preview localizable content within a XCode preview, use an environment variable or pass a language code to an object that holds localizable information.

Subscribe

The example can be found on the main branch of our SwiftUI Open Source Starter Project linked below.

Download Open Source SwiftUI Starter Project
<p>A screenshot of the code of a preview that uses the locale environment variable as well as passing the LanguageCoordinator the language code.</p>

To localize content using Apple's standard framework, the the following modifier: .environment(\.locale, .init(identifier: languageCode))

We have also adapted this example to show how it works with a custom coordinator like our LanguageCoordinator.

How to localize iOS, VisionOS MacOS, TVOS & WatchOS apps in SwiftUI

Looking to learn more about SwiftUI, Swift, Design and Technology?

Search our blog to learn more about Swift, SwiftUI, design and technology.

Search our Blog

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe