๐ Language Selection
This app supports multiple languages โ users can switch them anytime from the Settings screen.
โ Supported Languages
Display Label | Code |
---|---|
System Default | default |
English | en |
Malayalam | ml |
โ You can easily add more by updating the language arrays and translation files.
๐ง How It Works
Language settings are handled by a helper class: LocaleHelper.kt
.
When the user selects a language from the dropdown:
- The app stores the language code in SharedPreferences.
-
Then calls: ```kotlin LocaleHelper.setLocale(context, langCode) ````
-
Finally, the activity is restarted using:
kotlin
requireActivity().recreate()
to apply the new language.
๐ Persistence
The selected language is saved using this key in preferences:
Locale.Helper.Selected.Language
If the user selects โSystem Defaultโ, the preference is cleared and the app uses the phoneโs current system language.
๐งโ๐ How to Add a New Language
- Create a new folder in
res/
with the locale code. For example:
res/values-hi/strings.xml // Hindi
res/values-ta/strings.xml // Tamil
-
Add your translated strings in that
strings.xml
. -
Update:
res/values/strings.xml
โ Add tolanguage_levels
string array.SettingFragment.kt
โ Add the new code tolanguageCodeMap
.
Example:
private val languageCodeMap = mapOf(
0 to "default",
1 to "en",
2 to "ml",
3 to "hi" // Hindi
)