Skip to content

Commit

Permalink
added localization support
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 17, 2024
1 parent bd429a1 commit 3b2eb19
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.datlag.aniflow.ui.custom

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.SharedRes
import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@Composable
fun ErrorContent(
modifier: Modifier = Modifier,
horizontal: Boolean = false,
painter: ImageResource = SharedRes.images.sad_emote,
title: StringResource = SharedRes.strings.oh_noo,
text: StringResource = SharedRes.strings.error_try_again
) {
if (horizontal) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally)
) {
Image(
painter = painterResource(painter),
contentDescription = null,
)
Column(
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.Start
) {
Text(
text = stringResource(title),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
Text(text = stringResource(text))
}
}
} else {
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(painter),
contentDescription = null,
)
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = stringResource(title),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = stringResource(text)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.MenuBook
import androidx.compose.material.icons.rounded.ClearAll
import androidx.compose.material.icons.rounded.FilterList
import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.material.icons.rounded.SwapVert
Expand Down Expand Up @@ -37,6 +38,7 @@ import dev.datlag.aniflow.anilist.ListRepository
import dev.datlag.aniflow.anilist.type.MediaListStatus
import dev.datlag.aniflow.anilist.type.MediaType
import dev.datlag.aniflow.common.*
import dev.datlag.aniflow.ui.custom.ErrorContent
import dev.datlag.aniflow.ui.navigation.screen.component.HidingNavigationBar
import dev.datlag.aniflow.ui.navigation.screen.component.NavigationBarState
import dev.datlag.aniflow.ui.navigation.screen.favorites.component.ListCard
Expand Down Expand Up @@ -102,7 +104,7 @@ fun FavoritesScreen(component: FavoritesComponent) {
selection = OptionSelection.Single(
options = options.map {
Option(
icon = IconSource(it.icon(Icons.Rounded.FilterList)),
icon = IconSource(it.icon(Icons.Rounded.ClearAll)),
titleText = stringResource(it.stringRes(type, SharedRes.strings.all)),
selected = status == it
)
Expand Down Expand Up @@ -161,7 +163,9 @@ fun FavoritesScreen(component: FavoritesComponent) {
}
}
is ListRepository.State.Error -> {
Text(text = "Error")
ErrorContent(
modifier = Modifier.fillMaxSize()
)
}
is ListRepository.State.Success -> {
val titleLanguage by component.titleLanguage.collectAsStateWithLifecycle(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CameraEnhance
import androidx.compose.material.icons.rounded.GetApp
import androidx.compose.material.icons.rounded.Troubleshoot
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
Expand All @@ -24,6 +25,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.IconSource
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.option.OptionDialog
import com.maxkeppeler.sheets.option.models.DisplayMode
Expand Down Expand Up @@ -128,15 +130,10 @@ fun HomeScreen(component: HomeComponent) {
config = OptionConfig(
mode = DisplayMode.LIST
),
header = Header.Custom { padding ->
Text(
modifier = Modifier.padding(padding.merge(PaddingValues(16.dp))).fillMaxWidth(),
text = "Matching Anime",
textAlign = TextAlign.Center,
fontWeight = FontWeight.SemiBold,
style = MaterialTheme.typography.titleLarge
)
},
header = Header.Default(
icon = IconSource(Icons.Rounded.Troubleshoot),
title = stringResource(SharedRes.strings.matching_anime)
),
selection = OptionSelection.Single(
options = results.map {
Option(
Expand All @@ -161,7 +158,7 @@ fun HomeScreen(component: HomeComponent) {
)
},
text = {
Text(text = "Scan")
Text(text = stringResource(SharedRes.strings.scan))
}
)
}
Expand Down Expand Up @@ -208,15 +205,15 @@ fun HomeScreen(component: HomeComponent) {
}
item {
DefaultOverview(
title = "Trending",
title = stringResource(SharedRes.strings.trending),
flow = component.trending,
titleLanguage = titleLanguage,
onMediumClick = component::details
)
}
item {
DefaultOverview(
title = "Popular",
title = stringResource(SharedRes.strings.popular),
flow = component.popularNow,
titleLanguage = titleLanguage,
onMediumClick = component::details
Expand All @@ -225,7 +222,7 @@ fun HomeScreen(component: HomeComponent) {
if (!isManga) {
item {
DefaultOverview(
title = "Popular Next",
title = stringResource(SharedRes.strings.upcoming),
flow = component.popularNext,
titleLanguage = titleLanguage,
onMediumClick = component::details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.state.CollectionState
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.ui.custom.ErrorContent
import dev.datlag.aniflow.ui.navigation.screen.home.component.default.MediumCard
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -72,7 +73,10 @@ fun DefaultOverview(
}
}
is CollectionState.Error -> {
Text("Could not load $title")
ErrorContent(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
horizontal = true
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.anilist.AiringTodayRepository
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.other.StateSaver
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.ui.custom.ErrorContent
import dev.datlag.aniflow.ui.navigation.screen.home.component.airing.AiringCard
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.coroutines.flow.Flow

@OptIn(ExperimentalFoundationApi::class)
Expand All @@ -44,7 +47,7 @@ fun ScheduleOverview(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Schedule",
text = stringResource(SharedRes.strings.schedule),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold
)
Expand Down Expand Up @@ -81,7 +84,10 @@ fun ScheduleOverview(
}
}
is AiringTodayRepository.State.Error -> {
Text("Could not load Schedule")
ErrorContent(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
horizontal = true
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun RatingSection(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = stringResource(SharedRes.strings.popular),
text = stringResource(SharedRes.strings.popularity),
style = MaterialTheme.typography.labelSmall
)
Text(
Expand Down
10 changes: 9 additions & 1 deletion composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="media_status_hiatus">Paused</string>
<string name="unknown">Unknown</string>
<string name="rated">Rated</string>
<string name="popular">Popular</string>
<string name="popularity">Popular</string>
<string name="score">Score</string>
<string name="translate">Translate</string>
<string name="description">Description</string>
Expand Down Expand Up @@ -92,4 +92,12 @@
<string name="minus_one">-1</string>
<string name="filter">Filter</string>
<string name="all">All</string>
<string name="oh_noo">Oh noo...</string>
<string name="error_try_again">An error occurred, please try again later QwQ</string>
<string name="matching_anime">Matching Anime</string>
<string name="scan">Scan</string>
<string name="schedule">Schedule</string>
<string name="trending">Trending</string>
<string name="popular">Popular</string>
<string name="upcoming">Upcoming</string>
</resources>
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/moko-resources/de-DE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="media_status_hiatus">Pausiert</string>
<string name="unknown">Unbekannt</string>
<string name="rated">Bewertet</string>
<string name="popular">Popularität</string>
<string name="popularity">Popularität</string>
<string name="score">Wertung</string>
<string name="translate">Übersetzen</string>
<string name="description">Beschreibung</string>
Expand Down
16 changes: 16 additions & 0 deletions composeApp/src/commonMain/moko-resources/images/sad_emote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3b2eb19

Please sign in to comment.