Localization
Localization
Translate strings and assets per language and use Text/NSLocalizedString to display localized content.
Localize Strings
Add Localizable.strings per language and use NSLocalizedString or SwiftUI's Text("key").
Syntax: "key" = "value"; in each Localizable.strings, read with NSLocalizedString("key", comment: "") or Text("key").
Example
"hello" = "Hello";
"welcome_name" = "Welcome, %@";
"hello" = "Hola";
"welcome_name" = "Bienvenido, %@";
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("hello")
Text(String(format: NSLocalizedString("welcome_name", comment: ""), "Swift"))
}
}
}
Pluralization (.stringsdict)
Use .stringsdict to support plural rules that vary by language.
Example
{
"apples_count" : {
"NSStringLocalizedFormatKey" : "%#@apples@",
"apples" : {
"NSStringFormatSpecTypeKey" : "NSStringPluralRuleType",
"NSStringFormatValueTypeKey" : "d",
"one" : "%d apple",
"other" : "%d apples"
}
}
}
import SwiftUI
struct CounterView: View {
let count: Int
var body: some View {
Text(String.localizedStringWithFormat(NSLocalizedString("apples_count", comment: ""), count))
}
}
SwiftUI Localization Tips
- Prefer
Text("key")for static keys present inLocalizable.strings. - For values, compose with
String.localizedStringWithFormatand a localized key (supports.stringsdict). - Use system formatters for locale-aware output: numbers, dates, currency.
Example
import SwiftUI
struct PricesView: View {
let price: Double = 12.5
let date = Date()
var body: some View {
VStack(alignment: .leading) {
Text(price, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
Text(date, style: .date)
}
}
}
Testing Localization
- In Xcode scheme, set Application Language to a target language or a Pseudolanguage to catch truncation.
- Test Right-to-Left using the Right-to-Left Pseudolanguage and verify UI flips correctly.
- Avoid hard-coded strings; every user-facing string should be a key in
Localizable.strings. - Use String Catalogs in modern Xcode to manage keys and translations at scale.
App Metadata
Localize your App Store listing: name, subtitle, description, and screenshots per locale.
Tip: Use String Catalogs in modern Xcode to manage localizations at scale.