NSBundle.localizedStringForKey
doesn't work properly in pair with
NSString.localizedStringWithFormat
. Looks like
NSString
losing some metadata during conversion into Kotlin
String
.
Here is example on Kotlin:
import platform.Foundation.NSBundle
import platform.Foundation.NSString
import platform.Foundation.localizedStringWithFormat
class TestClass(private val bundle: NSBundle) {
fun localizedStringWithFormat(string: String): String {
return NSString.localizedStringWithFormat(
this.bundle.localizedStringForKey(string, "", "Localizable"), 5)
}
}
Here is the code in swift:
let testClass = TestClass(bundle: Bundle.main)
let testString = "screen_main_plural_string"
let nativeStr = Bundle.main.localizedString(forKey: testString, value: "", table: "Localizable") as NSString
NSLog("swift: %@", NSString.localizedStringWithFormat(nativeStr, 5))
NSLog("kotlin: %@", testClass.localizedStringWithFormat(string: testString))
Output logs:
swift: Plural: 5 apples
kotlin: %#@value@