I tried to build LocalizedKeyString using String's new Initializer.
String(localized: "hello",locale: locale)
When I change the language setting of the device, everything works as expected.
However, when I try to get the string in a specific language using the specified Locale, I can only ever get the string in .current.
String(localized: "hello",locale: Locale(identifier: "zh-cn"))
func getString(locale:Locale) -> String{
String(localized: "hello",locale: locale)
}
If you change the display language of the project (or the language setting of the device), the text in Text is always displayed correctly.
Text(getString(locale:.current))
However, the code in onAppear
print(getString(locale:Locale(identifier: "zh-cn")))
It only displays the same content as Text, but not the specified Chinese.
Is it my fault that the new Initializer The understanding is not correct, or the bug of String
init(localized keyAndValue: String.LocalizationValue, table: String? = nil, bundle: Bundle? = nil, locale: Locale = .current, comment: StaticString? = nil)
FB number: FB9675845
Post not yet marked as solved
Hi, I thought that with Exporting String with localization in all files but it didn't. It export all SwiftUI Text and Button Strings but thats it.
I had a file where I have.
String(localized: “Hello, world!”, comment: “Hello”)
It is in project and it is passed to the view later.
Tired in Beta 5 and RC
Thanks
Post not yet marked as solved
Hi. I'm looking forward to using the new localization features as shown in 10221.
Is there a version of String(localized: ) that uses a key that is separate from the user-facing string? This is my preferred approach even with short strings but becomes really important for long strings like what you might see for an explanation in a table view footer.
And is there support for multi-line strings? Again, with a key?
Many thanks.