Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Locale and Language from the device, with Kotlinmultiplatform

I am creating my first app on kotlin multi-platform, and a need to get some device's information like language and maybe country.

I am looking for a way to get on both devices, android and iOS, using Kotlin multi-plataform.

It is possible? Or it's only possible make this on native way on both devices?

like image 999
Jhonata Ávila Avatar asked Jan 25 '23 12:01

Jhonata Ávila


1 Answers

Something like the following.

Common

expect val myLang:String?
expect val myCountry:String?

iOS

actual val myLang:String?
    get() = NSLocale.currentLocale.languageCode

actual val myCountry:String?
    get() = NSLocale.currentLocale.countryCode

Android

actual val myLang:String?
    get() = Locale.getDefault().language

actual val myCountry:String?
    get() = Locale.getDefault().country
like image 125
Kevin Galligan Avatar answered May 11 '23 07:05

Kevin Galligan