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
@@ -27,7 +27,6 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.graphics.ColorUtils
import androidx.core.net.toUri
@@ -85,11 +84,13 @@ import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch
import logcat.LogPriority
import tachiyomi.core.Constants
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.lang.withUIContext
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -372,7 +373,7 @@ class ReaderActivity : BaseActivity() {
onClickCropBorder = {
val enabled = viewModel.toggleCropBorders()
menuToggleToast?.cancel()
menuToggleToast = toast(if (enabled) R.string.on else R.string.off)
menuToggleToast = toast(if (enabled) MR.strings.on else MR.strings.off)
},
onClickSettings = viewModel::openSettingsDialog,
)
@@ -399,7 +400,7 @@ class ReaderActivity : BaseActivity() {
verticalAlignment = Alignment.CenterVertically,
) {
CircularProgressIndicator()
Text(stringResource(R.string.loading))
Text(localize(MR.strings.loading))
}
},
)
@@ -536,7 +537,7 @@ class ReaderActivity : BaseActivity() {
private fun shareChapter() {
assistUrl?.let {
val intent = it.toUri().toShareIntent(this, type = "text/plain")
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
startActivity(Intent.createChooser(intent, localize(MR.strings.action_share)))
}
}
@@ -683,9 +684,9 @@ class ReaderActivity : BaseActivity() {
val intent = uri.toShareIntent(
context = applicationContext,
message = getString(R.string.share_page_info, manga.title, chapter.name, page.number),
message = localize(MR.strings.share_page_info, manga.title, chapter.name, page.number),
)
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
startActivity(Intent.createChooser(intent, localize(MR.strings.action_share)))
}
/**
@@ -695,7 +696,7 @@ class ReaderActivity : BaseActivity() {
private fun onSaveImageResult(result: ReaderViewModel.SaveImageResult) {
when (result) {
is ReaderViewModel.SaveImageResult.Success -> {
toast(R.string.picture_saved)
toast(MR.strings.picture_saved)
}
is ReaderViewModel.SaveImageResult.Error -> {
logcat(LogPriority.ERROR, result.error)
@@ -710,9 +711,9 @@ class ReaderActivity : BaseActivity() {
private fun onSetAsCoverResult(result: ReaderViewModel.SetAsCoverResult) {
toast(
when (result) {
Success -> R.string.cover_updated
AddToLibraryFirst -> R.string.notification_first_add_to_library
Error -> R.string.notification_cover_update_failed
Success -> MR.strings.cover_updated
AddToLibraryFirst -> MR.strings.notification_first_add_to_library
Error -> MR.strings.notification_cover_update_failed
},
)
}
@@ -13,6 +13,7 @@ import androidx.core.graphics.withTranslation
import androidx.core.view.isVisible
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.ui.reader.viewer.navigation.DisabledNavigation
import tachiyomi.core.i18n.localize
import kotlin.math.abs
class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet) : View(context, attributeSet) {
@@ -79,8 +80,8 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
// Calculate center of rect height on screen
val y = height * (abs(rect.top - rect.bottom) / 2)
drawText(context.getString(region.type.nameRes), x, y, textBorderPaint)
drawText(context.getString(region.type.nameRes), x, y, textPaint)
drawText(context.localize(region.type.nameRes), x, y, textBorderPaint)
drawText(context.localize(region.type.nameRes), x, y, textPaint)
}
}
}
@@ -15,6 +15,8 @@ import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.getBitmapOrNull
import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notify
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
/**
* Class used to show BigPictureStyle notifications
@@ -56,8 +58,8 @@ class SaveImageNotifier(private val context: Context) {
fun onError(error: String?) {
// Create notification
with(notificationBuilder) {
setContentTitle(context.getString(R.string.download_notifier_title_error))
setContentText(error ?: context.getString(R.string.unknown_error))
setContentTitle(context.localize(MR.strings.download_notifier_title_error))
setContentText(error ?: context.localize(MR.strings.unknown_error))
setSmallIcon(android.R.drawable.ic_menu_report_image)
}
updateNotification()
@@ -65,7 +67,7 @@ class SaveImageNotifier(private val context: Context) {
private fun showCompleteNotification(uri: Uri, image: Bitmap?) {
with(notificationBuilder) {
setContentTitle(context.getString(R.string.picture_saved))
setContentTitle(context.localize(MR.strings.picture_saved))
setSmallIcon(R.drawable.ic_photo_24dp)
image?.let { setStyle(NotificationCompat.BigPictureStyle().bigPicture(it)) }
setLargeIcon(image)
@@ -78,13 +80,13 @@ class SaveImageNotifier(private val context: Context) {
// Share action
addAction(
R.drawable.ic_share_24dp,
context.getString(R.string.action_share),
context.localize(MR.strings.action_share),
NotificationReceiver.shareImagePendingBroadcast(context, uri.path!!, notificationId),
)
// Delete action
addAction(
R.drawable.ic_delete_24dp,
context.getString(R.string.action_delete),
context.localize(MR.strings.action_delete),
NotificationReceiver.deleteImagePendingBroadcast(context, uri.path!!, notificationId),
)
@@ -2,16 +2,17 @@ package eu.kanade.tachiyomi.ui.reader.loader
import android.content.Context
import com.github.junrar.exception.UnsupportedRarV5Exception
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.lang.withIOContext
import tachiyomi.core.util.system.logcat
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.model.StubSource
import tachiyomi.i18n.MR
import tachiyomi.source.local.LocalSource
import tachiyomi.source.local.io.Format
@@ -46,7 +47,7 @@ class ChapterLoader(
.onEach { it.chapter = chapter }
if (pages.isEmpty()) {
throw Exception(context.getString(R.string.page_list_empty_error))
throw Exception(context.localize(MR.strings.page_list_empty_error))
}
// If the chapter is partially read, set the starting page to the last the user read
@@ -91,14 +92,14 @@ class ChapterLoader(
is Format.Rar -> try {
RarPageLoader(format.file)
} catch (e: UnsupportedRarV5Exception) {
error(context.getString(R.string.loader_rar5_error))
error(context.localize(MR.strings.loader_rar5_error))
}
is Format.Epub -> EpubPageLoader(format.file)
}
}
source is HttpSource -> HttpPageLoader(chapter, source)
source is StubSource -> error(context.getString(R.string.source_not_installed, source.toString()))
else -> error(context.getString(R.string.loader_not_implemented_error))
source is StubSource -> error(context.localize(MR.strings.source_not_installed, source.toString()))
else -> error(context.localize(MR.strings.loader_not_implemented_error))
}
}
}
@@ -2,54 +2,55 @@ package eu.kanade.tachiyomi.ui.reader.setting
import android.content.pm.ActivityInfo
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import dev.icerock.moko.resources.StringResource
import eu.kanade.tachiyomi.R
import tachiyomi.i18n.MR
enum class ReaderOrientation(
val flag: Int,
@StringRes val stringRes: Int,
val stringRes: StringResource,
@DrawableRes val iconRes: Int,
val flagValue: Int,
) {
DEFAULT(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
R.string.label_default,
MR.strings.label_default,
R.drawable.ic_screen_rotation_24dp,
0x00000000,
),
FREE(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
R.string.rotation_free,
MR.strings.rotation_free,
R.drawable.ic_screen_rotation_24dp,
0x00000008,
),
PORTRAIT(
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,
R.string.rotation_portrait,
MR.strings.rotation_portrait,
R.drawable.ic_stay_current_portrait_24dp,
0x00000010,
),
LANDSCAPE(
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
R.string.rotation_landscape,
MR.strings.rotation_landscape,
R.drawable.ic_stay_current_landscape_24dp,
0x00000018,
),
LOCKED_PORTRAIT(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
R.string.rotation_force_portrait,
MR.strings.rotation_force_portrait,
R.drawable.ic_screen_lock_portrait_24dp,
0x00000020,
),
LOCKED_LANDSCAPE(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
R.string.rotation_force_landscape,
MR.strings.rotation_force_landscape,
R.drawable.ic_screen_lock_landscape_24dp,
0x00000028,
),
REVERSE_PORTRAIT(
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
R.string.rotation_reverse_portrait,
MR.strings.rotation_reverse_portrait,
R.drawable.ic_stay_current_portrait_24dp,
0x00000030,
),
@@ -1,9 +1,9 @@
package eu.kanade.tachiyomi.ui.reader.setting
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import dev.icerock.moko.resources.StringResource
import tachiyomi.core.preference.PreferenceStore
import tachiyomi.core.preference.getEnum
import tachiyomi.i18n.MR
class ReaderPreferences(
private val preferenceStore: PreferenceStore,
@@ -129,14 +129,14 @@ class ReaderPreferences(
// endregion
enum class TappingInvertMode(
@StringRes val titleResId: Int,
val titleRes: StringResource,
val shouldInvertHorizontal: Boolean = false,
val shouldInvertVertical: Boolean = false,
) {
NONE(R.string.tapping_inverted_none),
HORIZONTAL(R.string.tapping_inverted_horizontal, shouldInvertHorizontal = true),
VERTICAL(R.string.tapping_inverted_vertical, shouldInvertVertical = true),
BOTH(R.string.tapping_inverted_both, shouldInvertHorizontal = true, shouldInvertVertical = true),
NONE(MR.strings.tapping_inverted_none),
HORIZONTAL(MR.strings.tapping_inverted_horizontal, shouldInvertHorizontal = true),
VERTICAL(MR.strings.tapping_inverted_vertical, shouldInvertVertical = true),
BOTH(MR.strings.tapping_inverted_both, shouldInvertHorizontal = true, shouldInvertVertical = true),
}
enum class ReaderHideThreshold(val threshold: Int) {
@@ -151,28 +151,28 @@ class ReaderPreferences(
const val WEBTOON_PADDING_MAX = 25
val TapZones = listOf(
R.string.label_default,
R.string.l_nav,
R.string.kindlish_nav,
R.string.edge_nav,
R.string.right_and_left_nav,
R.string.disabled_nav,
MR.strings.label_default,
MR.strings.l_nav,
MR.strings.kindlish_nav,
MR.strings.edge_nav,
MR.strings.right_and_left_nav,
MR.strings.disabled_nav,
)
val ImageScaleType = listOf(
R.string.scale_type_fit_screen,
R.string.scale_type_stretch,
R.string.scale_type_fit_width,
R.string.scale_type_fit_height,
R.string.scale_type_original_size,
R.string.scale_type_smart_fit,
MR.strings.scale_type_fit_screen,
MR.strings.scale_type_stretch,
MR.strings.scale_type_fit_width,
MR.strings.scale_type_fit_height,
MR.strings.scale_type_original_size,
MR.strings.scale_type_smart_fit,
)
val ZoomStart = listOf(
R.string.zoom_start_automatic,
R.string.zoom_start_left,
R.string.zoom_start_right,
R.string.zoom_start_center,
MR.strings.zoom_start_automatic,
MR.strings.zoom_start_left,
MR.strings.zoom_start_right,
MR.strings.zoom_start_center,
)
}
}
@@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.reader.setting
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import dev.icerock.moko.resources.StringResource
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.Viewer
@@ -9,45 +9,46 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
import tachiyomi.i18n.MR
enum class ReadingMode(
@StringRes val stringRes: Int,
val stringRes: StringResource,
@DrawableRes val iconRes: Int,
val flagValue: Int,
val direction: Direction? = null,
val type: ViewerType? = null,
) {
DEFAULT(R.string.label_default, R.drawable.ic_reader_default_24dp, 0x00000000),
DEFAULT(MR.strings.label_default, R.drawable.ic_reader_default_24dp, 0x00000000),
LEFT_TO_RIGHT(
R.string.left_to_right_viewer,
MR.strings.left_to_right_viewer,
R.drawable.ic_reader_ltr_24dp,
0x00000001,
Direction.Horizontal,
ViewerType.Pager,
),
RIGHT_TO_LEFT(
R.string.right_to_left_viewer,
MR.strings.right_to_left_viewer,
R.drawable.ic_reader_rtl_24dp,
0x00000002,
Direction.Horizontal,
ViewerType.Pager,
),
VERTICAL(
R.string.vertical_viewer,
MR.strings.vertical_viewer,
R.drawable.ic_reader_vertical_24dp,
0x00000003,
Direction.Vertical,
ViewerType.Pager,
),
WEBTOON(
R.string.webtoon_viewer,
MR.strings.webtoon_viewer,
R.drawable.ic_reader_webtoon_24dp,
0x00000004,
Direction.Vertical,
ViewerType.Webtoon,
),
CONTINUOUS_VERTICAL(
R.string.vertical_plus_viewer,
MR.strings.vertical_plus_viewer,
R.drawable.ic_reader_continuous_vertical_24dp,
0x00000005,
Direction.Vertical,
@@ -3,19 +3,19 @@ package eu.kanade.tachiyomi.ui.reader.viewer
import android.graphics.Color
import android.graphics.PointF
import android.graphics.RectF
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import dev.icerock.moko.resources.StringResource
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.lang.invert
import tachiyomi.i18n.MR
abstract class ViewerNavigation {
sealed class NavigationRegion(@StringRes val nameRes: Int, val color: Int) {
data object MENU : NavigationRegion(R.string.action_menu, Color.argb(0xCC, 0x95, 0x81, 0x8D))
data object PREV : NavigationRegion(R.string.nav_zone_prev, Color.argb(0xCC, 0xFF, 0x77, 0x33))
data object NEXT : NavigationRegion(R.string.nav_zone_next, Color.argb(0xCC, 0x84, 0xE2, 0x96))
data object LEFT : NavigationRegion(R.string.nav_zone_left, Color.argb(0xCC, 0x7D, 0x11, 0x28))
data object RIGHT : NavigationRegion(R.string.nav_zone_right, Color.argb(0xCC, 0xA6, 0xCF, 0xD5))
sealed class NavigationRegion(val nameRes: StringResource, val color: Int) {
data object MENU : NavigationRegion(MR.strings.action_menu, Color.argb(0xCC, 0x95, 0x81, 0x8D))
data object PREV : NavigationRegion(MR.strings.nav_zone_prev, Color.argb(0xCC, 0xFF, 0x77, 0x33))
data object NEXT : NavigationRegion(MR.strings.nav_zone_next, Color.argb(0xCC, 0x84, 0xE2, 0x96))
data object LEFT : NavigationRegion(MR.strings.nav_zone_left, Color.argb(0xCC, 0x7D, 0x11, 0x28))
data object RIGHT : NavigationRegion(MR.strings.nav_zone_right, Color.argb(0xCC, 0xA6, 0xCF, 0xD5))
}
data class Region(
@@ -10,7 +10,6 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatTextView
import com.google.android.material.progressindicator.CircularProgressIndicator
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderButton
@@ -21,6 +20,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
/**
* View of the ViewPager that contains a chapter transition.
@@ -104,7 +105,7 @@ class PagerTransitionHolder(
val textView = AppCompatTextView(context).apply {
wrapContent()
setText(R.string.transition_pages_loading)
text = context.localize(MR.strings.transition_pages_loading)
}
pagesContainer.addView(progress)
@@ -117,13 +118,13 @@ class PagerTransitionHolder(
private fun setError(error: Throwable) {
val textView = AppCompatTextView(context).apply {
wrapContent()
text = context.getString(R.string.transition_pages_error, error.message)
text = context.localize(MR.strings.transition_pages_error, error.message ?: "")
}
val retryBtn = ReaderButton(context).apply {
viewer = this@PagerTransitionHolder.viewer
wrapContent()
setText(R.string.action_retry)
text = context.localize(MR.strings.action_retry)
setOnClickListener {
val toChapter = transition.to
if (toChapter != null) {
@@ -9,7 +9,6 @@ import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isNotEmpty
import androidx.core.view.isVisible
import com.google.android.material.progressindicator.CircularProgressIndicator
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderTransitionView
@@ -18,6 +17,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
/**
* Holder of the webtoon viewer that contains a chapter transition.
@@ -106,7 +107,7 @@ class WebtoonTransitionHolder(
val textView = AppCompatTextView(context).apply {
wrapContent()
setText(R.string.transition_pages_loading)
text = context.localize(MR.strings.transition_pages_loading)
}
pagesContainer.addView(progress)
@@ -119,12 +120,12 @@ class WebtoonTransitionHolder(
private fun setError(error: Throwable, transition: ChapterTransition) {
val textView = AppCompatTextView(context).apply {
wrapContent()
text = context.getString(R.string.transition_pages_error, error.message)
text = context.localize(MR.strings.transition_pages_error, error.message ?: "")
}
val retryBtn = AppCompatButton(context).apply {
wrapContent()
setText(R.string.action_retry)
text = context.localize(MR.strings.action_retry)
setOnClickListener {
val toChapter = transition.to
if (toChapter != null) {