iOS - Access Localization
note
Modules that inherit from Q2ModuleBase or directly conform to the Module interface
receive moduleDataSource, which exposes localization access through localization.
Quick Start
Follow these three steps in any module:
- Access
moduleDataSource. - Request a localized value using
localization. - Apply the returned value to your UI text.
Quick Start Example
let title = moduleDataSource?.localization?.localizedString("_t.mob.rdc.title_header")
titleLabel.text = title
Implementation
Q2ModuleBase already provides moduleDataSource, so you can use localized strings
directly.
Q2ModuleBase Example
import Q2ModuleInterfaces
import UIKit
final class PartnerUIModule: Q2ModuleBase {
private let titleLabel = UILabel()
override func didOpen(_ identifier: String) {
titleLabel.text = moduleDataSource?.localization?.localizedString("_t.mob.rdc.title_header")
}
}
SwiftUI Usage
If your module UI is built with SwiftUI, request the localized value the same way.
SwiftUI Example
import Q2ModuleInterfaces
import SwiftUI
struct PartnerView: View {
let moduleDataSource: ModuleDataSource?
var body: some View {
Text(moduleDataSource?.localization?.localizedString("_t.mob.rdc.title_header") ?? "")
}
}
Guidance
- Use localization keys (for example
_t.mob...) instead of hardcoded display text. - Keep keys exact; avoid extra quotes or whitespace in the key string.
- Prefer
localizedString(_ key: String)for UI text because it returns the key itself if a value is not found.
Key Resolution
When your module calls:
let value = moduleDataSource?.localization?.localizedString("_t.mob.rdc.title_header")
localized values resolve in this order:
- Active app language table.
- Backup
en-UStable (fromi18nBackup). - If still unresolved:
localizedString(_ key: String)returns the key.localizedString(forKey:)returnsnil.
Key Source
Use these baseline files to discover keys:
Q2DevApp/conf/i18nBackup.jsonQ2DevApp/conf/i18n.json
tip
Localization data can be refreshed by environment/theme setup at runtime, so values may differ from the baseline files.