Created
April 3, 2023 20:30
-
-
Save qamarelsafadi/84a53921f794755d649871b418eaeb5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.LocaleManager | |
import android.content.Context | |
import android.os.Build | |
import android.os.LocaleList | |
import androidx.appcompat.app.AppCompatDelegate | |
import androidx.core.os.LocaleListCompat | |
import java.util.Locale | |
/// Change Langauage Extenstion | |
fun Context.changeLocale(language: String){ | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
this.getSystemService(LocaleManager::class.java) | |
.applicationLocales = LocaleList( | |
Locale.forLanguageTag( | |
language | |
) | |
) | |
} else { | |
AppCompatDelegate.setApplicationLocales( | |
LocaleListCompat.forLanguageTags( | |
language | |
) | |
) | |
} | |
} | |
/// Get current locale | |
val currentAppLocales: String = | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
context.getSystemService(LocaleManager::class.java).applicationLocales.toLanguageTags() | |
} else { | |
AppCompatDelegate.getApplicationLocales().toLanguageTags() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment