https://kotlinlang.org logo
#moko
Title
# moko
t

Thomas

03/19/2024, 1:43 AM
On iOS the standard way we obtain a string, with automatic locale resolution, is through
StringResource.desc().localized()
. Is there a good way to obtain a string of a particular locale programmatically, without automatic locale resolution? Like perhaps a function that takes a
NSLocale
object. Thanks.
a

alex009

03/19/2024, 2:26 AM
you can create extension function for StringResource and use NSLocale. StringResource contains stringKey and nsBundle that contains this string.
Copy code
let path = strinRes.bundle.path(forResource: languageCode, ofType: "lproj")
let bundle = Bundle(path: path!)
let result = NSLocalizedString(stringRes.resourceId , tableName: nil, bundle: bundle!, value: "", comment: "")
something like this
🙌 1
t

Thomas

03/19/2024, 2:27 AM
thanks for the swift reply!