From 7ea2c5534ee629b3d355b7d2147568e2363af1a7 Mon Sep 17 00:00:00 2001 From: Yuku on yuku12 Date: Tue, 6 Oct 2026 13:54:37 +0800 Subject: [PATCH] Honor app language in appearance and download messages --- .../br/VersionDownloadCompleteReceiver.java | 7 +++-- .../yuku/alkitab/base/sv/DownloadService.java | 3 +- .../base/sv/VersionConfigUpdaterService.java | 17 ++++++----- .../yuku/alkitab/base/util/DownloadMapper.kt | 7 +++-- .../yuku/alkitab/base/widget/Localized.java | 2 +- .../base/widget/TextAppearancePanel.kt | 10 +++++-- Alkitab/src/main/res/values-in/strings.xml | 1 + ...onfigurationWrapperLocalizedContextTest.kt | 30 +++++++++++++++++++ 8 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java b/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java index f1b63e394..6a04db65c 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/br/VersionDownloadCompleteReceiver.java @@ -21,6 +21,7 @@ import yuku.alkitab.base.util.Background; import yuku.alkitab.base.util.DownloadMapper; import yuku.alkitab.base.util.Foreground; +import yuku.alkitab.base.widget.Localized; import yuku.alkitab.debug.R; import yuku.alkitab.io.BibleReader; import yuku.alkitab.io.OptionalGzipInputStream; @@ -105,7 +106,7 @@ public static void onReceive(final int id) { } catch (IOException e) { AppLog.e(TAG, "I/O error when saving downloaded version", e); Foreground.run(() -> context.startActivity( - AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_saving_io_error)) + AlertDialogActivity.createOkIntent(null, Localized.string(R.string.version_download_saving_io_error)) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) )); AppEvents.emitVersionListReload(); @@ -123,7 +124,7 @@ public static void onReceive(final int id) { destFile.delete(); Foreground.run(() -> context.startActivity( - AlertDialogActivity.createOkIntent(null, context.getString(R.string.version_download_corrupted_file)) + AlertDialogActivity.createOkIntent(null, Localized.string(R.string.version_download_corrupted_file)) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) )); AppEvents.emitVersionListReload(); @@ -151,7 +152,7 @@ public static void onReceive(final int id) { MVersionDb.clearVersionImplCache(); Foreground.run(() -> { - Toast.makeText(App.context, TextUtils.expandTemplate(context.getText(R.string.version_download_complete), mvDb.longName), Toast.LENGTH_LONG).show(); + Toast.makeText(App.context, TextUtils.expandTemplate(Localized.text(R.string.version_download_complete), mvDb.longName), Toast.LENGTH_LONG).show(); }); AppEvents.emitVersionListReload(); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/sv/DownloadService.java b/Alkitab/src/main/java/yuku/alkitab/base/sv/DownloadService.java index 39e53b6c0..94d2b181a 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/sv/DownloadService.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/sv/DownloadService.java @@ -21,6 +21,7 @@ import yuku.alkitab.base.App; import yuku.alkitab.base.connection.Connections; import yuku.alkitab.base.util.AppLog; +import yuku.alkitab.base.widget.Localized; import yuku.alkitab.debug.R; public class DownloadService extends Service { @@ -190,7 +191,7 @@ void changeState(State newState) { boolean renameOk = entry.tempFile.renameTo(entry.completeFile); if (!renameOk) { AppLog.w(TAG, "Failed to rename file from " + entry.tempFile + " to " + entry.completeFile); - entry.errorMsg = getString(R.string.dl_failed_to_rename_temporary_file); + entry.errorMsg = Localized.string(R.string.dl_failed_to_rename_temporary_file); changeState(State.failed); return entry; } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/sv/VersionConfigUpdaterService.java b/Alkitab/src/main/java/yuku/alkitab/base/sv/VersionConfigUpdaterService.java index ba4357f41..76c8837bd 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/sv/VersionConfigUpdaterService.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/sv/VersionConfigUpdaterService.java @@ -16,6 +16,7 @@ import yuku.alkitab.base.events.AppEvents; import yuku.alkitab.base.storage.Prefkey; import yuku.alkitab.base.util.AppLog; +import yuku.alkitab.base.widget.Localized; import yuku.alkitab.debug.BuildConfig; import yuku.alkitab.debug.R; @@ -95,7 +96,7 @@ void handleCheckUpdate(final boolean auto) { AppLog.e(TAG, "failed to download modify time", e); if (!auto) { - toast(getString(R.string.version_config_updater_error_download_modify_time)); + toast(Localized.string(R.string.version_config_updater_error_download_modify_time)); } return; @@ -108,14 +109,14 @@ void handleCheckUpdate(final boolean auto) { AppLog.e(TAG, "failed to parse modify time file", e); if (!auto) { - toast(getString(R.string.version_config_updater_error_modify_time_cannot_parse)); + toast(Localized.string(R.string.version_config_updater_error_modify_time_cannot_parse)); } return; } if (!modifyTimeObj.success) { if (!auto) { - toast(getString(R.string.version_config_updater_error_modify_time_failed, modifyTimeObj.message)); + toast(Localized.string(R.string.version_config_updater_error_modify_time_failed, modifyTimeObj.message)); } return; } @@ -124,7 +125,7 @@ void handleCheckUpdate(final boolean auto) { if (localModifyTime != 0 && localModifyTime >= modifyTimeObj.modifyTime) { AppLog.d(TAG, "Update: no newer version available. Server modify time: " + new Date(modifyTimeObj.modifyTime * 1000L) + " Local modify time: " + new Date(localModifyTime * 1000L)); if (!auto) { - toast(getString(R.string.version_config_updater_no_newer_available)); + toast(Localized.string(R.string.version_config_updater_no_newer_available)); } return; } @@ -137,7 +138,7 @@ void handleCheckUpdate(final boolean auto) { AppLog.e(TAG, "failed to download version list", e); if (!auto) { - toast(getString(R.string.version_config_updater_error_download_list)); + toast(Localized.string(R.string.version_config_updater_error_download_list)); } return; @@ -145,7 +146,7 @@ void handleCheckUpdate(final boolean auto) { if (!VersionConfig.isValid(versionConfigBody)) { if (!auto) { - toast(getString(R.string.version_config_updater_error_parsing_list)); + toast(Localized.string(R.string.version_config_updater_error_parsing_list)); } return; @@ -154,13 +155,13 @@ void handleCheckUpdate(final boolean auto) { final boolean updateSuccess = VersionConfig.useLatest(versionConfigBody, modifyTimeObj.modifyTime); if (!updateSuccess) { if (!auto) { - toast(getString(R.string.version_config_cannot_write_updated_list)); + toast(Localized.string(R.string.version_config_cannot_write_updated_list)); } return; } if (!auto) { - toast(getString(R.string.version_config_updater_updated)); + toast(Localized.string(R.string.version_config_updater_updated)); } Preferences.setInt(Prefkey.version_config_last_update_check, now); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/util/DownloadMapper.kt b/Alkitab/src/main/java/yuku/alkitab/base/util/DownloadMapper.kt index 2de0228c6..767263366 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/util/DownloadMapper.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/util/DownloadMapper.kt @@ -23,6 +23,7 @@ import yuku.alkitab.base.App import yuku.alkitab.base.ac.AlertDialogActivity import yuku.alkitab.base.br.VersionDownloadCompleteReceiver import yuku.alkitab.base.events.AppEvents +import yuku.alkitab.base.widget.Localized import yuku.alkitab.debug.R /** @@ -201,13 +202,13 @@ class DownloadMapper private constructor() { val msg: CharSequence = when (errorType) { VersionDownloadWorker.ERROR_CONNECTION, VersionDownloadWorker.ERROR_CANCELLED -> - TextUtils.expandTemplate(App.context.getString(R.string.version_download_network_error), row.title) + TextUtils.expandTemplate(Localized.string(R.string.version_download_network_error), row.title) VersionDownloadWorker.ERROR_STORAGE -> - App.context.getString(R.string.version_download_saving_io_error) + Localized.string(R.string.version_download_saving_io_error) else -> - TextUtils.expandTemplate(App.context.getString(R.string.version_download_server_error), row.title) + TextUtils.expandTemplate(Localized.string(R.string.version_download_server_error), row.title) } App.context.startActivity( diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/Localized.java b/Alkitab/src/main/java/yuku/alkitab/base/widget/Localized.java index 0354893d0..516e1f586 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/Localized.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/Localized.java @@ -39,6 +39,6 @@ private static Resources upToDateResources() { } AppLog.d(TAG, "Need to adjust resources for pref locale: " + prefLocale); - return currentResources = ConfigurationWrapper.wrap(App.context).getResources(); + return currentResources = ConfigurationWrapper.localizedContext(App.context).getResources(); } } diff --git a/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.kt b/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.kt index f39a04b24..ce50c72aa 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.kt +++ b/Alkitab/src/main/java/yuku/alkitab/base/widget/TextAppearancePanel.kt @@ -433,7 +433,7 @@ class TextAppearancePanel( @Composable private fun FontRow() { val escapeColor = colorResource(R.color.escape) - val options = buildFontOptions(uiFontEntries, escapeColor) + val options = buildFontOptions(uiFontEntries, escapeColor, stringResource(R.string.get_more_fonts)) val currentDisplay = displayNameForFont(uiFontName, uiFontEntries) val currentFamily = fontFamilyForName(uiFontName, uiFontEntries) @@ -660,7 +660,11 @@ class TextAppearancePanel( val color: Color? = null, ) - private fun buildFontOptions(entries: List, escapeColor: Color): List { + private fun buildFontOptions( + entries: List, + escapeColor: Color, + getMoreFontsLabel: String, + ): List { val options = ArrayList(entries.size + 4) options += FontOption("DEFAULT", "Roboto", FontFamily.SansSerif) options += FontOption("SERIF", "Droid Serif", FontFamily.Serif) @@ -668,7 +672,7 @@ class TextAppearancePanel( for (entry in entries) { options += FontOption(entry.name, entry.name, familyForCustomFont(entry.name)) } - options += FontOption(null, App.context.getString(R.string.get_more_fonts), null, escapeColor) + options += FontOption(null, getMoreFontsLabel, null, escapeColor) return options } diff --git a/Alkitab/src/main/res/values-in/strings.xml b/Alkitab/src/main/res/values-in/strings.xml index 089658947..cae96a7f3 100644 --- a/Alkitab/src/main/res/values-in/strings.xml +++ b/Alkitab/src/main/res/values-in/strings.xml @@ -157,6 +157,7 @@ Tampilan Jenis Huruf Lainnya… + Tema warna Ukuran teks Ukuran huruf untuk ^1 Jarak antarbaris diff --git a/Alkitab/src/test/java/yuku/alkitab/base/widget/ConfigurationWrapperLocalizedContextTest.kt b/Alkitab/src/test/java/yuku/alkitab/base/widget/ConfigurationWrapperLocalizedContextTest.kt index 813a67a0b..8a9aaabbe 100644 --- a/Alkitab/src/test/java/yuku/alkitab/base/widget/ConfigurationWrapperLocalizedContextTest.kt +++ b/Alkitab/src/test/java/yuku/alkitab/base/widget/ConfigurationWrapperLocalizedContextTest.kt @@ -79,4 +79,34 @@ class ConfigurationWrapperLocalizedContextTest { assertEquals("Loading Genesis 1", localized.getString(R.string.audio_log_loading, "Genesis 1")) } + + @Test + fun `appearance actions and color theme have Indonesian translations`() { + Preferences.setString(R.string.pref_language_key, "in") + + val localized = ConfigurationWrapper.localizedContext(AfwApp.context) + + assertEquals("Dapatkan huruf lainnya…", localized.getString(R.string.get_more_fonts)) + assertEquals("Tema warna", localized.getString(R.string.text_appearance_color_theme)) + } + + @Test + fun `background strings follow language changes without changing application resources`() { + Preferences.setString(R.string.pref_language_key, "in") + + assertEquals("Gagal mengecek daftar versi.", Localized.string(R.string.version_config_updater_error_download_modify_time)) + assertEquals("Daftar versi tidak tersedia: offline", Localized.string(R.string.version_config_updater_error_modify_time_failed, "offline")) + assertEquals("^1 terunduh", Localized.text(R.string.version_download_complete).toString()) + assertEquals("Download more fonts…", AfwApp.context.getString(R.string.get_more_fonts)) + + Preferences.setString(R.string.pref_language_key, "en") + + assertEquals("Download more fonts…", Localized.string(R.string.get_more_fonts)) + + Preferences.setString(R.string.pref_language_key, "in") + + assertEquals("Tema warna", Localized.string(R.string.text_appearance_color_theme)) + assertEquals("Download more fonts…", AfwApp.context.getString(R.string.get_more_fonts)) + } + }