add languages

main
ByrmGkcn 2023-12-18 16:09:35 +01:00
parent 3956aad6c1
commit dc97d22b03
8 changed files with 158 additions and 24 deletions

View File

@ -39,6 +39,7 @@ dependencies {
testImplementation("junit:junit:4.13.1") testImplementation("junit:junit:4.13.1")
implementation("org.apache.poi:poi:5.0.0") implementation("org.apache.poi:poi:5.0.0")
implementation("org.apache.poi:poi-ooxml:5.0.0") implementation("org.apache.poi:poi-ooxml:5.0.0")
} }

View File

@ -22,6 +22,7 @@ import java.io.IOException
@Composable @Composable
fun glossaryPage( fun glossaryPage(
languageManager: LanguageManager,
onAddWordClick: () -> Unit, onAddWordClick: () -> Unit,
onImportClick: () -> Unit, onImportClick: () -> Unit,
onExportClick: () -> Unit, onExportClick: () -> Unit,
@ -34,7 +35,7 @@ fun glossaryPage(
verticalArrangement = Arrangement.Top, // Align content at the top verticalArrangement = Arrangement.Top, // Align content at the top
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text(text = "Glossaire", style = MaterialTheme.typography.h3) Text(text = languageManager.getGlossaryTitle(), style = MaterialTheme.typography.h3)
} }
Column( Column(
@ -55,7 +56,7 @@ fun glossaryPage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Ajouter un mot") Text(languageManager.getAddWordText())
} }
Button( Button(
@ -67,7 +68,7 @@ fun glossaryPage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Importer un fichier CSV ou XLSX") Text(languageManager.getImportText())
} }
Button( Button(
@ -79,7 +80,7 @@ fun glossaryPage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Exporter un fichier CSV") Text(languageManager.getExportText())
} }
Button( Button(
@ -91,7 +92,7 @@ fun glossaryPage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Voir le glossaire") Text(languageManager.getSeeGlossaryText())
} }
} }
@ -107,7 +108,7 @@ fun glossaryPage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Retour") Text(languageManager.getBackButtonText())
} }
} }
} }

View File

@ -1,20 +1,47 @@
package main package main
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.clickable
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import java.util.*
var mostUsedWordList = mutableMapOf<String, Int>() var mostUsedWordList = mutableMapOf<String, Int>()
enum class Language {
FRENCH, ENGLISH
}
@Composable @Composable
fun homePage( fun homePage(
languageManager: LanguageManager,
onGlossaryClick: () -> Unit, onGlossaryClick: () -> Unit,
onCodeToVerifyClick: () -> Unit onCodeToVerifyClick: () -> Unit
) { ) {
val noFileSnackbarVisibleState = remember { mutableStateOf(false) } val noFileSnackbarVisibleState = remember { mutableStateOf(false) }
var isCompareClicked by remember { mutableStateOf(false) }
// Utilisez un Box pour placer le drapeau en haut à droite
Box(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
contentAlignment = Alignment.TopEnd
) {
// Utilisez les images des drapeaux
Image(
painter = painterResource(if (languageManager.currentLanguage == Language.FRENCH) "FR.png" else "EN.png"),
contentDescription = "Language Flag",
modifier = Modifier.size(48.dp)
.clickable { languageManager.changeLanguage() }
)
}
Column( Column(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@ -23,41 +50,36 @@ fun homePage(
) { ) {
Text("Quali'Nomme", style = MaterialTheme.typography.h3) Text("Quali'Nomme", style = MaterialTheme.typography.h3)
var isCompareClicked by remember { mutableStateOf(false) }
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
Column { // Wrap the Row in a Column Column {
Row( Row(
horizontalArrangement = Arrangement.spacedBy(16.dp) horizontalArrangement = Arrangement.spacedBy(16.dp)
) { ) {
Button( Button(
onClick = onGlossaryClick, onClick = onGlossaryClick,
modifier = Modifier modifier = Modifier.width(200.dp),
.width(200.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Glossaire") Text(languageManager.getGlossaryText())
} }
Button( Button(
onClick = onCodeToVerifyClick, onClick = onCodeToVerifyClick,
modifier = Modifier modifier = Modifier.width(200.dp),
.width(200.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Code à Vérifier") Text(languageManager.getCodeToVerifyText())
} }
Button( Button(
onClick = { onClick = {
//if file not uploaded show snackbar
if (mostUsedWordList.isEmpty()) { if (mostUsedWordList.isEmpty()) {
noFileSnackbarVisibleState.value = true noFileSnackbarVisibleState.value = true
println("Veuillez d'abord importer un fichier") println("Veuillez d'abord importer un fichier")
@ -65,21 +87,17 @@ fun homePage(
} else { } else {
isCompareClicked = true isCompareClicked = true
} }
}, },
modifier = Modifier modifier = Modifier.width(200.dp),
.width(200.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
), ),
//disable if file not uploaded
enabled = mostUsedWordList.isNotEmpty() enabled = mostUsedWordList.isNotEmpty()
) { ) {
Text("Comparer") Text(languageManager.getCompareText())
} }
} }
} }
if (noFileSnackbarVisibleState.value) { if (noFileSnackbarVisibleState.value) {
@ -111,3 +129,28 @@ fun homePage(
} }
} }
} }
@Composable
fun getGlossaryButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Glossaire"
Language.ENGLISH -> "Glossary"
}
}
@Composable
fun getCodeToVerifyButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Code à Vérifier"
Language.ENGLISH -> "Code to Verify"
}
}
@Composable
fun getCompareButtonText(language: Language): String {
return when (language) {
Language.FRENCH -> "Comparer"
Language.ENGLISH -> "Compare"
}
}

