Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(language): đa ngôn ngữ ở màn học #87

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.pwhs.quickmem.R
import com.pwhs.quickmem.ui.theme.QuickMemTheme

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -30,7 +32,7 @@ fun StudyTopAppBar(
modifier = modifier,
title = {
Text(
text = if (isEnOfSet) "Congratulations!" else "Card $currentCardIndex of $totalCards",
text = if (isEnOfSet) stringResource(R.string.txt_congratulations) else "Card $currentCardIndex of $totalCards",
style = typography.titleMedium.copy(
fontWeight = FontWeight.Bold,
)
Expand All @@ -42,7 +44,7 @@ fun StudyTopAppBar(
) {
Icon(
imageVector = Default.Clear,
contentDescription = "Back"
contentDescription = stringResource(R.string.txt_back)
)
}
},
Expand All @@ -53,7 +55,7 @@ fun StudyTopAppBar(
) {
Icon(
imageVector = Default.RestartAlt,
contentDescription = "Restart"
contentDescription = stringResource(R.string.txt_restart)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -41,6 +42,7 @@ import com.msusman.compose.cardstack.Duration
import com.msusman.compose.cardstack.SwipeDirection
import com.msusman.compose.cardstack.SwipeMethod
import com.msusman.compose.cardstack.rememberStackState
import com.pwhs.quickmem.R
import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel
import com.pwhs.quickmem.presentation.app.study_set.component.StudyCardBottomSheet
import com.pwhs.quickmem.presentation.app.study_set.studies.flip.component.FlipFlashCardButton
Expand Down Expand Up @@ -165,9 +167,9 @@ fun FlipFlashCard(
val knownColor = Color(0xff18ae79)
val stackState = rememberStackState()
val suggestedText = listOf(
"Tap the card to flip",
"Swipe left to mark as known",
"Swipe right to mark as still learning"
stringResource(R.string.txt_tap_the_card_to_flip),
stringResource(R.string.txt_swipe_left_to_mark_as_known),
stringResource(R.string.txt_swipe_right_to_mark_as_still_learning)
)
var currentTextIndex by remember { mutableIntStateOf(0) }
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -379,7 +381,7 @@ fun FlipFlashCard(
showHintBottomSheet = true
},
studySetColor = studySetColor,
title = "Show Hint"
title = stringResource(R.string.txt_show_hint)
)
Comment on lines 383 to 385
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Thêm kiểm tra null safety cho hint

Hiện tại chỉ kiểm tra isNotEmpty() mà chưa kiểm tra null, có thể gây ra NullPointerException.

-if (flashCards.getOrNull(currentCardIndex)?.hint?.isNotEmpty() == true && !isFlipCard) {
+if (!flashCards.getOrNull(currentCardIndex)?.hint.isNullOrEmpty() && !isFlipCard) {

Committable suggestion skipped: line range outside the PR's diff.

}

Expand All @@ -389,13 +391,13 @@ fun FlipFlashCard(
showExplanationBottomSheet = true
},
studySetColor = studySetColor,
title = "Show Explanation"
title = stringResource(R.string.txt_show_explanation)
)
}
}
FlipFlashCardIconButton(
knownColor = knownColor,
contentDescription = "Swipe Right",
contentDescription = stringResource(R.string.txt_swipe_right),
imageVector = Icons.AutoMirrored.Filled.ArrowForwardIos,
onClick = {
stackState.swipe(Direction.Right)
Expand All @@ -414,7 +416,7 @@ fun FlipFlashCard(

StudyCardBottomSheet(
modifier = Modifier,
title = "Hint",
title = stringResource(R.string.txt_hint),
contentText = flashCards.getOrNull(currentCardIndex)?.hint ?: "",
onDismiss = {
showHintBottomSheet = false
Expand All @@ -425,7 +427,7 @@ fun FlipFlashCard(

StudyCardBottomSheet(
modifier = Modifier,
title = "Explanation",
title = stringResource(R.string.txt_explanation),
contentText = flashCards.getOrNull(currentCardIndex)?.explanation ?: "",
onDismiss = {
showExplanationBottomSheet = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -79,7 +80,7 @@ fun FlipFlashCardFinish(
) {
item {
Text(
text = "You're doing great!",
text = stringResource(R.string.txt_you_re_doing_great_keep_it_up),
style = MaterialTheme.typography.titleLarge.copy(
fontWeight = FontWeight.Bold
)
Expand All @@ -98,7 +99,7 @@ fun FlipFlashCardFinish(

item {
Text(
text = "Keep focusing on your study set to master it!",
text = stringResource(R.string.txt_keep_focusing_on_your_study_set_to_master_it),
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
),
Expand Down Expand Up @@ -131,7 +132,7 @@ fun FlipFlashCardFinish(
contentScale = ContentScale.Crop
)
Text(
text = "Flashcards learned",
text = stringResource(R.string.txt_flashcards_learned),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 18.sp
),
Expand Down Expand Up @@ -185,7 +186,7 @@ fun FlipFlashCardFinish(
contentDescription = "Time",
)
Text(
text = "Learning Time",
text = stringResource(R.string.txt_learning_time),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 18.sp
),
Expand Down Expand Up @@ -229,7 +230,10 @@ fun FlipFlashCardFinish(
border = BorderStroke(1.dp, studySetColor)
) {
Text(
text = "Keep reviewing $countStillLearning terms",
text = stringResource(
R.string.txt_keep_reviewing_terms_flip,
countStillLearning
),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 18.sp,
fontWeight = FontWeight.Bold
Expand All @@ -255,7 +259,7 @@ fun FlipFlashCardFinish(
border = BorderStroke(1.dp, studySetColor)
) {
Text(
text = "Restart Flashcards",
text = stringResource(R.string.txt_restart_flashcards),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 18.sp,
fontWeight = FontWeight.Bold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
Expand All @@ -30,11 +29,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.pwhs.quickmem.R
import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel

@Composable
Expand Down Expand Up @@ -126,7 +127,7 @@ fun StudyFlipFlashCard(
isShowingEffect -> when {
isSwipingLeft -> {
Text(
text = "Still Learning",
text = stringResource(R.string.txt_still_learning),
style = typography.bodyLarge.copy(
fontSize = 20.sp,
color = stillLearningColor,
Expand All @@ -137,7 +138,7 @@ fun StudyFlipFlashCard(

isSwipingRight -> {
Text(
text = "Known",
text = stringResource(R.string.txt_known),
style = typography.bodyLarge.copy(
fontSize = 20.sp,
color = knownColor,
Expand Down Expand Up @@ -195,7 +196,7 @@ fun StudyFlipFlashCard(
isShowingEffect -> when {
isSwipingLeft -> {
Text(
text = "Still Learning",
text = stringResource(R.string.txt_still_learning),
style = typography.bodyLarge.copy(
fontSize = 20.sp,
color = stillLearningColor,
Expand All @@ -206,7 +207,7 @@ fun StudyFlipFlashCard(

isSwipingRight -> {
Text(
text = "Known",
text = stringResource(R.string.txt_known),
style = typography.bodyLarge.copy(
fontSize = 20.sp,
color = knownColor,
Expand Down Expand Up @@ -291,7 +292,7 @@ fun StudyFlipFlashCard(
isShowingEffect -> when {
isSwipingLeft -> {
Text(
text = "Still Learning",
text = stringResource(R.string.txt_still_learning),
style = typography.bodyLarge.copy(
fontSize = 18.sp,
color = stillLearningColor,
Expand All @@ -302,7 +303,7 @@ fun StudyFlipFlashCard(

isSwipingRight -> {
Text(
text = "Known",
text = stringResource(R.string.txt_known),
style = typography.bodyLarge.copy(
fontSize = 18.sp,
color = knownColor,
Expand Down Expand Up @@ -360,7 +361,7 @@ fun StudyFlipFlashCard(
isShowingEffect -> when {
isSwipingLeft -> {
Text(
text = "Still Learning",
text = stringResource(R.string.txt_still_learning),
style = typography.bodyLarge.copy(
fontSize = 18.sp,
color = stillLearningColor,
Expand All @@ -371,7 +372,7 @@ fun StudyFlipFlashCard(

isSwipingRight -> {
Text(
text = "Known",
text = stringResource(R.string.txt_known),
style = typography.bodyLarge.copy(
fontSize = 18.sp,
color = knownColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.pwhs.quickmem.R
import com.pwhs.quickmem.core.data.enums.QuizStatus
import com.pwhs.quickmem.core.data.states.RandomAnswer
import com.pwhs.quickmem.core.data.states.WrongAnswer
Expand Down Expand Up @@ -149,10 +151,10 @@ fun LearnByQuiz(
CenterAlignedTopAppBar(
title = {
when (isLoading) {
true -> Text("Loading")
true -> Text(stringResource(R.string.txt_loading))
false -> when (isEndOfList) {
false -> Text("${currentCardIndex + 1}/${flashCardList.size}")
true -> Text("Finished")
true -> Text(stringResource(R.string.txt_finished))
}
Comment on lines +154 to 158
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Cần đồng bộ việc sử dụng stringResource

Phát hiện việc sử dụng không nhất quán của stringResource. Trong khi loading và finished text đã được localize, text hiển thị số thứ tự "${currentCardIndex + 1}/${flashCardList.size}" vẫn đang hardcode.

Đề xuất sửa như sau:

true -> Text(stringResource(R.string.txt_loading))
false -> when (isEndOfList) {
-    false -> Text("${currentCardIndex + 1}/${flashCardList.size}")
+    false -> Text(
+        text = stringResource(
+            R.string.txt_progress_format,
+            currentCardIndex + 1,
+            flashCardList.size
+        )
+    )
    true -> Text(stringResource(R.string.txt_finished))
}

Committable suggestion skipped: line range outside the PR's diff.

}
},
Expand All @@ -168,7 +170,7 @@ fun LearnByQuiz(
) {
Icon(
imageVector = Default.Clear,
contentDescription = "Back"
contentDescription = stringResource(R.string.txt_back),
)
}
},
Expand Down Expand Up @@ -302,7 +304,7 @@ fun LearnByQuiz(
.padding(16.dp)
) {
Text(
text = "Hint",
text = stringResource(R.string.txt_hint),
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
Expand Down
Loading