Skip to content

Commit bcfbf4f

Browse files
feat: utilise string localisations
1 parent a29ab0a commit bcfbf4f

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Utils/StringUtils.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import FirebaseAuth
22
import SwiftUI
33

4+
let kAuthPickerTitle = "AuthPickerTitle"
5+
6+
let kEnterYourEmail = "EnterYourEmail"
7+
let kEnterYourPassword = "EnterYourPassword"
8+
9+
let kSignedInTitle = "SignedIn"
10+
411
let kKeyNotFound = "Key not found"
512

613
let kUsersNotFoundError = "UserNotFoundError"
@@ -19,7 +26,7 @@ public class StringUtils {
1926
self.bundle = bundle
2027
}
2128

22-
public func localizedString(forKey key: String) -> String {
29+
public func localizedString(for key: String) -> String {
2330
let keyLocale = String.LocalizationValue(key)
2431
let value = String(localized: keyLocale, bundle: bundle)
2532
return value
@@ -31,27 +38,27 @@ public class StringUtils {
3138
switch errorCode {
3239
case .emailAlreadyInUse:
3340
return localizedString(
34-
forKey: kEmailAlreadyInUseError
41+
for: kEmailAlreadyInUseError
3542
)
3643
case .invalidEmail:
37-
return localizedString(forKey: kInvalidEmailError)
44+
return localizedString(for: kInvalidEmailError)
3845
case .weakPassword:
39-
return localizedString(forKey: kWeakPasswordError)
46+
return localizedString(for: kWeakPasswordError)
4047
case .tooManyRequests:
4148
return localizedString(
42-
forKey: kSignUpTooManyTimesError
49+
for: kSignUpTooManyTimesError
4350
)
4451
case .wrongPassword:
4552
return localizedString(
46-
forKey: kWrongPasswordError
53+
for: kWrongPasswordError
4754
)
4855
case .userNotFound:
4956
return localizedString(
50-
forKey: kUsersNotFoundError
57+
for: kUsersNotFoundError
5158
)
5259
case .userDisabled:
5360
return localizedString(
54-
forKey: kAccountDisabledError
61+
for: kAccountDisabledError
5562
)
5663
default:
5764
return error.localizedDescription

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public struct AuthPickerView<Content: View> {
1818
extension AuthPickerView: View {
1919
public var body: some View {
2020
VStack {
21+
Text(authService.string.localizedString(for: kAuthPickerTitle))
22+
.font(.largeTitle)
23+
.fontWeight(.bold)
24+
.padding()
2125
if authService.authenticationState == .authenticated {
2226
SignedInView()
2327
} else if authService.authView == .passwordRecovery {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EmailAuthView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension EmailAuthView: View {
5050
public var body: some View {
5151
VStack {
5252
LabeledContent {
53-
TextField("Email", text: $email)
53+
TextField(authService.string.localizedString(for: kEnterYourEmail), text: $email)
5454
.textInputAutocapitalization(.never)
5555
.disableAutocorrection(true)
5656
.focused($focus, equals: .email)
@@ -66,7 +66,7 @@ extension EmailAuthView: View {
6666
.padding(.bottom, 4)
6767

6868
LabeledContent {
69-
SecureField("Password", text: $password)
69+
SecureField(authService.string.localizedString(for: kEnterYourPassword), text: $password)
7070
.focused($focus, equals: .password)
7171
.submitLabel(.go)
7272
.onSubmit {

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ extension SignedInView: View {
1515

1616
public var body: some View {
1717
VStack {
18-
Text("Signed in")
18+
Text(authService.string.localizedString(for: kSignedInTitle))
19+
.font(.largeTitle)
20+
.fontWeight(.bold)
21+
.padding()
1922
Text("User: \(authService.currentUser?.email ?? "Unknown")")
2023

2124
if authService.currentUser?.isEmailVerified == false {

0 commit comments

Comments
 (0)