Migrate to multiplatform string resources (#10147)

* Migrate to multiplatform string resources

* Move plurals translations into separate files

* Fix lint check on generated files
This commit is contained in:
arkon
2023-11-18 13:54:56 -05:00
committed by GitHub
parent c39ae21f4a
commit 46e734fc8e
340 changed files with 5741 additions and 6292 deletions
@@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.data.download
import android.content.Context
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.Page
@@ -15,6 +14,7 @@ import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.runBlocking
import logcat.LogPriority
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.category.interactor.GetCategories
@@ -22,6 +22,7 @@ import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -158,7 +159,7 @@ class DownloadManager(
.filter { "image" in it.type.orEmpty() }
if (files.isEmpty()) {
throw Exception(context.getString(R.string.page_list_empty_error))
throw Exception(context.localize(MR.strings.page_list_empty_error))
}
return files.sortedBy { it.name }
@@ -14,6 +14,8 @@ import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notify
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
import uy.kohesive.injekt.injectLazy
import java.util.regex.Pattern
@@ -78,13 +80,13 @@ internal class DownloadNotifier(private val context: Context) {
// Pause action
addAction(
R.drawable.ic_pause_24dp,
context.getString(R.string.action_pause),
context.localize(MR.strings.action_pause),
NotificationReceiver.pauseDownloadsPendingBroadcast(context),
)
}
val downloadingProgressText = context.getString(
R.string.chapter_downloading_progress,
val downloadingProgressText = context.localize(
MR.strings.chapter_downloading_progress,
download.downloadedImages,
download.pages!!.size,
)
@@ -115,8 +117,8 @@ internal class DownloadNotifier(private val context: Context) {
*/
fun onPaused() {
with(progressNotificationBuilder) {
setContentTitle(context.getString(R.string.chapter_paused))
setContentText(context.getString(R.string.download_notifier_download_paused))
setContentTitle(context.localize(MR.strings.chapter_paused))
setContentText(context.localize(MR.strings.download_notifier_download_paused))
setSmallIcon(R.drawable.ic_pause_24dp)
setProgress(0, 0, false)
setOngoing(false)
@@ -126,13 +128,13 @@ internal class DownloadNotifier(private val context: Context) {
// Resume action
addAction(
R.drawable.ic_play_arrow_24dp,
context.getString(R.string.action_resume),
context.localize(MR.strings.action_resume),
NotificationReceiver.resumeDownloadsPendingBroadcast(context),
)
// Clear action
addAction(
R.drawable.ic_close_24dp,
context.getString(R.string.action_cancel_all),
context.localize(MR.strings.action_cancel_all),
NotificationReceiver.clearDownloadsPendingBroadcast(context),
)
@@ -162,7 +164,7 @@ internal class DownloadNotifier(private val context: Context) {
*/
fun onWarning(reason: String, timeout: Long? = null, contentIntent: PendingIntent? = null) {
with(errorNotificationBuilder) {
setContentTitle(context.getString(R.string.download_notifier_downloader_title))
setContentTitle(context.localize(MR.strings.download_notifier_downloader_title))
setStyle(NotificationCompat.BigTextStyle().bigText(reason))
setSmallIcon(R.drawable.ic_warning_white_24dp)
setAutoCancel(true)
@@ -190,9 +192,9 @@ internal class DownloadNotifier(private val context: Context) {
// Create notification
with(errorNotificationBuilder) {
setContentTitle(
mangaTitle?.plus(": $chapter") ?: context.getString(R.string.download_notifier_downloader_title),
mangaTitle?.plus(": $chapter") ?: context.localize(MR.strings.download_notifier_downloader_title),
)
setContentText(error ?: context.getString(R.string.download_notifier_unknown_error))
setContentText(error ?: context.localize(MR.strings.download_notifier_unknown_error))
setSmallIcon(R.drawable.ic_warning_white_24dp)
clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
@@ -3,17 +3,18 @@ package eu.kanade.tachiyomi.data.download
import android.content.Context
import androidx.core.net.toUri
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.util.storage.DiskUtil
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import logcat.LogPriority
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -58,7 +59,7 @@ class DownloadProvider(
.createDirectory(getMangaDirName(mangaTitle))
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Invalid download directory" }
throw Exception(context.getString(R.string.invalid_location, downloadsDir))
throw Exception(context.localize(MR.strings.invalid_location, downloadsDir))
}
}
@@ -6,9 +6,8 @@ import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.os.PowerManager
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import eu.kanade.tachiyomi.R
import dev.icerock.moko.resources.StringResource
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.util.system.acquireWakeLock
import eu.kanade.tachiyomi.util.system.isConnectedToWifi
@@ -27,9 +26,11 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import logcat.LogPriority
import ru.beryukhov.reactivenetwork.ReactiveNetwork
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.lang.withUIContext
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.i18n.MR
import uy.kohesive.injekt.injectLazy
/**
@@ -111,8 +112,8 @@ class DownloadService : Service() {
return null
}
private fun downloaderStop(@StringRes string: Int) {
downloadManager.downloaderStop(getString(string))
private fun downloaderStop(string: StringResource) {
downloadManager.downloaderStop(localize(string))
}
private fun listenNetworkChanges() {
@@ -122,20 +123,20 @@ class DownloadService : Service() {
withUIContext {
if (isOnline()) {
if (downloadPreferences.downloadOnlyOverWifi().get() && !isConnectedToWifi()) {
downloaderStop(R.string.download_notifier_text_only_wifi)
downloaderStop(MR.strings.download_notifier_text_only_wifi)
} else {
val started = downloadManager.downloaderStart()
if (!started) stopSelf()
}
} else {
downloaderStop(R.string.download_notifier_no_network)
downloaderStop(MR.strings.download_notifier_no_network)
}
}
}
.catch { error ->
withUIContext {
logcat(LogPriority.ERROR, error)
toast(R.string.download_queue_error)
toast(MR.strings.download_queue_error)
stopSelf()
}
}
@@ -144,7 +145,7 @@ class DownloadService : Service() {
private fun getPlaceholderNotification(): Notification {
return notificationBuilder(Notifications.CHANNEL_DOWNLOADER_PROGRESS) {
setContentTitle(getString(R.string.download_notifier_downloader_title))
setContentTitle(localize(MR.strings.download_notifier_downloader_title))
}.build()
}
}
@@ -4,7 +4,6 @@ import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.domain.chapter.model.toSChapter
import eu.kanade.domain.manga.model.getComicInfo
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
@@ -41,6 +40,7 @@ import kotlinx.coroutines.supervisorScope
import logcat.LogPriority
import nl.adaptivity.xmlutil.serialization.XML
import okhttp3.Response
import tachiyomi.core.i18n.localize
import tachiyomi.core.metadata.comicinfo.COMIC_INFO_FILE
import tachiyomi.core.metadata.comicinfo.ComicInfo
import tachiyomi.core.util.lang.launchIO
@@ -54,6 +54,7 @@ import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.BufferedOutputStream
@@ -302,7 +303,7 @@ class Downloader(
) {
withUIContext {
notifier.onWarning(
context.getString(R.string.download_queue_size_warning),
context.localize(MR.strings.download_queue_size_warning),
WARNING_NOTIF_TIMEOUT_MS,
NotificationHandler.openUrl(context, LibraryUpdateNotifier.HELP_WARNING_URL),
)
@@ -325,7 +326,7 @@ class Downloader(
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
download.status = Download.State.ERROR
notifier.onError(
context.getString(R.string.download_insufficient_space),
context.localize(MR.strings.download_insufficient_space),
download.chapter.name,
download.manga.title,
)
@@ -342,7 +343,7 @@ class Downloader(
val pages = download.source.getPageList(download.chapter.toSChapter())
if (pages.isEmpty()) {
throw Exception(context.getString(R.string.page_list_empty_error))
throw Exception(context.localize(MR.strings.page_list_empty_error))
}
// Don't trust index from source
val reIndexedPages = pages.mapIndexed { index, page -> Page(index, page.url, page.imageUrl, page.uri) }
@@ -546,7 +547,7 @@ class Downloader(
try {
val filenamePrefix = String.format("%03d", page.number)
val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) }
?: error(context.getString(R.string.download_notifier_split_page_not_found, page.number))
?: error(context.localize(MR.strings.download_notifier_split_page_not_found, page.number))
// If the original page was previously split, then skip
if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return