From 8f395d98e7be976263d2ee9b7559c2638d57b47e Mon Sep 17 00:00:00 2001 From: Mekanik Date: Sun, 6 Aug 2023 06:50:43 -0700 Subject: [PATCH] Make some error messages localizable (#9811) * Make error message of 3 exceptions localizable. * Revert unnecessary file handle exception change. --- .../java/eu/kanade/presentation/util/ExceptionFormatter.kt | 2 ++ .../java/eu/kanade/tachiyomi/data/backup/BackupManager.kt | 4 ++-- i18n/src/main/res/values/strings.xml | 2 ++ .../kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt b/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt index a69bcfcbe6..7169c9e9bd 100644 --- a/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt +++ b/app/src/main/java/eu/kanade/presentation/util/ExceptionFormatter.kt @@ -3,6 +3,7 @@ package eu.kanade.presentation.util import android.content.Context import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.network.HttpException +import eu.kanade.tachiyomi.source.online.LicensedMangaChaptersException import tachiyomi.data.source.NoResultsException import tachiyomi.domain.source.model.SourceNotInstalledException @@ -13,6 +14,7 @@ val Throwable.formattedMessage: String is NoResultsException -> return getString(R.string.no_results_found) is SourceNotInstalledException -> return getString(R.string.loader_not_implemented_error) is HttpException -> return "$message: ${getString(R.string.http_error_hint)}" + is LicensedMangaChaptersException -> return getString(R.string.licensed_manga_chapters_error) } return when (val className = this::class.simpleName) { "Exception", "IOException" -> message ?: className diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index 9c699f5353..35a9ea5987 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -106,10 +106,10 @@ class BackupManager( UniFile.fromUri(context, uri) } ) - ?: throw Exception("Couldn't create backup file") + ?: throw Exception(context.getString(R.string.create_backup_file_error)) if (!file.isFile) { - throw IllegalStateException("Failed to get handle on file") + throw IllegalStateException("Failed to get handle on a backup file") } val byteArray = parser.encodeToByteArray(BackupSerializer, backup) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 7f8c138f37..8560883add 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -495,6 +495,7 @@ Backup failed Storage permissions not granted No library entries to back up + Couldn\'t create a backup file Backup/restore may not function properly if MIUI Optimization is disabled. Restore is already in progress Restoring backup @@ -608,6 +609,7 @@ No results found Check website in WebView + Licensed - No chapters to show Local source Other Last used diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt index f9e616dcdf..c4529f4b49 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -215,7 +215,7 @@ abstract class HttpSource : CatalogueSource { chapterListParse(response) } } else { - Observable.error(Exception("Licensed - No chapters to show")) + Observable.error(LicensedMangaChaptersException()) } } @@ -404,3 +404,5 @@ abstract class HttpSource : CatalogueSource { */ override fun getFilterList() = FilterList() } + +class LicensedMangaChaptersException : Exception("Licensed - No chapters to show")