-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙️ Add app language selection setting
A language selection setting is added to the settings page. The `MainActivity` now extends `AppCompatActivity` to handle changing the app language. More info on this here: https://developer.android.com/guide/topics/resources/app-languages#androidx-impl
- Loading branch information
1 parent
fc8b29e
commit e1f95a5
Showing
8 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/kotlin/br/com/colman/petals/settings/AppLanguages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package br.com.colman.petals.settings | ||
|
||
enum class AppLanguage(val code: String) { | ||
Deutsch("de"), | ||
English("en"), | ||
Français("fr"), | ||
Español("es"), | ||
Italiano("it"), | ||
Nederlands("nl"), | ||
Norsk("no"), | ||
Português("pt"), | ||
Русский("ru"), | ||
Türkçe("tr"), | ||
Українськ("uk"); | ||
|
||
companion object { | ||
fun getAppLanguageName(code: String): String { | ||
return when (code) { | ||
"de" -> Deutsch.name | ||
"fr" -> Français.name | ||
"es" -> Español.name | ||
"it" -> Italiano.name | ||
"nl" -> Nederlands.name | ||
"no" -> Norsk.name | ||
"pt" -> Português.name | ||
"ru" -> Русский.name | ||
"tr" -> Türkçe.name | ||
"uk" -> Українськ.name | ||
else -> English.name | ||
} | ||
} | ||
|
||
fun getAppLanguageCode(languageName: String): String { | ||
return when (languageName) { | ||
Deutsch.name -> Deutsch.code | ||
Français.name -> Français.code | ||
Español.name -> Español.code | ||
Italiano.name -> Italiano.code | ||
Nederlands.name -> Nederlands.code | ||
Norsk.name -> Norsk.code | ||
Português.name -> Português.code | ||
Русский.name -> Русский.code | ||
Türkçe.name -> Türkçe.code | ||
Українськ.name -> Українськ.code | ||
else -> English.code | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/kotlin/br/com/colman/petals/settings/view/listitem/LanguageListItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package br.com.colman.petals.settings.view.listitem | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import br.com.colman.petals.R.string.language_label | ||
import br.com.colman.petals.R.string.what_language_should_be_used | ||
import br.com.colman.petals.settings.view.dialog.SelectFromListDialog | ||
import compose.icons.TablerIcons | ||
import compose.icons.tablericons.Language | ||
|
||
@Preview | ||
@Composable | ||
fun LanguageListItem( | ||
appLanguage: String = "English", | ||
appLanguageList: List<String> = listOf(), | ||
setAppLanguage: (String) -> Unit = {} | ||
) { | ||
DialogListItem( | ||
icon = TablerIcons.Language, | ||
textId = language_label, | ||
descriptionId = what_language_should_be_used, | ||
dialog = { hideDialog -> LanguageDialog(appLanguage, appLanguageList, setAppLanguage, hideDialog) } | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun LanguageDialog( | ||
initialAppLanguage: String = "", | ||
appLanguageList: List<String> = listOf(), | ||
setAppLanguage: (String) -> Unit = {}, | ||
onDismiss: () -> Unit = {}, | ||
) { | ||
SelectFromListDialog( | ||
initialValue = initialAppLanguage, | ||
possibleValues = appLanguageList, | ||
setValue = setAppLanguage, | ||
onDismiss = onDismiss, | ||
label = language_label | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/> | ||
</resources> |