Internationalization (i18n)
This app supports multiple languages using a hybrid approach:
- Resource strings in
res/values*/strings.xml
for all UI text. - Excel-driven, per-language content in
app/src/main/assets/questions/{lang}.xlsx
for questions. - Per-language user guide HTML in
app/src/main/assets/userguide/{lang}.html
. - Runtime language switching via
LocaleHelper
.
Resource Strings (UI)
- Location:
app/src/main/res/values/strings.xml
,values-<lang>/strings.xml
(e.g.,values-hi
,values-ml
). - Usage:
- XML:
@string/app_name
- Kotlin:
getString(R.string.app_name)
or with argsgetString(R.string.score_fmt, score)
- Conventions:
- Use meaningful names:
title_home
,action_retry
,msg_correct_answer
. - Prefer placeholders over string concatenation: "Score: %1$d".
- Add plurals when needed:
<plurals name="questions_count">
<item quantity="one">%d question</item>
<item quantity="other">%d questions</item>
</plurals>
Runtime Locale Switching
- Manager:
presentation/features/setting/util/LocaleHelper.kt
. - Behavior:
- Applies the chosen language at app startup and when changed in Settings.
- Persists selection in preferences and updates configuration/context.
- UI should re-read strings after configuration update (activities/fragments recreated by helper as needed).
Localized Content (Excel + HTML)
- Questions Excel per language:
app/src/main/assets/questions/{lang}.xlsx
- Loaded by
core/utility/excel/ExcelQuestionLoader.kt
(with cache inQuestionCache
). - Filtered by Mode and Difficulty. Column layout summarized in
dev/structure.md
. -
Keep column structure identical across languages; only localize question templates and literals.
-
User guide per language:
app/src/main/assets/userguide/{lang}.html
- Served by
data/repository/userguide/UserGuideRepositoryImpl.kt
and consumed viaGetUserGuideHtmlUseCase
.
TextโtoโSpeech (TTS)
- TTS follows the current app locale via
core/utility/common/TTSUtility.java
. - Ensure the device has a voice installed for the selected language; otherwise Android may fall back.
Add a New Language (Checklist)
- Strings resources
- Create
app/src/main/res/values-<lang>/strings.xml
. -
Translate all keys from base
values/strings.xml
. -
Questions Excel
- Add
app/src/main/assets/questions/<lang>.xlsx
. -
Match the same sheet/columns as other languages (see
dev/structure.md
). -
User guide (optional but recommended)
-
Add
app/src/main/assets/userguide/<lang>.html
. -
LocaleHelper
-
Add the language to the supported list and settings options handled by
LocaleHelper.kt
. -
Verify
- Launch, switch language in Settings, confirm:
- All screens show translated strings.
- Questions load from the new Excel.
- User guide opens in the selected language.
- TTS pronounces texts appropriately (install voice if needed).
Tips & Pitfalls
- Keep placeholders identical across translations (
%1$d
,%1$s
, etc.). - Avoid embedding numbers or punctuation that vary by locale; prefer placeholders.
- For right-to-left languages, verify layout mirroring and content descriptions.
- If a translation is missing, Android falls back to
values/strings.xml
; Excel does notโensure the{lang}.xlsx
exists.