Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked Localization Mechanism, refactored all localized parts of the wallet #247

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Modules/feature-common/Sources/Config/BiometricUiConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ import Foundation
public extension UIConfig {
struct Biometry: UIConfigType, Equatable {

public let navigationTitle: LocalizableString.Key
public let navigationTitle: LocalizableStringKey
public let displayLogo: Bool
public let title: LocalizableString.Key
public let caption: LocalizableString.Key
public let quickPinOnlyCaption: LocalizableString.Key
public let title: LocalizableStringKey
public let caption: LocalizableStringKey
public let quickPinOnlyCaption: LocalizableStringKey
public let navigationSuccessType: ThreeWayNavigationType
public let navigationBackType: ThreeWayNavigationType?
public let isPreAuthorization: Bool
public let shouldInitializeBiometricOnCreate: Bool

public var log: String {
return "navigationTitle: \(LocalizableString.shared.get(with: navigationTitle))" +
return "navigationTitle: \(navigationTitle.toString)" +
"displayLogo: \(displayLogo)" +
"title: \(LocalizableString.shared.get(with: title))" +
"title: \(title.toString)" +
" onSuccessNav: \(navigationSuccessType.key)" +
" onBackNav: \(navigationBackType?.key ?? "none")" +
" isPreAuthorization: \(isPreAuthorization)" +
" shouldInitializeBiometricOnCreate: \(shouldInitializeBiometricOnCreate)"
}

public init(
navigationTitle: LocalizableString.Key,
navigationTitle: LocalizableStringKey,
displayLogo: Bool = true,
title: LocalizableString.Key,
caption: LocalizableString.Key,
quickPinOnlyCaption: LocalizableString.Key,
title: LocalizableStringKey,
caption: LocalizableStringKey,
quickPinOnlyCaption: LocalizableStringKey,
navigationSuccessType: ThreeWayNavigationType,
navigationBackType: ThreeWayNavigationType?,
isPreAuthorization: Bool,
Expand Down
6 changes: 3 additions & 3 deletions Modules/feature-common/Sources/Config/ScannerUiConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public extension ScannerUiConfig {
case presentation
case issuing(IssuanceFlowUiConfig)

var title: LocalizableString.Key {
var title: LocalizableStringKey {
return switch self {
case .presentation:
.scannerQrTitlePresentation
Expand All @@ -45,7 +45,7 @@ public extension ScannerUiConfig {
}
}

var caption: LocalizableString.Key {
var caption: LocalizableStringKey {
return switch self {
case .presentation:
.scannerQrCaptionPresentation
Expand All @@ -54,7 +54,7 @@ public extension ScannerUiConfig {
}
}

var informativeText: LocalizableString.Key {
var informativeText: LocalizableStringKey {
return .qrScanInformativeText
}

Expand Down
18 changes: 9 additions & 9 deletions Modules/feature-common/Sources/Config/SuccessUiConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public extension UIConfig {
struct Success: UIConfigType, Equatable {

public let title: Title
public let subtitle: LocalizableString.Key
public let subtitle: LocalizableStringKey
public let buttons: [Success.Button]
public let visualKind: VisualKind

public var log: String {
return "title: \(LocalizableString.shared.get(with: title.value))" +
return "title: \(title.value.toString)" +
"title color: \(title.color)" +
" caption: \(LocalizableString.shared.get(with: subtitle))" +
" buttons: \(buttons.map({ LocalizableString.shared.get(with: $0.title) as String }).joined(separator: ","))" +
" caption: \(subtitle.toString)" +
" buttons: \(buttons.map({ $0.title.toString }).joined(separator: ","))" +
" actions: \(buttons.map(\.navigationType.type).joined(separator: ","))"
}

public init(
title: Title,
subtitle: LocalizableString.Key,
subtitle: LocalizableStringKey,
buttons: [Success.Button],
visualKind: VisualKind
) {
Expand All @@ -52,11 +52,11 @@ public extension UIConfig {

public extension UIConfig.Success {
struct Title: Equatable, Sendable {
public let value: LocalizableString.Key
public let value: LocalizableStringKey
public let color: Color

public init(
value: LocalizableString.Key,
value: LocalizableStringKey,
color: Color = Theme.shared.color.success
) {
self.value = value
Expand All @@ -77,7 +77,7 @@ public extension UIConfig.Success {
@EquatableNoop
public var id: UUID

public let title: LocalizableString.Key
public let title: LocalizableStringKey
public let style: Style
public let navigationType: UIConfig.DeepLinkNavigationType

Expand All @@ -87,7 +87,7 @@ public extension UIConfig.Success {
}

public init(
title: LocalizableString.Key,
title: LocalizableStringKey,
style: Style,
navigationType: UIConfig.DeepLinkNavigationType
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public struct AddNewDocumentCellView: View {

let isEnabled: Bool
let icon: Image?
let title: LocalizableString.Key
let title: LocalizableStringKey
let action: () -> Void
let isLoading: Bool

public init(
isEnabled: Bool,
icon: Image? = nil,
title: LocalizableString.Key,
title: LocalizableStringKey,
isLoading: Bool,
action: @autoclosure @escaping () -> Void
) {
Expand Down Expand Up @@ -83,7 +83,7 @@ public struct AddNewDocumentCellView: View {
AddNewDocumentCellView(
isEnabled: true,
icon: Image(systemName: "person.text.rectangle"),
title: LocalizableString.Key.addDocumentTitle,
title: LocalizableStringKey.addDocumentTitle,
isLoading: false,
action: {}()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct AddDocumentOptionsViewState: ViewState {
let isLoading: Bool
let error: ContentErrorView.Config?
let config: IssuanceFlowUiConfig
let title: LocalizableString.Key
let title: LocalizableStringKey
}

open class AddDocumentOptionsViewModel<Router: RouterHost>: ViewModel<Router, AddDocumentOptionsViewState> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ open class BaseLoadingViewModel<Router: RouterHost>: ViewModel<Router, BaseLoadi
}
}

open func getTitle() -> LocalizableString.Key {
open func getTitle() -> LocalizableStringKey {
return .custom("")
}

open func getCaption() -> LocalizableString.Key {
open func getCaption() -> LocalizableStringKey {
return .custom("")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private func content(
private func pinView(
uiPinInputField: Binding<String>,
quickPinSize: Int,
pinError: LocalizableString.Key?
pinError: LocalizableStringKey?
) -> some View {
VStack(spacing: .zero) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ enum QuickPinStep {
@Copyable
struct QuickPinState: ViewState {
let config: QuickPinUiConfig
let navigationTitle: LocalizableString.Key
let title: LocalizableString.Key
let caption: LocalizableString.Key
let button: LocalizableString.Key
let success: LocalizableString.Key
let successButton: LocalizableString.Key
let navigationTitle: LocalizableStringKey
let title: LocalizableStringKey
let caption: LocalizableStringKey
let button: LocalizableStringKey
let success: LocalizableStringKey
let successButton: LocalizableStringKey
let successNavigationType: UIConfig.DeepLinkNavigationType
let isCancellable: Bool
let pinError: LocalizableString.Key?
let pinError: LocalizableStringKey?
let isButtonActive: Bool
let step: QuickPinStep
let quickPinSize: Int
Expand Down Expand Up @@ -161,7 +161,7 @@ final class QuickPinViewModel<Router: RouterHost>: ViewModel<Router, QuickPinSta
private func onSuccess() {
interactor.setPin(newPin: uiPinInputField)

let buttonTitle: LocalizableString.Key = viewState.config.isSetFlow ?
let buttonTitle: LocalizableStringKey = viewState.config.isSetFlow ?
.walletIsSecured :
.successTitlePunctuated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public struct RequestViewState: ViewState {
public let error: ContentErrorView.Config?
public let showMissingCrredentials: Bool
public let items: [RequestDataUI]
public let trustedRelyingPartyInfo: LocalizableString.Key
public let relyingParty: LocalizableString.Key
public let trustedRelyingPartyInfo: LocalizableStringKey
public let relyingParty: LocalizableStringKey
public let isTrusted: Bool
public let allowShare: Bool
public let originator: AppRoute
Expand Down Expand Up @@ -65,39 +65,39 @@ open class BaseRequestViewModel<Router: RouterHost>: ViewModel<Router, RequestVi

open func doWork() async {}

open func getTitle() -> LocalizableString.Key {
open func getTitle() -> LocalizableStringKey {
return .custom("")
}

open func getRelyingParty() -> LocalizableString.Key {
open func getRelyingParty() -> LocalizableStringKey {
return .custom("")
}

open func getRelyingPartyIsTrusted() -> Bool {
return false
}

open func getCaption() -> LocalizableString.Key {
open func getCaption() -> LocalizableStringKey {
return .custom("")
}

open func getDataRequestInfo() -> LocalizableString.Key {
open func getDataRequestInfo() -> LocalizableStringKey {
return .custom("")
}

open func getSuccessRoute() -> AppRoute? {
return nil
}

open func getTitleCaption() -> String {
return ""
open func getTitleCaption() -> LocalizableStringKey {
return .custom("")
}

open func getTrustedRelyingParty() -> LocalizableString.Key {
open func getTrustedRelyingParty() -> LocalizableStringKey {
return .custom("")
}

open func getTrustedRelyingPartyInfo() -> LocalizableString.Key {
open func getTrustedRelyingPartyInfo() -> LocalizableStringKey {
return .custom("")
}

Expand Down Expand Up @@ -145,8 +145,8 @@ open class BaseRequestViewModel<Router: RouterHost>: ViewModel<Router, RequestVi

public func onReceivedItems(
with items: [RequestDataUI],
title: LocalizableString.Key,
relyingParty: LocalizableString.Key,
title: LocalizableStringKey,
relyingParty: LocalizableStringKey,
isTrusted: Bool
) {
setState {
Expand Down
42 changes: 26 additions & 16 deletions Modules/feature-common/Sources/UI/Scanner/ScannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,40 @@ private func content(
textColor: Theme.shared.color.white,
onClick: { onErrorClick() }
)
.padding()
}
informativeText(viewState: viewState)
}
.animation(.easeInOut, value: viewState.showInformativeText)
}
.ignoresSafeArea(.all, edges: .bottom)
}

VStack {
Spacer()
HStack(spacing: SPACING_MEDIUM) {
@MainActor
@ViewBuilder
private func informativeText(viewState: ScannerState) -> some View {
ZStack {
VStack {
HStack(spacing: SPACING_MEDIUM) {

Theme.shared.image.errorIndicator
.renderingMode(.template)
.foregroundStyle(Theme.shared.color.white)
Theme.shared.image.errorIndicator
.renderingMode(.template)
.foregroundStyle(Theme.shared.color.onSurface)

Text(viewState.informativeTest)
.typography(Theme.shared.font.bodyLarge)
.foregroundStyle(Theme.shared.color.white)
.multilineTextAlignment(.center)
Text(viewState.informativeTest)
.typography(Theme.shared.font.bodyLarge)
.foregroundStyle(Theme.shared.color.onSurface)
.multilineTextAlignment(.center)

}
}
.padding(.horizontal)
.padding(.bottom, SPACING_LARGE)
.frame(maxWidth: .infinity)
}
.animation(.easeInOut, value: viewState.showInformativeText)
.padding()
.background(Theme.shared.color.surfaceContainer)
.clipShape(Theme.shared.shape.highCornerRadiusShape)
.opacity(viewState.showInformativeText ? 1.0 : 0.0)
}
.ignoresSafeArea(.all, edges: .bottom)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.padding(.bottom, SPACING_LARGE)
}

#Preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import logic_business
struct ScannerState: ViewState {

let config: ScannerUiConfig
let error: LocalizableString.Key?
let error: LocalizableStringKey?
let showInformativeText: Bool
let informativeTest: LocalizableString.Key
let informativeTest: LocalizableStringKey
let allowScanning: Bool
let failedScanAttempts: Int

var title: LocalizableString.Key {
var title: LocalizableStringKey {
return config.flow.title
}

var caption: LocalizableString.Key {
var caption: LocalizableStringKey {
return config.flow.caption
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct BaseSuccessState: ViewState {
let config: DocumentSuccessUIConfig
let relyingParty: RelyingPartyData
let items: [ListItemSection]
let navigationTitle: String
let navigationTitle: LocalizableStringKey
let isLoading: Bool
}

Expand Down Expand Up @@ -70,7 +70,9 @@ open class BaseSuccessViewModel<Router: RouterHost>: ViewModel<Router, BaseSucce
}
)
},
navigationTitle: config.relyingPartyIsTrusted ? LocalizableString.shared.get(with: .documentAdded) : LocalizableString.shared.get(with: .dataShared),
navigationTitle: config.relyingPartyIsTrusted
? .documentAdded
: .dataShared,
isLoading: false
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private func getCenteredIcon(
subtitle: .issuanceSuccessDeferredCaption(["Name"]),
buttons: [
.init(
title: LocalizableString.Key.okButton,
title: LocalizableStringKey.okButton,
style: .primary,
navigationType: UIConfig.DeepLinkNavigationType.push(screen: .featureDashboardModule(.dashboard))
)
Expand Down
Loading