On iOS the standard way we obtain a string, with a...
# moko
t
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
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
thanks for the swift reply!