Stringboot provides native integrations for both SwiftUI and UIKit.
SwiftUI
SBText
Use the SBText view to automatically display localized strings. It updates automatically when the language changes.
import SwiftUI
import StringbootSDK
struct ContentView: View {
var body: some View {
VStack {
// Basic usage
SBText("welcome_message")
.font(.title)
// With explicit language (optional)
SBText("description", lang: "es")
}
}
}
Property Wrapper
Use @StringbootString to bind a string to a property.
struct ContentView: View {
@StringbootString("welcome_message") var welcomeText: String
var body: some View {
Text(welcomeText)
}
}
UIKit
SBLabel
SBLabel is a UILabel subclass that automatically updates its text.
import UIKit
import StringbootSDK
class ViewController: UIViewController {
let titleLabel = SBLabel(key: "welcome_message")
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(titleLabel)
}
}
Extensions
You can also use extensions on standard UIKit components.
let button = UIButton()
button.setStringbootTitle(key: "submit_btn", for: .normal)
let textField = UITextField()
textField.setStringbootPlaceholder(key: "email_placeholder")
Manual Access
For non-UI logic, you can fetch strings asynchronously.
Task {
let text = await StringProvider.shared.get("error_message")
print(text)
}
Changing Language
To switch the language of the app:
@StateObject var languageManager = StringbootLanguageManager()
Button("Switch to Spanish") {
languageManager.setLanguage("es")
}
StringbootLanguageNotifier.shared.changeLanguage(to: "es")
When you change the language using StringbootLanguageManager or StringbootLanguageNotifier, all SBText and SBLabel instances update automatically.