Fix and add each label translation

This commit is contained in:
J-Jamet
2021-06-07 13:27:28 +02:00
parent d3d5a1745d
commit 42c8f0c345
8 changed files with 122 additions and 92 deletions

View File

@@ -41,12 +41,12 @@ import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.database.element.template.*
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_NOTES
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_PASSWORD
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_TITLE
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_URL
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_USERNAME
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_NOTES
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_PASSWORD
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_TITLE
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_URL
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_USERNAME
import com.kunzisoft.keepass.education.EntryEditActivityEducation
import com.kunzisoft.keepass.icons.IconDrawableFactory
import com.kunzisoft.keepass.model.EntryAttachmentState
@@ -190,7 +190,7 @@ class EntryEditFragment: DatabaseFragment() {
generatePasswordView,
{
GeneratePasswordDialogFragment
.getInstance(Field(STANDARD_PASSWORD, ProtectedString(true, mEntryInfo.password)))
.getInstance(Field(LABEL_PASSWORD, ProtectedString(true, mEntryInfo.password)))
.show(parentFragmentManager, "PasswordGeneratorFragment")
},
{
@@ -251,27 +251,27 @@ class EntryEditFragment: DatabaseFragment() {
val fieldTag: String
val fieldValue: String
when (templateAttribute.label.toLowerCase(Locale.ENGLISH)) {
STANDARD_TITLE -> {
when {
templateAttribute.label.equals(LABEL_TITLE, true) -> {
throw Exception("title cannot be in template attribute")
}
STANDARD_USERNAME -> {
templateAttribute.label.equals(LABEL_USERNAME, true) -> {
fieldTag = FIELD_USERNAME_TAG
fieldValue = mEntryInfo.username
}
STANDARD_PASSWORD -> {
templateAttribute.label.equals(LABEL_PASSWORD, true) -> {
fieldTag = FIELD_PASSWORD_TAG
fieldValue = mEntryInfo.password
}
STANDARD_URL -> {
templateAttribute.label.equals(LABEL_URL, true) -> {
fieldTag = FIELD_URL_TAG
fieldValue = mEntryInfo.url
}
STANDARD_EXPIRATION -> {
templateAttribute.label.equals(LABEL_EXPIRATION, true) -> {
fieldTag = FIELD_EXPIRES_TAG
fieldValue = mEntryInfo.getExpiresStringValue()
}
STANDARD_NOTES -> {
templateAttribute.label.equals(LABEL_NOTES, true) -> {
fieldTag = FIELD_NOTES_TAG
fieldValue = mEntryInfo.notes
}

View File

@@ -177,17 +177,17 @@ object AutofillHelper {
}
}
for (field in entryInfo.customFields) {
if (field.name == TemplateField.CREDIT_CARD_CARDHOLDER) {
if (field.name == TemplateField.LABEL_CARD_CARDHOLDER) {
struct.ccNameId?.let { ccNameId ->
builder.setValue(ccNameId, AutofillValue.forText(field.protectedValue.stringValue))
}
}
if (field.name == TemplateField.CREDIT_CARD_NUMBER) {
if (field.name == TemplateField.LABEL_NUMBER) {
struct.ccnId?.let { ccnId ->
builder.setValue(ccnId, AutofillValue.forText(field.protectedValue.stringValue))
}
}
if (field.name == TemplateField.CREDIT_CARD_CVV) {
if (field.name == TemplateField.LABEL_CVV) {
struct.cvvId?.let { cvvId ->
builder.setValue(cvvId, AutofillValue.forText(field.protectedValue.stringValue))
}

View File

@@ -26,11 +26,11 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.BUILD_ID
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.TEMPLATE_LABEL_VERSION
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_NOTES
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_PASSWORD
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_URL
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_USERNAME
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_NOTES
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_PASSWORD
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_URL
import com.kunzisoft.keepass.database.element.template.TemplateField.LABEL_USERNAME
import java.util.*
import kotlin.collections.ArrayList
@@ -119,16 +119,16 @@ class Template : Parcelable {
get() {
val sections = ArrayList<TemplateSection>()
val mainSection = TemplateSection(ArrayList<TemplateAttribute>().apply {
add(TemplateAttribute(STANDARD_USERNAME, TemplateAttributeType.INLINE))
add(TemplateAttribute(STANDARD_PASSWORD,
add(TemplateAttribute(LABEL_USERNAME, TemplateAttributeType.INLINE))
add(TemplateAttribute(LABEL_PASSWORD,
TemplateAttributeType.INLINE,
true,
"",
TemplateAttributeAction.PASSWORD_GENERATION)
)
add(TemplateAttribute(STANDARD_URL, TemplateAttributeType.INLINE))
add(TemplateAttribute(STANDARD_EXPIRATION, TemplateAttributeType.DATETIME))
add(TemplateAttribute(STANDARD_NOTES, TemplateAttributeType.MULTILINE))
add(TemplateAttribute(LABEL_URL, TemplateAttributeType.INLINE))
add(TemplateAttribute(LABEL_EXPIRATION, TemplateAttributeType.DATETIME))
add(TemplateAttribute(LABEL_NOTES, TemplateAttributeType.MULTILINE))
})
sections.add(mainSection)
return Template(DatabaseVersioned.UUID_ZERO,

View File

@@ -158,7 +158,10 @@ class TemplateEngine(private val mDatabase: DatabaseKDBX) {
return templateVersion?.let { version ->
val templateAttributes = arrayOfNulls<TemplateAttribute>(attributes.size)
attributes.values.forEach {
templateAttributes[it.position] = it.attribute
val attribute = it.attribute.apply {
this.label = decodeTemplateAttribute(this.label)
}
templateAttributes[it.position] = attribute
}
val templateSections = mutableListOf<TemplateSection>()
val templateSection = TemplateSection(templateAttributes.filterNotNull())
@@ -249,14 +252,24 @@ class TemplateEngine(private val mDatabase: DatabaseKDBX) {
private data class TemplateAttributePosition(var position: Int, var attribute: TemplateAttribute)
private val TAG = TemplateEngine::class.java.name
const val PREFIX_DECODED_TEMPLATE = "["
const val SUFFIX_DECODED_TEMPLATE = "]"
// Custom template ref
private const val TEMPLATE_ATTRIBUTE_TITLE = "@title"
private const val TEMPLATE_ATTRIBUTE_USERNAME = "@username"
private const val TEMPLATE_ATTRIBUTE_PASSWORD = "@password"
private const val TEMPLATE_ATTRIBUTE_URL = "@url"
private const val TEMPLATE_ATTRIBUTE_EXP_DATE = "@exp_date"
private const val TEMPLATE_ATTRIBUTE_EXPIRES = "@expires"
private const val TEMPLATE_ATTRIBUTE_NOTES = "@notes"
const val TEMPLATE_LABEL_VERSION = "_etm_template"
const val TEMPLATE_ENTRY_UUID = "_etm_template_uuid"
private const val TEMPLATE_ATTRIBUTE_POSITION_PREFIX = "_etm_position"
private const val TEMPLATE_ATTRIBUTE_TITLE_PREFIX = "_etm_title"
private const val TEMPLATE_ATTRIBUTE_TYPE_PREFIX = "_etm_type"
const val TEMPLATE_ATTRIBUTE_TITLE_EXPIRATION = "@exp_date"
private const val TEMPLATE_ATTRIBUTE_TYPE_PROTECTED = "Protected"
private const val TEMPLATE_ATTRIBUTE_TYPE_INLINE = "Inline"
private const val TEMPLATE_ATTRIBUTE_TYPE_MULTILINE = "Multiline"
@@ -270,5 +283,19 @@ class TemplateEngine(private val mDatabase: DatabaseKDBX) {
fun getDefaultTemplateGroupName(resources: Resources): String {
return resources.getString(R.string.templates)
}
fun decodeTemplateAttribute(name: String): String {
return when {
TEMPLATE_LABEL_VERSION.equals(name, true) -> TemplateField.LABEL_VERSION
TEMPLATE_ATTRIBUTE_TITLE.equals(name, true) -> TemplateField.LABEL_TITLE
TEMPLATE_ATTRIBUTE_USERNAME.equals(name, true) -> TemplateField.LABEL_USERNAME
TEMPLATE_ATTRIBUTE_PASSWORD.equals(name, true) -> TemplateField.LABEL_PASSWORD
TEMPLATE_ATTRIBUTE_URL.equals(name, true) -> TemplateField.LABEL_URL
TEMPLATE_ATTRIBUTE_EXP_DATE.equals(name, true) -> TemplateField.LABEL_EXPIRATION
TEMPLATE_ATTRIBUTE_EXPIRES.equals(name, true) -> TemplateField.LABEL_EXPIRATION
TEMPLATE_ATTRIBUTE_NOTES.equals(name, true) -> TemplateField.LABEL_NOTES
else -> name
}
}
}
}

View File

@@ -3,8 +3,6 @@ package com.kunzisoft.keepass.database.element.template
import android.content.Context
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.TEMPLATE_ATTRIBUTE_TITLE_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.TEMPLATE_LABEL_VERSION
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.PREFIX_DECODED_TEMPLATE
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.SUFFIX_DECODED_TEMPLATE
@@ -12,50 +10,38 @@ import com.kunzisoft.keepass.utils.UuidUtil
object TemplateField {
const val STANDARD_TITLE = "title"
const val STANDARD_USERNAME = "username"
const val STANDARD_PASSWORD = "password"
const val STANDARD_URL = "url"
const val STANDARD_EXPIRATION = "expires"
const val STANDARD_NOTES = "notes"
const val LABEL_TITLE = "Title"
const val LABEL_USERNAME = "Username"
const val LABEL_PASSWORD = "Password"
const val LABEL_URL = "URL"
const val LABEL_EXPIRATION = "Expires"
const val LABEL_NOTES = "Notes"
const val CREDIT_CARD_TITLE = "Credit Card"
const val CREDIT_CARD_CARDHOLDER = "Card holder"
const val CREDIT_CARD_NUMBER = "Number"
const val CREDIT_CARD_CVV = "CVV"
const val CREDIT_CARD_PIN = "PIN"
const val ID_CARD_TITLE = "ID Card"
const val ID_CARD_NUMBER = "Number"
const val ID_CARD_NAME = "Name"
const val ID_CARD_PLACE_OF_ISSUE = "Place of issue"
const val ID_CARD_DATE_OF_ISSUE = "Date of issue"
const val EMAIL_TITLE = "E-mail"
const val EMAIL_ADDRESS = "E-mail address"
const val EMAIL_URL = "URL"
const val EMAIL_PASSWORD = "Password"
const val WIRELESS_LAN_TITLE = "Wireless LAN"
const val WIRELESS_LAN_SSID = "SSID"
const val WIRELESS_LAN_PASSWORD = "Password"
const val SECURE_NOTE_TITLE = "Secure Note"
const val SECURE_NOTE_NOTES = "Notes"
const val MEMBERSHIP_TITLE = "Membership"
const val MEMBERSHIP_Number = "Number"
const val MEMBERSHIP_URL = "URL"
const val MEMBERSHIP_EXPIRATION = "@exp_date"
const val LABEL_VERSION = "Version"
const val LABEL_CREDIT_CARD = "Credit Card"
const val LABEL_CARD_CARDHOLDER = "Card holder"
const val LABEL_NUMBER = "Number"
const val LABEL_CVV = "CVV"
const val LABEL_PIN = "PIN"
const val LABEL_ID_CARD = "ID Card"
const val LABEL_NAME = "Name"
const val LABEL_PLACE_OF_ISSUE = "Place of issue"
const val LABEL_DATE_OF_ISSUE = "Date of issue"
const val LABEL_EMAIL_TITLE = "E-mail"
const val LABEL_EMAIL_ADDRESS = "E-mail address"
const val LABEL_WIRELESS_LAN = "Wireless LAN"
const val LABEL_SSID = "SSID"
const val LABEL_SECURE_NOTE = "Secure Note"
const val LABEL_MEMBERSHIP = "Membership"
fun isStandardFieldName(name: String): Boolean {
return arrayOf(
STANDARD_TITLE,
STANDARD_USERNAME,
STANDARD_PASSWORD,
STANDARD_URL,
STANDARD_EXPIRATION,
STANDARD_NOTES
LABEL_TITLE,
LABEL_USERNAME,
LABEL_PASSWORD,
LABEL_URL,
LABEL_EXPIRATION,
LABEL_NOTES
).firstOrNull { it.equals(name, true) } != null
}
@@ -65,24 +51,31 @@ object TemplateField {
&& name.endsWith(SUFFIX_DECODED_TEMPLATE))
return name
return when (name) {
STANDARD_TITLE -> context.getString(R.string.entry_title)
STANDARD_USERNAME -> context.getString(R.string.entry_user_name)
STANDARD_PASSWORD -> context.getString(R.string.entry_password)
STANDARD_URL -> context.getString(R.string.entry_url)
STANDARD_EXPIRATION -> context.getString(R.string.entry_expires)
TEMPLATE_ATTRIBUTE_TITLE_EXPIRATION -> context.getString(R.string.entry_expires)
STANDARD_NOTES -> context.getString(R.string.entry_notes)
return when {
LABEL_TITLE.equals(name, true) -> context.getString(R.string.entry_title)
LABEL_USERNAME.equals(name, true) -> context.getString(R.string.entry_user_name)
LABEL_PASSWORD.equals(name, true) -> context.getString(R.string.entry_password)
LABEL_URL.equals(name, true) -> context.getString(R.string.entry_url)
LABEL_EXPIRATION.equals(name, true) -> context.getString(R.string.entry_expires)
LABEL_NOTES.equals(name, true) -> context.getString(R.string.entry_notes)
TEMPLATE_LABEL_VERSION -> context.getString(R.string.templates_version)
LABEL_VERSION.equals(name, true) -> context.getString(R.string.version)
LABEL_CREDIT_CARD.equals(name, true) -> context.getString(R.string.credit_card)
LABEL_CARD_CARDHOLDER.equals(name, true) -> context.getString(R.string.credit_card_cardholder)
LABEL_NUMBER.equals(name, true) -> context.getString(R.string.credit_card_number)
LABEL_CVV.equals(name, true) -> context.getString(R.string.credit_card_security_code)
LABEL_PIN.equals(name, true) -> context.getString(R.string.credit_card_pin)
LABEL_ID_CARD.equals(name, true) -> context.getString(R.string.id_card)
LABEL_NAME.equals(name, true) -> context.getString(R.string.name)
LABEL_PLACE_OF_ISSUE.equals(name, true) -> context.getString(R.string.place_of_issue)
LABEL_DATE_OF_ISSUE.equals(name, true) -> context.getString(R.string.date_of_issue)
LABEL_EMAIL_TITLE.equals(name, true) -> context.getString(R.string.email)
LABEL_EMAIL_ADDRESS.equals(name, true) -> context.getString(R.string.email_address)
LABEL_WIRELESS_LAN.equals(name, true) -> context.getString(R.string.vireless_lan)
LABEL_SSID.equals(name, true) -> context.getString(R.string.ssid)
LABEL_SECURE_NOTE.equals(name, true) -> context.getString(R.string.secure_note)
LABEL_MEMBERSHIP.equals(name, true) -> context.getString(R.string.membership)
CREDIT_CARD_TITLE -> context.getString(R.string.credit_card)
CREDIT_CARD_CARDHOLDER -> context.getString(R.string.credit_card_cardholder)
CREDIT_CARD_NUMBER -> context.getString(R.string.credit_card_number)
CREDIT_CARD_CVV -> context.getString(R.string.credit_card_security_code)
CREDIT_CARD_PIN -> context.getString(R.string.credit_card_pin)
// TODO Others translations
else -> name
}
}

View File

@@ -168,7 +168,7 @@ class EntryInfo : NodeInfo {
creditCard?.let { cc ->
cc.cardholder?.let {
val v = ProtectedString(false, it)
addUniqueField(Field(TemplateField.CREDIT_CARD_CARDHOLDER, v))
addUniqueField(Field(TemplateField.LABEL_CARD_CARDHOLDER, v))
}
cc.expiration?.let {
expires = true
@@ -176,11 +176,11 @@ class EntryInfo : NodeInfo {
}
cc.number?.let {
val v = ProtectedString(false, it)
addUniqueField(Field(TemplateField.CREDIT_CARD_NUMBER, v))
addUniqueField(Field(TemplateField.LABEL_NUMBER, v))
}
cc.cvv?.let {
val v = ProtectedString(true, it)
addUniqueField(Field(TemplateField.CREDIT_CARD_CVV, v))
addUniqueField(Field(TemplateField.LABEL_CVV, v))
}
}
}

View File

@@ -41,7 +41,7 @@ class EntryViewModel: ViewModel() {
entry?.touch(modified = false, touchParents = false)
// To simplify template field visibility
entry?.let {
entry = mDatabase.decodeTemplateEntry(it)
// TODO entry = mDatabase.decodeTemplateEntry(it)
}
_entry.value = EntryHistory(entry, entryLastVersion, historyPosition)
} else {

View File

@@ -104,6 +104,17 @@
<string name="credit_card_number">Number</string>
<string name="credit_card_security_code">CVV</string>
<string name="credit_card_pin">PIN</string>
<string name="id_card">ID Card</string>
<string name="name">Name</string>
<string name="place_of_issue">Place of issue</string>
<string name="date_of_issue">Date of issue</string>
<string name="email">E-mail</string>
<string name="email_address">E-mail address</string>
<string name="vireless_lan">Wireless LAN</string>
<string name="ssid">SSID</string>
<string name="secure_note">Secure Note</string>
<string name="membership">Membership</string>
<string name="version">Version</string>
<string name="entry_otp">OTP</string>
<string name="entry_url">URL</string>
<string name="entry_user_name">Username</string>
@@ -380,7 +391,6 @@
<string name="templates_group_enable_title">Templates usage</string>
<string name="templates_group_enable_summary">Use dynamic templates to fill in the fields of an entry</string>
<string name="templates_group_uuid_title">Templates group</string>
<string name="templates_version">Version</string>
<string name="max_history_items_title">Maximum number</string>
<string name="max_history_items_summary">Limit the number of history items per entry</string>
<string name="max_history_size_title">Maximum size</string>