Skip to content

Commit f74c2a1

Browse files
committed
added custom string provider sample, tests for locale overrides
1 parent 7f29a25 commit f74c2a1

File tree

12 files changed

+374
-212
lines changed

12 files changed

+374
-212
lines changed

auth/src/main/java/com/firebase/ui/auth/compose/configuration/AuthUIConfiguration.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import android.content.Context
1818
import java.util.Locale
1919
import com.google.firebase.auth.ActionCodeSettings
2020
import androidx.compose.ui.graphics.vector.ImageVector
21+
import com.firebase.ui.auth.compose.configuration.stringprovider.AuthUIStringProvider
22+
import com.firebase.ui.auth.compose.configuration.stringprovider.DefaultAuthUIStringProvider
2123

2224
fun actionCodeSettings(block: ActionCodeSettings.Builder.() -> Unit) =
2325
ActionCodeSettings.newBuilder().apply(block).build()

auth/src/main/java/com/firebase/ui/auth/compose/configuration/PasswordRule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.firebase.ui.auth.compose.configuration
1616

17+
import com.firebase.ui.auth.compose.configuration.stringprovider.AuthUIStringProvider
18+
1719
/**
1820
* An abstract class representing a set of validation rules that can be applied to a password field,
1921
* typically within the [AuthProvider.Email] configuration.
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* Copyright 2025 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.compose.configuration.stringprovider
16+
17+
/**
18+
* An interface for providing localized string resources. This interface defines methods for all
19+
* user-facing strings, such as initializing(), signInWithGoogle(), invalidEmailAddress(),
20+
* passwordsDoNotMatch(), etc., allowing for complete localization of the UI.
21+
*
22+
* @sample AuthUIStringProviderSample
23+
*/
24+
interface AuthUIStringProvider {
25+
/** Loading text displayed during initialization or processing states */
26+
val initializing: String
27+
28+
/** Text for Google Provider */
29+
val googleProvider: String
30+
31+
/** Text for Facebook Provider */
32+
val facebookProvider: String
33+
34+
/** Text for Twitter Provider */
35+
val twitterProvider: String
36+
37+
/** Text for Github Provider */
38+
val githubProvider: String
39+
40+
/** Text for Phone Provider */
41+
val phoneProvider: String
42+
43+
/** Text for Email Provider */
44+
val emailProvider: String
45+
46+
/** Button text for Google sign-in option */
47+
val signInWithGoogle: String
48+
49+
/** Button text for Facebook sign-in option */
50+
val signInWithFacebook: String
51+
52+
/** Button text for Twitter sign-in option */
53+
val signInWithTwitter: String
54+
55+
/** Button text for Github sign-in option */
56+
val signInWithGithub: String
57+
58+
/** Button text for Email sign-in option */
59+
val signInWithEmail: String
60+
61+
/** Button text for Phone sign-in option */
62+
val signInWithPhone: String
63+
64+
/** Button text for Anonymous sign-in option */
65+
val signInAnonymously: String
66+
67+
/** Button text for Apple sign-in option */
68+
val signInWithApple: String
69+
70+
/** Button text for Microsoft sign-in option */
71+
val signInWithMicrosoft: String
72+
73+
/** Button text for Yahoo sign-in option */
74+
val signInWithYahoo: String
75+
76+
/** Error message when email address field is empty */
77+
val missingEmailAddress: String
78+
79+
/** Error message when email address format is invalid */
80+
val invalidEmailAddress: String
81+
82+
/** Generic error message for incorrect password during sign-in */
83+
val invalidPassword: String
84+
85+
/** Error message when password confirmation doesn't match the original password */
86+
val passwordsDoNotMatch: String
87+
88+
/** Error message when password doesn't meet minimum length requirement. Should support string formatting with minimum length parameter. */
89+
val passwordTooShort: String
90+
91+
/** Error message when password is missing at least one uppercase letter (A-Z) */
92+
val passwordMissingUppercase: String
93+
94+
/** Error message when password is missing at least one lowercase letter (a-z) */
95+
val passwordMissingLowercase: String
96+
97+
/** Error message when password is missing at least one numeric digit (0-9) */
98+
val passwordMissingDigit: String
99+
100+
/** Error message when password is missing at least one special character */
101+
val passwordMissingSpecialCharacter: String
102+
103+
// Email Authentication Strings
104+
/** Title for email signup form */
105+
val titleRegisterEmail: String
106+
107+
/** Hint for email input field */
108+
val emailHint: String
109+
110+
/** Hint for password input field */
111+
val passwordHint: String
112+
113+
/** Hint for new password input field */
114+
val newPasswordHint: String
115+
116+
/** Hint for name input field */
117+
val nameHint: String
118+
119+
/** Button text to save form */
120+
val buttonTextSave: String
121+
122+
/** Welcome back header for email users */
123+
val welcomeBackEmailHeader: String
124+
125+
/** Trouble signing in link text */
126+
val troubleSigningIn: String
127+
128+
// Phone Authentication Strings
129+
/** Phone number entry form title */
130+
val verifyPhoneNumberTitle: String
131+
132+
/** Hint for phone input field */
133+
val phoneHint: String
134+
135+
/** Hint for country input field */
136+
val countryHint: String
137+
138+
/** Invalid phone number error */
139+
val invalidPhoneNumber: String
140+
141+
/** Phone verification code entry form title */
142+
val enterConfirmationCode: String
143+
144+
/** Button text to verify phone number */
145+
val verifyPhoneNumber: String
146+
147+
/** Resend code countdown timer */
148+
val resendCodeIn: String
149+
150+
/** Resend code link text */
151+
val resendCode: String
152+
153+
/** Verifying progress text */
154+
val verifying: String
155+
156+
/** Wrong verification code error */
157+
val incorrectCodeDialogBody: String
158+
159+
/** SMS terms of service warning */
160+
val smsTermsOfService: String
161+
162+
// Provider Picker Strings
163+
/** Common button text for sign in */
164+
val signInDefault: String
165+
166+
/** Common button text for continue */
167+
val continueText: String
168+
169+
/** Common button text for next */
170+
val nextDefault: String
171+
172+
// General Error Messages
173+
/** General unknown error message */
174+
val errorUnknown: String
175+
176+
/** Required field error */
177+
val requiredField: String
178+
179+
/** Loading progress text */
180+
val progressDialogLoading: String
181+
182+
/** Network error message */
183+
val noInternet: String
184+
185+
/** TOTP Code prompt */
186+
val enterTOTPCode: String
187+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2025 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.compose.configuration.stringprovider
16+
17+
import android.content.Context
18+
import com.firebase.ui.auth.compose.configuration.AuthProvider
19+
import com.firebase.ui.auth.compose.configuration.AuthUIConfiguration
20+
import com.firebase.ui.auth.compose.configuration.authUIConfiguration
21+
22+
class AuthUIStringProviderSample {
23+
/**
24+
* Override specific strings while delegating others to default provider
25+
*/
26+
class CustomAuthUIStringProvider(
27+
private val defaultProvider: AuthUIStringProvider
28+
) : AuthUIStringProvider by defaultProvider {
29+
30+
// Override only the strings you want to customize
31+
override val signInWithGoogle: String = "Continue with Google • MyApp"
32+
override val signInWithFacebook: String = "Continue with Facebook • MyApp"
33+
34+
// Add custom branding to common actions
35+
override val continueText: String = "Continue to MyApp"
36+
override val signInDefault: String = "Sign in to MyApp"
37+
38+
// Custom MFA messaging
39+
override val enterTOTPCode: String =
40+
"Enter the 6-digit code from your authenticator app to secure your MyApp account"
41+
}
42+
43+
fun createCustomConfiguration(applicationContext: Context): AuthUIConfiguration {
44+
val customStringProvider =
45+
CustomAuthUIStringProvider(DefaultAuthUIStringProvider(applicationContext))
46+
return authUIConfiguration {
47+
context = applicationContext
48+
providers {
49+
provider(
50+
AuthProvider.Google(
51+
scopes = listOf(),
52+
serverClientId = ""
53+
)
54+
)
55+
}
56+
stringProvider = customStringProvider
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)