Hi there, is there a way to change the strings lan...
# moko
p
Hi there, is there a way to change the strings language that is being served in iOS? I have tried doing that by changing the StringDesc.LocaleType by it does not work (or I am missing something).
Copy code
fun setLocale(locale: String) {
  StringDesc.localeType = StringDesc.LocaleType.Custom (locale)
}
a
hi. StringDesc locale change language only for StringDesc.localize results. if you read string not by
StringDesc.localize
you will read system language
v
Also, what is the exact
locale
you are passing and do you have this exact resource directory? You have to pass the exact locale as the resource directory is named under
resources/MR/*
. So if you have a directory called
fr
, you cannot pass
fr-FR
as a
locale
. You must pass
fr
, or add some additional logic to resolve this
p
Hi there, I have fresh news. 1. I wanted to have greek language as my base, so in the base folder strings.xml file I had greek strings. 2. I have also created a second folder named “en” for the english strings. 3. Finally I tried setting
iosBaseLocalizationRegion = "el"
(not worked) and leave it blank (also not worked) The setup that seems to work (I must confirm it 100%) is this: 1. The base folder contains the english strings 2. I have also created a second folder named “el” for the greek strings. 3.
iosBaseLocalizationRegion = "en"
4. In order to change locale I call the function:
Copy code
fun setLocale(locale: String) {
    StringDesc.localeType = StringDesc.LocaleType.Custom (locale)
}
with the appropriate locale (“en” or “el”).
The locale change seems to work fine. The final issue that I have to figure out is that the english strings appear with their keys (e.g home_screen_title) and not with their values. The produced
Localizable.strings
file seems fine but I suspect that there is a typo somewhere in the strings.xml file.
a
correct is use base for greek and setup valid base localization. maybe you not setup xcode project? https://github.com/icerockdev/moko-resources#installation check
ios-app Info.plist
block
if you see keys on ios instead of locales - maybe you have static framework and need to setup additional build phase https://github.com/icerockdev/moko-resources#static-kotlin-frameworks-support
p
The setup seems ok. I see keys because the exported
Localizable.strings
file for english was invalid and the iOS did a fallback and returned the key. In order to confirm that the content of the
Localizable.strings
was invalid I took it’s strings and placed them into xcode’s Localizable strings. Then I took a compile error. This time the issue was the text above:
Copy code
"my_key" = "Click \\"Continue\\" to choose how you want to receive the new equipment.\\"";
and the KMM string was this:
Copy code
<string name="my_key">Click \&quot;Continue\&quot; to choose how you want to receive the new equipment.\&quot;</string>
Apparently there was no compile issue and the android code worked fine. If I may suggest, there should be an extra check in order to determine that the produced
Localizable.strings
file inside any .lproj folder is valid.
a
maybe you know some cli cmd for check correctness of this file?
p
@alex009 about the base folder you are right, there was no need to change it.
I have tried the command tool below but I have not seen it in depth:
Copy code
plutil -lint Localizable.strings
In the example that I described above it worked fine
b
Hi there, I also tried to change locale from app. if I set localeType in start up it is working import SwiftUI import shared
@main
struct iOSApp: App {
init() {
//here
KoinHelperKt.doInitKoin()
}
var body: some Scene {
WindowGroup {
ContentView()
.preferredColorScheme(.light)
}
}
}
but later when I tried to call it in runtime, it did not work
fun setLocale(locale: String) {
StringDesc.localeType = StringDesc.LocaleType.Custom(locale)
preferenceManager?.setLocale(locale)
}
I'm new to iOS development, need some instructions. Thanks in advance!
a
You should trigger reloading of you UI, it can't be triggered automatically from kotlin
🤝 1
b
@alex009 thanks a lot it worked. 👍
530 Views