From 3cc61bc3b836a9c10641f16dc93301b8e74ea254 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 24 May 2021 16:50:07 -0400 Subject: [PATCH] Make some strings in LocalSource translatable (closes #5178) (cherry picked from commit 179cb8eb50951955611036f4140d6128e6fce781) --- .../eu/kanade/tachiyomi/source/LocalSource.kt | 29 ++++++++++--------- app/src/main/res/values/strings.xml | 4 +++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 165b0c0ce..1f7683811 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -38,8 +38,6 @@ class LocalSource(private val context: Context) : CatalogueSource { private const val COVER_NAME = "cover.jpg" private val SUPPORTED_ARCHIVE_TYPES = setOf("zip", "rar", "cbr", "cbz", "epub") - private val POPULAR_FILTERS = FilterList(OrderBy()) - private val LATEST_FILTERS = FilterList(OrderBy().apply { state = Filter.Sort.Selection(1, false) }) private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS) fun updateCover(context: Context, manga: SManga, input: InputStream): File? { @@ -248,12 +246,10 @@ class LocalSource(private val context: Context) : CatalogueSource { ChapterRecognition.parseChapterNumber(this, manga) } } - .sortedWith( - Comparator { c1, c2 -> - val c = c2.chapter_number.compareTo(c1.chapter_number) - if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c - } - ) + .sortedWith { c1, c2 -> + val c = c2.chapter_number.compareTo(c1.chapter_number) + if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c + } .toList() return Observable.just(chapters) @@ -298,7 +294,7 @@ class LocalSource(private val context: Context) : CatalogueSource { } private fun isSupportedFile(extension: String): Boolean { - return extension.toLowerCase() in SUPPORTED_ARCHIVE_TYPES + return extension.toLowerCase(Locale.ROOT) in SUPPORTED_ARCHIVE_TYPES } fun getFormat(chapter: SChapter): Format { @@ -310,7 +306,7 @@ class LocalSource(private val context: Context) : CatalogueSource { return getFormat(chapFile) } - throw Exception("Chapter not found") + throw Exception(context.getString(R.string.chapter_not_found)) } private fun getFormat(file: File): Format { @@ -324,7 +320,7 @@ class LocalSource(private val context: Context) : CatalogueSource { } else if (extension.equals("epub", true)) { Format.Epub(file) } else { - throw Exception("Invalid chapter format") + throw Exception(context.getString(R.string.local_invalid_format)) } } @@ -367,9 +363,16 @@ class LocalSource(private val context: Context) : CatalogueSource { } } - private class OrderBy : Filter.Sort("Order by", arrayOf("Title", "Date"), Selection(0, true)) + override fun getFilterList() = POPULAR_FILTERS - override fun getFilterList() = FilterList(OrderBy()) + private val POPULAR_FILTERS = FilterList(OrderBy(context)) + private val LATEST_FILTERS = FilterList(OrderBy(context).apply { state = Filter.Sort.Selection(1, false) }) + + private class OrderBy(context: Context) : Filter.Sort( + context.getString(R.string.local_filter_order_by), + arrayOf(context.getString(R.string.title), context.getString(R.string.date)), + Selection(0, true) + ) sealed class Format { data class Directory(val file: File) : Format() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 16584b433..e6a0bf0b2 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -520,6 +520,10 @@ Browse Local source guide You have no pinned sources + Chapter not found + Invalid chapter format + Order by + Date This manga has been removed from the database.