Reputation: 1
I am currently working with english to japanese feature in an app on the kotlin android studio, but my problem is that even though some of the translation is working, there are translated text that is not displaying japanese character instead it display random characters that can't be read. how can I fix this error?
I have a constant for the arraylist of strings, i have a data class I am expecting it to translate once the user choose to translate the app in to japanese
Upvotes: 0
Views: 67
Reputation: 153
If specific characters are displaying incorrectly, it could be related to encoding issues. Be sure that you are using UTF-8 encoding for your strings.
val yourString = "Hello"
val stringAsByteArray = originalString.toByteArray()
val utf8String = String(stringAsByteArray, Charsets.UTF_8)
Also, I suggest you to handle string resources by using strings.xml.
strings.xml(en)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
</resources>
strings.xml(jp)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">こんにちは</string>
</resources>
Upvotes: 0