Reputation: 95
i am working on app using SwiftUI in Xcode, and i want to localise it, but i have an issue. I already done all steps from youtube video
and when i build an app i have only keys instead values (hll instead Hello), so i tried Text("hll") and Text(LocalizedStringKey("hll")). What am i missing?
Upvotes: 0
Views: 3487
Reputation: 33
extension Text {
public init<S>(_ text: S) where S : StringProtocol {
let text = String(text)
let path = Bundle.main.path(forResource: "en", ofType: "lproj")
let bundle = Bundle(path: path!)
let translated = NSLocalizedString(text, tableName: "Localizable", bundle: bundle!, value: "", comment: "")
self.init(verbatim: translated)
}
Upvotes: 0
Reputation: 29242
Make sure you have the Localizable.strings
file in your project. There is where LocalizedStringKey
looks for the keys/values as a default.
https://developer.apple.com/documentation/swiftui/localizedstringkey
If you want to define a different file use the
Text(LocalizedStringKey, tableName: String?, bundle: Bundle?, comment: StaticString?)
initializer and the tableName
should match your .strings
file name.
Upvotes: 3