mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 18:47:51 +02:00
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:
@ -21,7 +21,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core"))
|
||||
api(project(":core"))
|
||||
api(project(":i18n"))
|
||||
|
||||
// Compose
|
||||
implementation(platform(compose.bom))
|
||||
|
@ -1,6 +1,5 @@
|
||||
package tachiyomi.presentation.core.components
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -42,12 +41,13 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import dev.icerock.moko.resources.StringResource
|
||||
import tachiyomi.core.preference.Preference
|
||||
import tachiyomi.core.preference.TriState
|
||||
import tachiyomi.core.preference.toggle
|
||||
import tachiyomi.presentation.core.components.material.padding
|
||||
import tachiyomi.presentation.core.i18n.localize
|
||||
import tachiyomi.presentation.core.theme.header
|
||||
import tachiyomi.presentation.core.util.collectAsState
|
||||
|
||||
@ -57,8 +57,8 @@ object SettingsItemsPaddings {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun HeadingItem(@StringRes labelRes: Int) {
|
||||
HeadingItem(stringResource(labelRes))
|
||||
fun HeadingItem(labelRes: StringResource) {
|
||||
HeadingItem(localize(labelRes))
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -318,7 +318,7 @@ fun TextItem(label: String, value: String, onChange: (String) -> Unit) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsChipRow(@StringRes labelRes: Int, content: @Composable FlowRowScope.() -> Unit) {
|
||||
fun SettingsChipRow(labelRes: StringResource, content: @Composable FlowRowScope.() -> Unit) {
|
||||
Column {
|
||||
HeadingItem(labelRes)
|
||||
FlowRow(
|
||||
@ -335,7 +335,7 @@ fun SettingsChipRow(@StringRes labelRes: Int, content: @Composable FlowRowScope.
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsIconGrid(@StringRes labelRes: Int, content: LazyGridScope.() -> Unit) {
|
||||
fun SettingsIconGrid(labelRes: StringResource, content: LazyGridScope.() -> Unit) {
|
||||
Column {
|
||||
HeadingItem(labelRes)
|
||||
LazyVerticalGrid(
|
||||
|
@ -0,0 +1,33 @@
|
||||
package tachiyomi.presentation.core.i18n
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import dev.icerock.moko.resources.PluralsResource
|
||||
import dev.icerock.moko.resources.StringResource
|
||||
import tachiyomi.core.i18n.localize
|
||||
import tachiyomi.core.i18n.localizePlural
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun localize(resource: StringResource): String {
|
||||
return LocalContext.current.localize(resource)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun localize(resource: StringResource, vararg args: Any): String {
|
||||
return LocalContext.current.localize(resource, *args)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun localizePlural(resource: PluralsResource, count: Int): String {
|
||||
return LocalContext.current.localizePlural(resource, count)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun localizePlural(resource: PluralsResource, count: Int, vararg args: Any): String {
|
||||
return LocalContext.current.localizePlural(resource, count, *args)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package tachiyomi.presentation.core.screens
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@ -18,31 +17,32 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.util.fastForEach
|
||||
import dev.icerock.moko.resources.StringResource
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import tachiyomi.presentation.core.components.ActionButton
|
||||
import tachiyomi.presentation.core.components.material.padding
|
||||
import tachiyomi.presentation.core.i18n.localize
|
||||
import tachiyomi.presentation.core.util.secondaryItemAlpha
|
||||
import kotlin.random.Random
|
||||
|
||||
data class EmptyScreenAction(
|
||||
@StringRes val stringResId: Int,
|
||||
val stringRes: StringResource,
|
||||
val icon: ImageVector,
|
||||
val onClick: () -> Unit,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun EmptyScreen(
|
||||
@StringRes textResource: Int,
|
||||
stringRes: StringResource,
|
||||
modifier: Modifier = Modifier,
|
||||
actions: ImmutableList<EmptyScreenAction>? = null,
|
||||
) {
|
||||
EmptyScreen(
|
||||
message = stringResource(textResource),
|
||||
message = localize(stringRes),
|
||||
modifier = modifier,
|
||||
actions = actions,
|
||||
)
|
||||
@ -89,7 +89,7 @@ fun EmptyScreen(
|
||||
actions.fastForEach {
|
||||
ActionButton(
|
||||
modifier = Modifier.weight(1f),
|
||||
title = stringResource(it.stringResId),
|
||||
title = localize(it.stringRes),
|
||||
icon = it.icon,
|
||||
onClick = it.onClick,
|
||||
)
|
||||
|
Reference in New Issue
Block a user