Internationalization in Apple
Learn how to create a basic implementation of field-level translation in an Apple project.
In your space, open Settings → Internationalization → Languages and add es (Spanish).
- In the article content type block schema, set the
titleandcontentfields as translatable. - Go to each article, select the Spanish language, and provide translated content. You can also use AI Translations.
Use the device locale
Section titled “Use the device locale”Update ExampleApp.swift to determine the language from the device locale.
…@mainstruct ExampleApp: App { @State private var path = NavigationPath()
private static let availableLanguages = ["es"]
private let client = StoryblokClient( library: Block.self, accessToken: "YOUR_ACCESS_TOKEN", version: { #if DEBUG .draft #else .published #endif }(), region: .eu, // Choose the correct region from your Space. language: Locale.preferredLanguages .map { Locale(identifier: $0).language.languageCode?.identifier ?? $0 } .first { availableLanguages.contains($0) } )…First, an array with all language codes configured in the space is defined.
Next, Locale.preferredLanguages lists the user’s preferred languages in order of preference, and the first match among the languages available in the space is passed to the StoryblokClient initializer via its language parameter.
To test the implementation, change the device language to Spanish under Settings → General → Language & Region, or add a Spanish localization to your project to enable a per-app language preference. The app now renders the translated article content.
Related resources
Section titled “Related resources”Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community