From 3d6fe3bcb27221e8eb4d174e61dc918e0376084b Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Tue, 1 Oct 2024 15:52:45 +0200 Subject: [PATCH] Localization --- app/build.gradle.kts | 4 ++++ .../java/eu/m724/coincounter/MainActivity.kt | 3 ++- .../m724/coincounter/wallet/WalletActivity.kt | 7 ++++++- .../wallet/compose/TransactionDialog.kt | 20 ++++++++++++------- .../wallet/compose/WalletActionsDialog.kt | 8 +++++--- .../wallet/compose/WalletRenameDialog.kt | 8 +++++--- app/src/main/res/resources.properties | 1 + app/src/main/res/values/strings.xml | 15 ++++++++++++++ 8 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/resources.properties diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5818509..ddd0e92 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -56,6 +56,10 @@ android { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } + + androidResources { + generateLocaleConfig = true + } } dependencies { diff --git a/app/src/main/java/eu/m724/coincounter/MainActivity.kt b/app/src/main/java/eu/m724/coincounter/MainActivity.kt index 4dfa6b8..ea7f98f 100644 --- a/app/src/main/java/eu/m724/coincounter/MainActivity.kt +++ b/app/src/main/java/eu/m724/coincounter/MainActivity.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.rotate import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -262,7 +263,7 @@ fun AddWalletButton( ) { Icon( imageVector = Icons.Filled.Add, - contentDescription = "Add wallet", + contentDescription = stringResource(R.string.home_add_wallet), modifier = Modifier.rotate(angle) ) } diff --git a/app/src/main/java/eu/m724/coincounter/wallet/WalletActivity.kt b/app/src/main/java/eu/m724/coincounter/wallet/WalletActivity.kt index b7cfa04..99497cb 100644 --- a/app/src/main/java/eu/m724/coincounter/wallet/WalletActivity.kt +++ b/app/src/main/java/eu/m724/coincounter/wallet/WalletActivity.kt @@ -18,7 +18,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import dagger.hilt.android.AndroidEntryPoint +import eu.m724.coincounter.R import eu.m724.coincounter.ui.theme.CoinCounterTheme import eu.m724.coincounter.wallet.compose.TransactionDialog import eu.m724.coincounter.wallet.compose.WalletActivityView @@ -52,7 +54,10 @@ class WalletActivity : ComponentActivity() { FloatingActionButton(onClick = { transactionDialogShown = true }) { - Icon(Icons.Filled.Create, "New transaction") + Icon( + imageVector = Icons.Filled.Create, + contentDescription = stringResource(R.string.wallet_new_transaction) + ) } } ) { innerPadding -> diff --git a/app/src/main/java/eu/m724/coincounter/wallet/compose/TransactionDialog.kt b/app/src/main/java/eu/m724/coincounter/wallet/compose/TransactionDialog.kt index c7c4de2..4c80c5e 100644 --- a/app/src/main/java/eu/m724/coincounter/wallet/compose/TransactionDialog.kt +++ b/app/src/main/java/eu/m724/coincounter/wallet/compose/TransactionDialog.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview @@ -87,7 +88,7 @@ fun TransactionDialog( .weight(1f) .focusRequester(firstFocus) .focusProperties { next = secondFocus }, - supportingText = { Text("Label") }, + supportingText = { Text(stringResource(R.string.create_transaction_label)) }, keyboardOptions = KeyboardOptions.Default.copy( imeAction = ImeAction.Next ), @@ -106,7 +107,7 @@ fun TransactionDialog( .focusRequester(secondFocus), supportingText = { Text( - text = "Value", + text = stringResource(R.string.create_transaction_value), color = if (!valueValid) MaterialTheme.colorScheme.error else Color.Unspecified ) }, @@ -117,7 +118,11 @@ fun TransactionDialog( isError = !valueValid, trailingIcon = { if (!valueValid) - Icon(painterResource(id = R.drawable.baseline_error_24), "error", tint = MaterialTheme.colorScheme.error) + Icon( + painter = painterResource(id = R.drawable.baseline_error_24), + contentDescription = stringResource(R.string.create_transaction_value_error), + tint = MaterialTheme.colorScheme.error + ) }, singleLine = true ) @@ -129,7 +134,7 @@ fun TransactionDialog( checked = absoluteChecked, onCheckedChange = { absoluteChecked = it } ) - Text(text = "Absolute") + Text(text = stringResource(R.string.create_transaction_absolute)) } } Row( @@ -142,7 +147,7 @@ fun TransactionDialog( onDismiss() } ) { - Text(text = "Cancel") + Text(text = stringResource(R.string.create_transaction_cancel)) } TextButton( onClick = { @@ -150,11 +155,12 @@ fun TransactionDialog( if (doubleValue != null) { onConfirm(label, (doubleValue * 100).toInt(), absoluteChecked) // TODO handle fixed point } else { - Toast.makeText(context, "Value is not a number", Toast.LENGTH_SHORT).show() + Toast.makeText(context, + context.getString(R.string.create_transaction_nan), Toast.LENGTH_SHORT).show() } } ) { - Text("Create transaction") + Text(stringResource(R.string.create_transaction_confirm)) } } } diff --git a/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletActionsDialog.kt b/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletActionsDialog.kt index 5c372d1..6d4d538 100644 --- a/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletActionsDialog.kt +++ b/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletActionsDialog.kt @@ -8,8 +8,10 @@ import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog +import eu.m724.coincounter.R /** * A dialog that's shown when you long click on wallet name @@ -37,13 +39,13 @@ fun ActionsDialog( modifier = Modifier.padding(16.dp) ) { TextButton(onClick = onRename) { - Text("Rename wallet") + Text(stringResource(R.string.wallet_actions_rename)) } TextButton(onClick = onDelete) { - Text("Delete wallet") + Text(stringResource(R.string.wallet_actions_delete)) } TextButton(onClick = onDismiss) { - Text("Cancel") + Text(stringResource(R.string.wallet_actions_cancel)) } } } diff --git a/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletRenameDialog.kt b/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletRenameDialog.kt index fe79d98..f69ba36 100644 --- a/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletRenameDialog.kt +++ b/app/src/main/java/eu/m724/coincounter/wallet/compose/WalletRenameDialog.kt @@ -19,8 +19,10 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog +import eu.m724.coincounter.R @Composable fun RenameDialog( @@ -52,7 +54,7 @@ fun RenameDialog( .fillMaxWidth() .weight(1f) .focusRequester(focusRequester), - supportingText = { Text("New name") }, + supportingText = { Text(stringResource(R.string.wallet_rename_name)) }, singleLine = true ) } @@ -66,14 +68,14 @@ fun RenameDialog( onDismiss() } ) { - Text(text = "Cancel") + Text(text = stringResource(R.string.wallet_rename_cancel)) } TextButton( onClick = { onRename(value) } ) { - Text("Rename") + Text(stringResource(R.string.wallet_rename_confirm)) } } } diff --git a/app/src/main/res/resources.properties b/app/src/main/res/resources.properties new file mode 100644 index 0000000..63b46f9 --- /dev/null +++ b/app/src/main/res/resources.properties @@ -0,0 +1 @@ +unqualifiedResLocale=en \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f318c89..ead16ed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,4 +2,19 @@ Coin Counter Coin Counter WalletActivity + Create transaction + Value must be a number + Cancel + Absolute + Error + Value + Label + Rename wallet + Delete wallet + Cancel + New name + Cancel + Rename + New transaction + Create wallet \ No newline at end of file