View File

@ -0,0 +1,84 @@
package main
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
class LanguageManager {
var currentLanguage by mutableStateOf(Language.FRENCH)
private set
fun changeLanguage() {
currentLanguage = if (currentLanguage == Language.FRENCH) Language.ENGLISH else Language.FRENCH
}
fun getGlossaryText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Glossaire"
Language.ENGLISH -> "Glossary"
}
}
fun getCodeToVerifyText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Code à Vérifier"
Language.ENGLISH -> "Code to Verify"
}
}
fun getCompareText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Comparer"
Language.ENGLISH -> "Compare"
}
}
fun getAddWordText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Ajouter un mot"
Language.ENGLISH -> "Add a word"
}
}
fun getImportText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Importer un fichier"
Language.ENGLISH -> "Import a file"
}
}
fun getExportText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Exporter un fichier"
Language.ENGLISH -> "Export a file"
}
}
fun getSeeGlossaryText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Voir le glossaire"
Language.ENGLISH -> "See glossary"
}
}
fun getGlossaryTitle(): String {
return when (currentLanguage) {
Language.FRENCH -> "Glossaire"
Language.ENGLISH -> "Glossary"
}
}
fun getLanguageChoiceTitle(): String {
return when (currentLanguage) {
Language.FRENCH -> "Choix du langage"
Language.ENGLISH -> "Language choice"
}
}
fun getBackButtonText(): String {
return when (currentLanguage) {
Language.FRENCH -> "Retour"
Language.ENGLISH -> "Back"
}
}
}

View File

@ -17,6 +17,7 @@ val customRedColor = Color(0xFFB70D1B)
@Composable @Composable
@Preview @Preview
fun app() { fun app() {
val languageManager = LanguageManager()
MaterialTheme { MaterialTheme {
val currentPage = remember { mutableStateOf("accueil") } val currentPage = remember { mutableStateOf("accueil") }
@ -26,6 +27,7 @@ fun app() {
when (currentPage.value) { when (currentPage.value) {
"accueil" -> { "accueil" -> {
homePage( homePage(
languageManager,
onGlossaryClick = { currentPage.value = "glossaire" }, onGlossaryClick = { currentPage.value = "glossaire" },
onCodeToVerifyClick = { currentPage.value = "choixLangage" } onCodeToVerifyClick = { currentPage.value = "choixLangage" }
) )
@ -33,6 +35,7 @@ fun app() {
"glossaire" -> { "glossaire" -> {
glossaryPage( glossaryPage(
languageManager,
onAddWordClick = { currentPage.value = "formulaire" }, onAddWordClick = { currentPage.value = "formulaire" },
onImportClick = { onImportClick = {
selectFile(setOf("csv", "xlsx")) { filePath -> selectFile(setOf("csv", "xlsx")) { filePath ->
@ -77,6 +80,7 @@ fun app() {
val javaExtensions = setOf("java") val javaExtensions = setOf("java")
val jsExtensions = setOf("js", "html") val jsExtensions = setOf("js", "html")
choixLangagePage( choixLangagePage(
languageManager,
onBackClick = { currentPage.value = "accueil" }, onBackClick = { currentPage.value = "accueil" },
onPythonClick = { onPythonClick = {
selectFile(pythonExtensions) { filePath -> selectFile(pythonExtensions) { filePath ->

View File

@ -13,6 +13,7 @@ import androidx.compose.ui.unit.dp
@Composable @Composable
fun choixLangagePage( fun choixLangagePage(
languageManager: LanguageManager,
onBackClick: () -> Unit, onBackClick: () -> Unit,
onPythonClick: () -> Unit, onPythonClick: () -> Unit,
onJavaClick: () -> Unit, onJavaClick: () -> Unit,
@ -24,7 +25,7 @@ fun choixLangagePage(
verticalArrangement = Arrangement.Top, // Align content at the top verticalArrangement = Arrangement.Top, // Align content at the top
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text(text = "Choix du langage", style = MaterialTheme.typography.h3) Text(text = languageManager.getLanguageChoiceTitle(), style = MaterialTheme.typography.h3)
} }
Column( Column(
@ -87,7 +88,7 @@ fun choixLangagePage(
contentColor = Color.White contentColor = Color.White
) )
) { ) {
Text("Retour") Text(languageManager.getBackButtonText())
} }
} }

BIN
src/main/resources/EN.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/main/resources/FR.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B