Skip to content

๐ŸŒ 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:

  1. The app stores the language code in SharedPreferences.
  2. Then calls: ```kotlin LocaleHelper.setLocale(context, langCode) ````

  3. 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

  1. Create a new folder in res/ with the locale code. For example:

res/values-hi/strings.xml // Hindi res/values-ta/strings.xml // Tamil

  1. Add your translated strings in that strings.xml.

  2. Update:

    • res/values/strings.xml โ†’ Add to language_levels string array.
    • SettingFragment.kt โ†’ Add the new code to languageCodeMap.

Example:

private val languageCodeMap = mapOf(
    0 to "default",
    1 to "en",
    2 to "ml",
    3 to "hi"  // Hindi
)