From 179cb8eb50951955611036f4140d6128e6fce781 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) --- .../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 90099cbba..a0f2c0056 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -32,8 +32,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? { @@ -192,12 +190,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) @@ -242,7 +238,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 { @@ -254,7 +250,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 { @@ -268,7 +264,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)) } } @@ -311,9 +307,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 054d8adb7..7395d56bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -519,6 +519,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.