From dc97d22b0363f54c337aaa2c2e301242cafeedf3 Mon Sep 17 00:00:00 2001 From: ByrmGkcn Date: Mon, 18 Dec 2023 16:09:35 +0100 Subject: [PATCH] add languages --- build.gradle.kts | 1 + src/main/kotlin/main/Glossary.kt | 13 ++-- src/main/kotlin/main/Home.kt | 75 ++++++++++++++++----- src/main/kotlin/main/LanguageManager.kt | 84 ++++++++++++++++++++++++ src/main/kotlin/main/Main.kt | 4 ++ src/main/kotlin/main/Verify.kt | 5 +- src/main/resources/EN.png | Bin 0 -> 1369 bytes src/main/resources/FR.png | Bin 0 -> 239 bytes 8 files changed, 158 insertions(+), 24 deletions(-) create mode 100644 src/main/kotlin/main/LanguageManager.kt create mode 100644 src/main/resources/EN.png create mode 100644 src/main/resources/FR.png diff --git a/build.gradle.kts b/build.gradle.kts index 6dddd18..12de536 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,6 +39,7 @@ dependencies { testImplementation("junit:junit:4.13.1") implementation("org.apache.poi:poi:5.0.0") implementation("org.apache.poi:poi-ooxml:5.0.0") + } diff --git a/src/main/kotlin/main/Glossary.kt b/src/main/kotlin/main/Glossary.kt index c695faa..7ccf2ed 100644 --- a/src/main/kotlin/main/Glossary.kt +++ b/src/main/kotlin/main/Glossary.kt @@ -22,6 +22,7 @@ import java.io.IOException @Composable fun glossaryPage( + languageManager: LanguageManager, onAddWordClick: () -> Unit, onImportClick: () -> Unit, onExportClick: () -> Unit, @@ -34,7 +35,7 @@ fun glossaryPage( verticalArrangement = Arrangement.Top, // Align content at the top horizontalAlignment = Alignment.CenterHorizontally ) { - Text(text = "Glossaire", style = MaterialTheme.typography.h3) + Text(text = languageManager.getGlossaryTitle(), style = MaterialTheme.typography.h3) } Column( @@ -55,7 +56,7 @@ fun glossaryPage( contentColor = Color.White ) ) { - Text("Ajouter un mot") + Text(languageManager.getAddWordText()) } Button( @@ -67,7 +68,7 @@ fun glossaryPage( contentColor = Color.White ) ) { - Text("Importer un fichier CSV ou XLSX") + Text(languageManager.getImportText()) } Button( @@ -79,7 +80,7 @@ fun glossaryPage( contentColor = Color.White ) ) { - Text("Exporter un fichier CSV") + Text(languageManager.getExportText()) } Button( @@ -91,7 +92,7 @@ fun glossaryPage( contentColor = Color.White ) ) { - Text("Voir le glossaire") + Text(languageManager.getSeeGlossaryText()) } } @@ -107,7 +108,7 @@ fun glossaryPage( contentColor = Color.White ) ) { - Text("Retour") + Text(languageManager.getBackButtonText()) } } } diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index fe971c5..46ad5f3 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -1,20 +1,47 @@ package main +import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* +import androidx.compose.foundation.clickable import androidx.compose.material.* import androidx.compose.runtime.* 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.unit.dp +import java.util.* var mostUsedWordList = mutableMapOf() + +enum class Language { + FRENCH, ENGLISH +} + @Composable fun homePage( + languageManager: LanguageManager, onGlossaryClick: () -> Unit, onCodeToVerifyClick: () -> Unit ) { 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( modifier = Modifier.fillMaxSize(), @@ -23,41 +50,36 @@ fun homePage( ) { Text("Quali'Nomme", style = MaterialTheme.typography.h3) - var isCompareClicked by remember { mutableStateOf(false) } - Spacer(modifier = Modifier.height(16.dp)) - Column { // Wrap the Row in a Column + Column { Row( horizontalArrangement = Arrangement.spacedBy(16.dp) ) { Button( onClick = onGlossaryClick, - modifier = Modifier - .width(200.dp), + modifier = Modifier.width(200.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White ) ) { - Text("Glossaire") + Text(languageManager.getGlossaryText()) } Button( onClick = onCodeToVerifyClick, - modifier = Modifier - .width(200.dp), + modifier = Modifier.width(200.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White ) ) { - Text("Code à Vérifier") + Text(languageManager.getCodeToVerifyText()) } Button( onClick = { - //if file not uploaded show snackbar if (mostUsedWordList.isEmpty()) { noFileSnackbarVisibleState.value = true println("Veuillez d'abord importer un fichier") @@ -65,21 +87,17 @@ fun homePage( } else { isCompareClicked = true } - }, - modifier = Modifier - .width(200.dp), + modifier = Modifier.width(200.dp), colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White ), - //disable if file not uploaded enabled = mostUsedWordList.isNotEmpty() ) { - Text("Comparer") + Text(languageManager.getCompareText()) } } - } 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" + } +} + diff --git a/src/main/kotlin/main/LanguageManager.kt b/src/main/kotlin/main/LanguageManager.kt new file mode 100644 index 0000000..37fa943 --- /dev/null +++ b/src/main/kotlin/main/LanguageManager.kt @@ -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" + } + } +} diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index 4dd3cde..1307cf9 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -17,6 +17,7 @@ val customRedColor = Color(0xFFB70D1B) @Composable @Preview fun app() { + val languageManager = LanguageManager() MaterialTheme { val currentPage = remember { mutableStateOf("accueil") } @@ -26,6 +27,7 @@ fun app() { when (currentPage.value) { "accueil" -> { homePage( + languageManager, onGlossaryClick = { currentPage.value = "glossaire" }, onCodeToVerifyClick = { currentPage.value = "choixLangage" } ) @@ -33,6 +35,7 @@ fun app() { "glossaire" -> { glossaryPage( + languageManager, onAddWordClick = { currentPage.value = "formulaire" }, onImportClick = { selectFile(setOf("csv", "xlsx")) { filePath -> @@ -77,6 +80,7 @@ fun app() { val javaExtensions = setOf("java") val jsExtensions = setOf("js", "html") choixLangagePage( + languageManager, onBackClick = { currentPage.value = "accueil" }, onPythonClick = { selectFile(pythonExtensions) { filePath -> diff --git a/src/main/kotlin/main/Verify.kt b/src/main/kotlin/main/Verify.kt index f96eaef..5f8e7fb 100644 --- a/src/main/kotlin/main/Verify.kt +++ b/src/main/kotlin/main/Verify.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.unit.dp @Composable fun choixLangagePage( + languageManager: LanguageManager, onBackClick: () -> Unit, onPythonClick: () -> Unit, onJavaClick: () -> Unit, @@ -24,7 +25,7 @@ fun choixLangagePage( verticalArrangement = Arrangement.Top, // Align content at the top horizontalAlignment = Alignment.CenterHorizontally ) { - Text(text = "Choix du langage", style = MaterialTheme.typography.h3) + Text(text = languageManager.getLanguageChoiceTitle(), style = MaterialTheme.typography.h3) } Column( @@ -87,7 +88,7 @@ fun choixLangagePage( contentColor = Color.White ) ) { - Text("Retour") + Text(languageManager.getBackButtonText()) } } diff --git a/src/main/resources/EN.png b/src/main/resources/EN.png new file mode 100644 index 0000000000000000000000000000000000000000..58b0ec24b7d2d67b995119efb714d6d8bd65bd98 GIT binary patch literal 1369 zcmeAS@N?(olHy`uVBq!ia0vp^4}rLygBeI(KX8s8NU@|l`Z_W&Z0zU$lgJ9>D%Da2>HmNKUN7HtR>l6jf!Dk32Tn(bn^L+Y}e}Dd7wh#Y&`r-*e{X6MZzh1vPqh$AT!J7Yn|7Nrr z9RRwJG0EHAg(;1@CI!f0FY)wsWq;1jFD}T{zS&5ffr0ser;B4q#jUqf(m7k)m$@A=NpDMr~`Z+xmQ&E5SyXyw_A zTk~&a7sZ#>Z$J6;;9>W<`ZsPL|MKx*qWt5@%m1@H-27aBmQUQiS1JFe^Ln4NJ90h$ zUY_m4H+O%lb@RK+Tkq8Wd*tc-oY3QncT`?{lHak$Z`-P5fjqG*Z68ipaGmq# zs#BcotZ#+<`ggAC;*56me>T@=eer_nwrf{SxuEhw%4yXqFQ?fHcppB~I=5n#@)oXJ z0#b`EEIax#hnpjPIrriPybHfN?O&zj)V@HxWwzXO$xzjnHupbPhdSLui&twYY}vjb zoJ0Iwzfaluyp9iNG+%6b+pz!E+Etr4n^jx?U)#Fslxh#ht{jPpKRReadwWkgF_UIsNv=rSrE)Y)LXM99dAZ<~mVlV7Alr*!j#r@|$X z&p9$1+x+@@6hEdlz7y*g4wANcG3%v);`fEDcNd#^oOoB^a6Ohw@RN1_h0;ppmL^7q zlEY&53sVHx?_RjzW)O61YiK&&!7lpLCTqySQb`BJc za@?G&=@@!~g?H{u!4+In7hEj%F9}^JXi`|#yH-o3>Df8?qEMjfHumL>gBY>Ep*E|gBUXvy5X;Pt0X9Fq^W=iP8p zJ~Nen*FyD)29G65F0+RmsxWmhXFa0Iv%2b|UA})x-k;iga<|1U_#XYl>AcFxe6F5C z&kC-)lR8>1+&4J%^h?>_eXVP=3}SA6o_yodlCBHOU&-uxnku`{JJjP^?9-OMFwsd{ zi)|Oi0^Kg#d|?&P>3z-_!9bV0E19eWI()I96ex@YIoUy;H{@&&Ioh?rzW%Qtx0T+* zw9x+yNlR1ow%mGg1(>~6OI#yLQW8s2t&)pUffR$0fswJUfw``sX^4@rm7%$np@Fu6 nft7)QVWkzYNJG+)o1c=IR*74KgGy5fPy>UftDnm{r-UW|tnOf! literal 0 HcmV?d00001 diff --git a/src/main/resources/FR.png b/src/main/resources/FR.png new file mode 100644 index 0000000000000000000000000000000000000000..449901d169e4f3b9eda10432278b2e458826e4d7 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^4}o|Z2Q!eA_mVdRQk(%kA+8K+A^-pXKPRZxxWHmD zP;jBAi(^Q|oVVu<85tNjm=|RJztC2oZldsV=DfF>Y`g;w