improvement: Move more text phrases to translatable resources #626

This commit is contained in:
Artem Chepurnyi 2024-10-22 20:13:08 +03:00
parent 1b29e2d24a
commit ce59bcd3c3
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
7 changed files with 42 additions and 83 deletions

View File

@ -41,20 +41,26 @@ import com.artemchep.keyguard.common.usecase.GetVaultSession
import com.artemchep.keyguard.common.usecase.ShowMessage
import com.artemchep.keyguard.common.usecase.WindowCoroutineScope
import com.artemchep.keyguard.copy.PermissionServiceAndroid
import com.artemchep.keyguard.feature.loading.ReadableExceptionMessage
import com.artemchep.keyguard.feature.loading.getErrorReadableMessage
import com.artemchep.keyguard.feature.navigation.LocalNavigationBackHandler
import com.artemchep.keyguard.feature.navigation.N
import com.artemchep.keyguard.feature.navigation.NavigationController
import com.artemchep.keyguard.feature.navigation.NavigationIntent
import com.artemchep.keyguard.feature.navigation.NavigationRouterBackHandler
import com.artemchep.keyguard.feature.navigation.state.TranslatorScope
import com.artemchep.keyguard.platform.LeContext
import com.artemchep.keyguard.platform.recordException
import com.artemchep.keyguard.res.Res
import com.artemchep.keyguard.res.*
import com.artemchep.keyguard.ui.surface.LocalBackgroundManager
import com.artemchep.keyguard.ui.surface.LocalSurfaceColor
import com.artemchep.keyguard.ui.theme.KeyguardTheme
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.kodein.di.DIAware
import org.kodein.di.android.closestDI
import org.kodein.di.compose.rememberInstance
@ -75,6 +81,11 @@ abstract class BaseActivity : AppCompatActivity(), DIAware {
*/
private var lastUseExternalBrowser: Boolean = false
protected val translatorScope by lazy {
val context = LeContext(this)
TranslatorScope.of(context)
}
@OptIn(ExperimentalComposeUiApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -472,18 +483,26 @@ abstract class BaseActivity : AppCompatActivity(), DIAware {
}
private fun ShowMessage.internalShowNavigationErrorMessage(e: Throwable) {
Firebase.crashlytics.recordException(e)
recordException(e)
e.printStackTrace()
// Show an error message
lifecycleScope.launch {
val msg = when (e) {
is ActivityNotFoundException -> {
val title = translatorScope.translate(Res.string.error_failed_open_app_for)
ReadableExceptionMessage(title = title)
}
val model = ToastMessage(
type = ToastMessage.Type.ERROR,
title = when (e) {
is ActivityNotFoundException -> "No installed app can handle this request."
else -> "Something went wrong"
},
)
copy(model)
else -> getErrorReadableMessage(e, translatorScope)
}
val model = ToastMessage(
type = ToastMessage.Type.ERROR,
title = msg.title,
text = msg.text,
)
copy(model)
}
}
@Composable

View File

@ -495,6 +495,8 @@
<string name="error_failed_use_passkey">Failed to authorize a request</string>
<string name="error_failed_open_uri">Failed to open a URI</string>
<string name="error_failed_format_placeholder">Failed to format the placeholder</string>
<string name="error_failed_open_app_for">No installed app can handle this request</string>
<string name="error_failed_unknown">Something went wrong</string>
<string name="scanqr_title">Scan QR code</string>
<string name="scanqr_load_from_image_note">Load and parse a QR code from an image file.</string>
@ -611,6 +613,7 @@
<string name="urloverride_empty_label">No URL overrides</string>
<string name="setup_header_text">Create an encrypted vault where the local data will be stored.</string>
<string name="setup_free_text">By continuing you confirm that you have purchased the Keyguard or have had an active license.</string>
<string name="setup_field_app_password_label">App password</string>
<string name="setup_checkbox_biometric_auth">Biometric authentication</string>
<string name="setup_biometric_auth_confirm_title">Create a vault</string>
@ -927,6 +930,7 @@
<string name="changepassword_biometric_auth_confirm_title">Change app password</string>
<string name="changepassword_disclaimer_local_note">App password never gets stored on the device nor sent over the network. It is used to generate a secret key that is used to encrypt the local data.</string>
<string name="changepassword_disclaimer_abuse_note">Unless you suspect unauthorized access or discover a malware on the device, there is no need to change the password if it is a strong, unique password.</string>
<string name="changepassword_password_changed_successfully">Password changed successfully</string>
<string name="exportaccount_header_title">Export items</string>
<string name="exportaccount_password_label">Archive password</string>

View File

@ -173,7 +173,7 @@ private fun RememberStateFlowScope.ah(
.getCreateIo(currentPassword, newPassword)
.effectTap {
val msg = ToastMessage(
title = "Changed the password",
title = translate(Res.string.changepassword_password_changed_successfully),
type = ToastMessage.Type.SUCCESS,
)
message(msg)
@ -207,7 +207,7 @@ private fun RememberStateFlowScope.ah(
.getCreateIo(currentPassword, newPassword)
.effectTap {
val msg = ToastMessage(
title = "Changed the password",
title = translate(Res.string.changepassword_password_changed_successfully),
type = ToastMessage.Type.SUCCESS,
)
message(msg)

View File

@ -451,12 +451,6 @@ fun RememberStateFlowScope.createCipherSelectionFlow(
filteredCipherIds,
true,
)
.effectMap {
val message = ToastMessage(
title = "Add to favourites",
)
message(message)
}
.launchIn(appScope)
},
)
@ -478,12 +472,6 @@ fun RememberStateFlowScope.createCipherSelectionFlow(
filteredCipherIds,
false,
)
.effectMap {
val message = ToastMessage(
title = "Removed from favourites",
)
message(message)
}
.launchIn(appScope)
},
)

View File

@ -90,12 +90,6 @@ fun RememberStateFlowScope.cipherEnableConfirmAccessAction(
filteredCipherIds,
true,
)
.effectMap {
val message = ToastMessage(
title = "Auth re-prompt enabled",
)
message(message)
}
.launchIn(appScope)
},
)
@ -122,12 +116,6 @@ fun RememberStateFlowScope.cipherDisableConfirmAccessAction(
filteredCipherIds,
false,
)
.effectMap {
val message = ToastMessage(
title = "Auth re-prompt disabled",
)
message(message)
}
.biFlatTap(
ifException = {
ioEffect { after?.invoke(false) }
@ -299,12 +287,6 @@ fun RememberStateFlowScope.cipherCopyToAction(
cipher.id to ownership
}
copyCipherById(cipherIdsToOwnership)
.effectMap {
val message = ToastMessage(
title = "Copied ciphers!",
)
message(message)
}
.launchIn(appScope)
}
@ -383,12 +365,6 @@ fun RememberStateFlowScope.cipherMoveToFolderAction(
cipherIds,
destination,
)
.effectMap {
val message = ToastMessage(
title = "Moved to the folder",
)
message(message)
}
.launchIn(appScope)
}
@ -444,12 +420,6 @@ fun RememberStateFlowScope.cipherChangeNameAction(
.data
.mapValues { it.value as String }
changeCipherNameById(cipherIdsToNames)
.effectMap {
val message = ToastMessage(
title = "Changed names",
)
message(message)
}
.launchIn(appScope)
}
@ -518,12 +488,6 @@ fun RememberStateFlowScope.cipherChangePasswordAction(
.data
.mapValues { it.value as String }
changeCipherPasswordById(cipherIdsToPasswords)
.effectMap {
val message = ToastMessage(
title = "Changed passwords",
)
message(message)
}
.launchIn(appScope)
}
@ -601,12 +565,6 @@ fun RememberStateFlowScope.cipherTrashAction(
.map { it.id }
.toSet()
trashCipherById(cipherIds)
.effectMap {
val message = ToastMessage(
title = "Trashed",
)
message(message)
}
.launchIn(appScope)
}
@ -646,12 +604,6 @@ fun RememberStateFlowScope.cipherRestoreAction(
.map { it.id }
.toSet()
restoreCipherById(cipherIds)
.effectMap {
val message = ToastMessage(
title = "Restored",
)
message(message)
}
.launchIn(appScope)
}
@ -691,12 +643,6 @@ fun RememberStateFlowScope.cipherDeleteAction(
.map { it.id }
.toSet()
removeCipherById(cipherIds)
.effectMap {
val message = ToastMessage(
title = "Deleted",
)
message(message)
}
.launchIn(appScope)
}

View File

@ -304,7 +304,7 @@ private fun ColumnScope.SetupScreenCreateVaultTitle() {
if (isStandalone) {
Spacer(Modifier.height(8.dp))
Text(
text = "By continuing you confirm that you have purchased the Keyguard or have had an active license.",
text = stringResource(Res.string.setup_free_text),
style = MaterialTheme.typography.bodyMedium,
color = LocalContentColor.current
.combineAlpha(DisabledEmphasisAlpha),

View File

@ -8,11 +8,12 @@ import com.artemchep.keyguard.common.io.bind
import com.artemchep.keyguard.common.util.flow.EventFlow
import com.artemchep.keyguard.feature.navigation.state.TranslatorScope
import com.artemchep.keyguard.feature.navigation.state.translate
import com.artemchep.keyguard.res.Res
import com.artemchep.keyguard.res.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
class LoadingTask(
@ -94,7 +95,8 @@ suspend fun getErrorReadableMessage(e: Throwable, translator: TranslatorScope) =
}
else -> {
val title = e.message.orEmpty()
val title = e.message
?: translator.translate(Res.string.error_failed_unknown)
ReadableExceptionMessage(
title = title,
)