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ữ #84

Merged
merged 15 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -25,6 +25,7 @@ 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
Expand All @@ -41,6 +42,7 @@ import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScr
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination
import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination.invoke
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.pwhs.quickmem.R

@Composable
@Destination<RootGraph>
Expand Down Expand Up @@ -104,7 +106,6 @@ fun ExploreScreen(
onCreateStudySet = {
viewModel.onEvent(ExploreUiAction.OnCreateStudySet)
},
errorMessage = uiState.errorMessage
)
}

Expand All @@ -131,12 +132,11 @@ fun Explore(
onQuestionTypeChange: (QuestionType) -> Unit = {},
onDifficultyLevelChange: (DifficultyLevel) -> Unit = {},
onCreateStudySet: () -> Unit = {},
errorMessage: String = ""
) {
var tabIndex by remember { mutableIntStateOf(0) }
val tabTitles = listOf(
"Create Study Set AI",
"Top Streak",
stringResource(R.string.txt_create_study_set_ai),
stringResource(R.string.txt_top_streak),
)

Scaffold(
Expand All @@ -145,7 +145,7 @@ fun Explore(
CenterAlignedTopAppBar(
title = {
Text(
text = "Explore",
text = stringResource(R.string.txt_explore),
style = typography.titleMedium.copy(
fontWeight = FontWeight.Bold
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ fun CreateStudySetAITab(
) {
Icon(
painter = painterResource(R.drawable.ic_sparkling),
contentDescription = "Create",
contentDescription = stringResource(R.string.txt_create),
)
Text(
text = "Create",
text = stringResource(R.string.txt_create),
style = typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
Expand All @@ -141,7 +141,7 @@ fun CreateStudySetAITab(
modifier = Modifier.padding(bottom = 8.dp)
) {
Text(
text = "Warning: AI may not generate accurate or complete flashcards. Please review if unsure.",
text = stringResource(R.string.txt_warning_ai_not_gen),
color = Color.Red,
style = typography.bodyMedium.copy(fontWeight = FontWeight.Bold),
textAlign = TextAlign.Start,
Expand Down Expand Up @@ -176,7 +176,7 @@ fun CreateStudySetAITab(
onValueChange = onTitleChange,
placeholder = {
Text(
text = "Title (required)",
text = stringResource(R.string.txt_title_required),
style = typography.bodyMedium,
)
}
Expand All @@ -194,7 +194,7 @@ fun CreateStudySetAITab(
onValueChange = onDescriptionChange,
placeholder = {
Text(
text = "Description (optional)",
text = stringResource(R.string.txt_description_optional),
style = typography.bodyMedium,
)
},
Expand All @@ -211,7 +211,7 @@ fun CreateStudySetAITab(
}
item {
Text(
text = "Number of flashcards (optional)",
text = stringResource(R.string.txt_number_of_flashcards_optional),
style = typography.titleMedium.copy(
fontWeight = FontWeight.Bold
),
Expand Down Expand Up @@ -310,7 +310,7 @@ fun CreateStudySetAITab(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Language",
text = stringResource(R.string.txt_language),
style = typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
Expand All @@ -336,7 +336,7 @@ fun CreateStudySetAITab(
}
item {
Text(
text = "Question type",
text = stringResource(R.string.txt_question_type),
style = typography.titleMedium.copy(
fontWeight = FontWeight.Bold
),
Expand All @@ -363,7 +363,7 @@ fun CreateStudySetAITab(
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Text(text = "Multiple choice")
Text(text = stringResource(R.string.txt_multiple_choice))
Spacer(modifier = Modifier.weight(1f))
RadioButton(
selected = questionType == QuestionType.MULTIPLE_CHOICE,
Expand All @@ -377,7 +377,7 @@ fun CreateStudySetAITab(
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Text(text = "True/False")
Text(text = stringResource(R.string.txt_true_false))
Spacer(modifier = Modifier.weight(1f))
RadioButton(
selected = questionType == QuestionType.TRUE_FALSE,
Expand All @@ -390,7 +390,7 @@ fun CreateStudySetAITab(

item {
Text(
text = "Difficulty level",
text = stringResource(R.string.txt_difficulty_level),
style = typography.titleMedium.copy(
fontWeight = FontWeight.Bold
),
Expand All @@ -416,7 +416,7 @@ fun CreateStudySetAITab(
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Text(text = "Easy")
Text(text = stringResource(R.string.txt_easy))
Spacer(modifier = Modifier.weight(1f))
RadioButton(
selected = difficultyLevel == DifficultyLevel.EASY,
Expand All @@ -430,7 +430,7 @@ fun CreateStudySetAITab(
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Text(text = "Medium")
Text(text = stringResource(R.string.txt_medium))
Spacer(modifier = Modifier.weight(1f))
RadioButton(
selected = difficultyLevel == DifficultyLevel.MEDIUM,
Expand All @@ -444,7 +444,7 @@ fun CreateStudySetAITab(
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Text(text = "Hard")
Text(text = stringResource(R.string.txt_hard))
Spacer(modifier = Modifier.weight(1f))
RadioButton(
selected = difficultyLevel == DifficultyLevel.HARD,
Expand Down Expand Up @@ -492,7 +492,7 @@ fun CreateStudySetAITab(
) {
Image(
painter = painterResource(id = R.drawable.ic_vn_flag),
contentDescription = "VN Flag",
contentDescription = stringResource(R.string.txt_vn_flag),
modifier = Modifier
.size(24.dp)
)
Expand All @@ -511,7 +511,7 @@ fun CreateStudySetAITab(
if (language == LanguageCode.VI.code) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "Check",
contentDescription = stringResource(R.string.txt_check),
tint = colorScheme.primary
)
}
Expand All @@ -532,7 +532,7 @@ fun CreateStudySetAITab(
) {
Image(
painter = painterResource(id = R.drawable.ic_us_flag),
contentDescription = "US Flag",
contentDescription = stringResource(R.string.txt_us_flag),
modifier = Modifier
.size(24.dp)
)
Expand All @@ -552,7 +552,7 @@ fun CreateStudySetAITab(
if (language == LanguageCode.EN.code) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "Check",
contentDescription = stringResource(R.string.txt_check),
tint = colorScheme.primary
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -86,25 +87,25 @@ fun TopStreakScreen(
) {
Image(
painter = painterResource(id = R.drawable.top2),
contentDescription = "Silver Medal",
contentDescription = stringResource(R.string.txt_silver_medal),
modifier = Modifier.size(with(density) { silverSize.value.toDp() })
)
Image(
painter = painterResource(id = R.drawable.top1),
contentDescription = "Gold Medal",
contentDescription = stringResource(R.string.txt_gold_medal),
modifier = Modifier.size(with(density) { goldSize.value.toDp() })
)
Image(
painter = painterResource(id = R.drawable.top3),
contentDescription = "Bronze Medal",
contentDescription = stringResource(R.string.txt_bronze_medal),
modifier = Modifier.size(with(density) { bronzeSize.value.toDp() })
)
}

val message = when (rankOwner) {
in 1..3 -> "You have reached the top #$rankOwner on the Top Streak leaderboard!"
in 4..10 -> "Keep up the streak to climb the leaderboard!"
else -> "Top 10 highest streak leaderboard"
in 4..10 -> stringResource(R.string.txt_keep_up_the_streak_to_climb_the_leaderboard)
else -> stringResource(R.string.txt_top_10_highest_streak_leaderboard)
nqmgaming marked this conversation as resolved.
Show resolved Hide resolved
}

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ fun StreakItem(
when (rank) {
1 -> Image(
painter = painterResource(id = R.drawable.top1),
contentDescription = "Gold Medal",
contentDescription = stringResource(R.string.txt_gold_medal),
modifier = Modifier.size(32.dp)
)

2 -> Image(
painter = painterResource(id = R.drawable.top2),
contentDescription = "Silver Medal",
contentDescription = stringResource(R.string.txt_silver_medal),
modifier = Modifier.size(32.dp)
)

3 -> Image(
painter = painterResource(id = R.drawable.top3),
contentDescription = "Bronze Medal",
contentDescription = stringResource(R.string.txt_bronze_medal),
modifier = Modifier.size(32.dp)
)

Expand All @@ -85,7 +85,7 @@ fun StreakItem(

AsyncImage(
model = topStreak.avatarUrl,
contentDescription = "User Avatar",
contentDescription = stringResource(R.string.txt_user_avatar_top_streak),
contentScale = ContentScale.Crop,
modifier = Modifier
.size(40.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private fun Home(
if (studySets.isEmpty() && classes.isEmpty() && folders.isEmpty() && !isLoading) {
item {
Text(
text = "Here's how to get started",
text = stringResource(R.string.txt_here_is_how_to_get_started),
style = typography.titleMedium.copy(
color = colorScheme.primary,
fontWeight = FontWeight.Bold
Expand All @@ -436,14 +436,14 @@ private fun Home(
) {
Icon(
painter = painterResource(R.drawable.ic_three_cards),
contentDescription = "Create a flashcard",
contentDescription = stringResource(R.string.txt_create_a_flashcard),
tint = Color.Blue,
modifier = Modifier
.size(50.dp)
)

Text(
text = "Create your own flashcards",
text = stringResource(R.string.txt_create_your_own_flashcards),
style = typography.titleMedium.copy(
color = colorScheme.onSurface,
fontWeight = FontWeight.Bold
Expand All @@ -462,7 +462,7 @@ private fun Home(
if (studySets.isNotEmpty()) {
item {
Text(
text = "Study sets",
text = stringResource(R.string.txt_study_sets),
style = typography.titleMedium.copy(
color = colorScheme.primary,
fontWeight = FontWeight.Bold
Expand Down Expand Up @@ -490,7 +490,7 @@ private fun Home(
if (folders.isNotEmpty()) {
item {
Text(
text = "Folders",
text = stringResource(R.string.txt_folders),
style = typography.titleMedium.copy(
color = colorScheme.primary,
fontWeight = FontWeight.Bold
Expand Down Expand Up @@ -520,7 +520,7 @@ private fun Home(
if (classes.isNotEmpty()) {
item {
Text(
text = "Classes",
text = stringResource(R.string.txt_classes),
style = typography.titleMedium.copy(
color = colorScheme.primary,
fontWeight = FontWeight.Bold
Expand All @@ -547,7 +547,7 @@ private fun Home(

item {
Text(
text = "Top 5 subjects have study sets",
text = stringResource(R.string.txt_top_5_subjects_have_study_sets),
style = typography.titleMedium.copy(
color = colorScheme.primary,
fontWeight = FontWeight.Bold
Expand Down Expand Up @@ -613,7 +613,7 @@ private fun Home(
modifier = Modifier.padding(bottom = 16.dp)
)
Text(
text = "Practice every day so you don't lose your streak!",
text = stringResource(R.string.txt_practice_every_day),
modifier.padding(top = 16.dp)
nqmgaming marked this conversation as resolved.
Show resolved Hide resolved
)
StreakCalendar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun FolderHomeItem(
) {
Icon(
imageVector = Outlined.Folder,
contentDescription = "Folder Icon",
contentDescription = stringResource(R.string.txt_folder_icon),
)
Text(
text = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
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
Expand Down Expand Up @@ -62,7 +63,7 @@ fun StreakCalendar(
if (hasStreak) {
Image(
painter = painterResource(id = R.drawable.ic_fire_date),
contentDescription = "Streak Fire",
contentDescription = stringResource(R.string.txt_streak_fire),
modifier = Modifier.fillMaxSize()
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fun SearchStudySetBySubject(
onClick = { retry() },
modifier = Modifier.padding(top = 16.dp)
) {
Text(text = "Retry")
Text(text = stringResource(R.string.txt_retry))
}
}
}
Expand Down
Loading