Skip to content

Commit bd47e8f

Browse files
committed
refactor: Improve how localized document names are retrieved
This commit refactors the logic for obtaining localized document names. - A new extension function `CredentialMetadata.getLocalizedDisplayName()` is introduced to directly retrieve the localized name, simplifying the call site. - `WalletCoreDocumentsController` is updated to use this new extension function, removing the previous usage of `ifEmptyOrNull` as the new function handles the fallback logic. - KDoc for the localization extension has been improved to be more accurate and clear.
1 parent 2aea13d commit bd47e8f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

core-logic/src/main/java/eu/europa/ec/corelogic/controller/WalletCoreDocumentsController.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package eu.europa.ec.corelogic.controller
1919
import androidx.core.net.toUri
2020
import eu.europa.ec.authenticationlogic.controller.authentication.DeviceAuthenticationResult
2121
import eu.europa.ec.authenticationlogic.model.BiometricCrypto
22-
import eu.europa.ec.businesslogic.extension.ifEmptyOrNull
2322
import eu.europa.ec.businesslogic.extension.safeAsync
2423
import eu.europa.ec.corelogic.config.WalletCoreConfig
2524
import eu.europa.ec.corelogic.extension.documentIdentifier
@@ -252,7 +251,7 @@ class WalletCoreDocumentsControllerImpl(
252251
metadata.flatMap { (issuer, meta) ->
253252
meta.credentialConfigurationsSupported.map { (id, config) ->
254253

255-
val name = config.credentialMetadata?.display?.getLocalizedDisplayName(
254+
val name: String = config.credentialMetadata.getLocalizedDisplayName(
256255
userLocale = locale,
257256
fallback = id.value
258257
)
@@ -270,7 +269,7 @@ class WalletCoreDocumentsControllerImpl(
270269
}
271270

272271
ScopedDocumentDomain(
273-
name = name.ifEmptyOrNull(id.value),
272+
name = name,
274273
configurationId = id.value,
275274
credentialIssuerId = issuer,
276275
formatType = formatType,

core-logic/src/main/java/eu/europa/ec/corelogic/extension/DisplayExtensions.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package eu.europa.ec.corelogic.extension
1818

1919
import eu.europa.ec.businesslogic.extension.getLocalizedString
20-
import eu.europa.ec.eudi.openid4vci.Display
20+
import eu.europa.ec.eudi.openid4vci.CredentialMetadata
2121
import eu.europa.ec.eudi.wallet.document.metadata.IssuerMetadata
22-
2322
import java.util.Locale
2423

2524
/**
@@ -49,23 +48,25 @@ fun List<IssuerMetadata.Claim.Display>?.getLocalizedClaimName(
4948
}
5049

5150
/**
52-
* Retrieves the localized display name from a list of [Display] objects based on the user's locale.
51+
* Retrieves the localized display name of a document based on the user's locale.
5352
*
54-
* This function searches through a list of [Display] objects to find a display name that matches
55-
* the provided [userLocale]. If a matching locale is found, the corresponding name is returned.
56-
* If no matching locale is found, the provided [fallback] string is returned.
53+
* This function attempts to find a localized version of the document's name
54+
* within the [CredentialMetadata.display] property of the [CredentialMetadata] object. If a localized
55+
* version matching the user's locale is found, it is returned. If no matching
56+
* localized version is found, a fallback string is returned instead.
5757
*
58-
* @param userLocale The user's locale to match against.
59-
* @param fallback The fallback string to use if no match is found.
60-
* @return The localized display name if found, otherwise the [fallback] string.
58+
* @param userLocale The user's locale, used to find a matching localized name.
59+
* @param fallback The string to return if no matching localized name is found.
60+
* @return The localized document name, or the fallback string if no matching localized name is available.
61+
* If [CredentialMetadata] or its display is null, it will return the [fallback].
6162
*
6263
* @see getLocalizedString
6364
*/
64-
fun List<Display>?.getLocalizedDisplayName(
65+
fun CredentialMetadata?.getLocalizedDisplayName(
6566
userLocale: Locale,
6667
fallback: String,
6768
): String {
68-
return this.getLocalizedString(
69+
return this?.display.getLocalizedString(
6970
userLocale = userLocale,
7071
localeExtractor = { it.locale },
7172
stringExtractor = { it.name },

0 commit comments

Comments
 (0)