Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2024 App ServicesSwiftUI & UI Frameworks

WWDC24 · 17 min · App Services / SwiftUI & UI Frameworks

Build multilingual-ready apps

Ensure your app works properly and effectively for multilingual users. Learn best practices for text input, display, search, and formatting. Get details on typing in multiple languages without switching between keyboards. And find out how the latest advances in the String Catalog can make localization even easier.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

Code shown on screen · 13 snippets

Specify textInputContextIdentifier swift · at 3:18 ↗
override var textInputContextIdentifier: String? {
    uniqueID
}
Place a view directly above the keyboard swift · at 3:41 ↗
textView.inputAccessoryView = viewAboveKeyboard
Use keyboardLayoutGuide to adapt to keyboard swift · at 4:00 ↗
view.keyboardLayoutGuide.topAnchor.constraint(equalToSystemSpacingBelow: textView.bottomAnchor, multiplier: 1.0).isActive = true
Check for marked text before modifying swift · at 4:42 ↗
if textView.markedTextRange.empty {
    // Perform actions involving editing text
}
Use localizedStandardRange when searching swift · at 5:58 ↗
let range = text.localizedStandardRange(of: search)
Use color differences to highlight text swift · at 7:24 ↗
attributedString[range].foregroundColor = highlightColor
Text Styles swift · at 9:39 ↗
// Text Styles

// SwiftUI
Text("Hello, world!") // uses .body Text Style by default
Text("Hello, world!").font(.title)

// UIKit
let label = UILabel()
label.text = "Hello, world!"
label.font = UIFont.preferredFont(forTextStyle: .body)

// AppKit
let textField = NSTextField(labelWithString: "Hello, world!")
textField.font = NSFont.preferredFont(forTextStyle: .body)

// Keep clipsToBounds off
clipsToBounds = false
Typesetting language swift · at 10:03 ↗
// Typesetting language

// SwiftUI
Text(verbatim: "Hello, world!").typesettingLanguage(.init(languageCode: .english))

// UIKit
let label = UILabel()
label.text = "Hello, world!"
label.traitOverrides.typesettingLanguage = Locale.Language(languageCode: .english)
Formatting names swift · at 10:29 ↗
// Formatting names

let nameComponents = PersonNameComponents
  (givenName: "瑗珺", familyName: "汪", nickname: "珺珺")

// Short Name (respects settings like “Prefer Nicknames”)
let shortName = 
 nameComponents.formatted(.name(style: .short)) // 珺珺

// Abbreviated Name (can be used for monograms)
let monogram = 
 nameComponents.formatted(.name(style: .abbreviated)) // 汪
Examples of personalizing text markdown · at 12:20 ↗
"^[Nuestro %@](inflect: true) está ^[hecho](agreeWithArgument: 1) de %@."
"अगर आप पहुँच नहीं ^[पाते हैं](inflect: true)"
"예: ‘^[%@을](inflect: true) 켤 때’"
Format numbers using Text swift · at 13:43 ↗
Text("\(numberOfDays)-day forecast")
Format numbers using AttributedString swift · at 14:21 ↗
AttributedString(localized: "10-day forecast")
AttributedString(localized: "0.5× zoom")
Launch to your app’s settings swift · at 15:23 ↗
// Launch to your app’s settings
if let url =
URL(string: UIApplication.openSettingsURLString) {
   await UIApplication.shared.open(url)
}

Resources