Localization

This commit is contained in:
Minecon724 2024-10-01 15:52:45 +02:00
parent 3f09577411
commit 3d6fe3bcb2
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
8 changed files with 51 additions and 15 deletions

View file

@ -56,6 +56,10 @@ android {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
androidResources {
generateLocaleConfig = true
}
}
dependencies {

View file

@ -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)
)
}

View file

@ -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 ->

View file

@ -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))
}
}
}

View file

@ -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))
}
}
}

View file

@ -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))
}
}
}

View file

@ -0,0 +1 @@
unqualifiedResLocale=en

View file

@ -2,4 +2,19 @@
<string name="app_name">Coin Counter</string>
<string name="title_activity_main">Coin Counter</string>
<string name="title_activity_wallet">WalletActivity</string>
<string name="create_transaction_confirm">Create transaction</string>
<string name="create_transaction_nan">Value must be a number</string>
<string name="create_transaction_cancel">Cancel</string>
<string name="create_transaction_absolute">Absolute</string>
<string name="create_transaction_value_error">Error</string>
<string name="create_transaction_value">Value</string>
<string name="create_transaction_label">Label</string>
<string name="wallet_actions_rename">Rename wallet</string>
<string name="wallet_actions_delete">Delete wallet</string>
<string name="wallet_actions_cancel">Cancel</string>
<string name="wallet_rename_name">New name</string>
<string name="wallet_rename_cancel">Cancel</string>
<string name="wallet_rename_confirm">Rename</string>
<string name="wallet_new_transaction">New transaction</string>
<string name="home_add_wallet">Create wallet</string>
</resources>