diff --git a/CHANGELOG.md b/CHANGELOG.md index 04955f5da..0c2143e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Bug introduced by PR [#482](https://github.com/dpa99c/cordova-plugin-firebasex/pull/482). * (Android) Add the Firebase Performance Monitoring Gradle plugin to monitor network traffic. * Resolves [#520](https://github.com/dpa99c/cordova-plugin-firebasex/issues/520). +* (Feature): Add setLanguageCode method for Firebase Auth + * Merged from PR [#527](https://github.com/dpa99c/cordova-plugin-firebasex/pull/527). # Version 11.0.1 * (iOS) Set the Sign In with Apple capability based on the `IOS_ENABLE_APPLE_SIGNIN` plugin variable. diff --git a/README.md b/README.md index f9b475679..e915e41b2 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ To help ensure this plugin is kept updated, new features are added and bugfixes - [verifyPhoneNumber](#verifyphonenumber) - [Android](#android-2) - [iOS](#ios-2) + - [setLanguageCode](#setLanguageCode) - [authenticateUserWithEmailAndPassword](#authenticateuserwithemailandpassword) - [authenticateUserWithGoogle](#authenticateuserwithgoogle) - [Android](#android-3) @@ -2550,6 +2551,17 @@ You can [set up reCAPTCHA verification for iOS](https://firebase.google.com/docs This adds the `REVERSED_CLIENT_ID` from the `GoogleService-Info.plist` to the list of custom URL schemes in your Xcode project, so you don't need to do this manually. +### setLanguageCode +Sets the user-facing language code for auth operations that can be internationalized, such as sendEmailVerification() or verifyPhoneNumber(). This language code should follow the conventions defined by the IETF in BCP47. + +**Parameters**: +- {string} lang - language to change, ex: 'fr' for french + +Example usage: + +```javascript + FirebasePlugin.setLanguageCode('fr'); // will switch to french +``` ### authenticateUserWithEmailAndPassword Authenticates the user with email/password-based user account to obtain a credential that can be used to sign the user in/link to an existing user account/reauthenticate the user. diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index c4bf4a82d..969ca9824 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -259,6 +259,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo } else if (action.equals("verifyPhoneNumber")) { this.verifyPhoneNumber(callbackContext, args); + } else if (action.equals("setLanguageCode")) { + this.setLanguageCode(callbackContext, args); } else if (action.equals("authenticateUserWithGoogle")) { this.authenticateUserWithGoogle(callbackContext, args); } else if (action.equals("authenticateUserWithApple")) { @@ -1456,6 +1458,27 @@ public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingTo }); } + public void setLanguageCode(final CallbackContext callbackContext, final JSONArray args){ + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String lang = args.getString(0); + + if(lang == null || lang.equals("")){ + callbackContext.error("Lang must be specified"); + return; + } + + FirebaseAuth.getInstance().setLanguageCode(lang); + + Log.d(TAG, "Language code setted to "+lang); + } catch (Exception e) { + handleExceptionWithContext(e, callbackContext); + } + } + }); + } + public void createUserWithEmailAndPassword(final CallbackContext callbackContext, final JSONArray args){ cordova.getThreadPool().execute(new Runnable() { public void run() { diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index 73c26e6cb..5656f0574 100644 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -10,6 +10,7 @@ // Authentication - (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command; +- (void)setLanguageCode:(CDVInvokedUrlCommand*)command; - (void)createUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command; - (void)signInUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command; - (void)authenticateUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m old mode 100644 new mode 100755 index b957a33f4..5cb510ec0 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -543,6 +543,16 @@ - (void)verifyPhoneNumber:(CDVInvokedUrlCommand *)command { } } +- (void)setLanguageCode:(CDVInvokedUrlCommand *)command { + NSString* lang = [command.arguments objectAtIndex:0]; + @try { + [FIRAuth auth].languageCode = lang; + NSLog(@"Language code setted to %@!", lang); + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } +} + - (void)createUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command { @try { NSString* email = [command.arguments objectAtIndex:0]; diff --git a/types/index.d.ts b/types/index.d.ts old mode 100644 new mode 100755 index 187f9226f..2b11ddfae --- a/types/index.d.ts +++ b/types/index.d.ts @@ -138,6 +138,11 @@ interface FirebasePlugin { timeOutDuration: number, fakeVerificationCode?: string ): void + setLanguageCode( + lang: string, + success?: () => void, + error?: (err: string) => void + ): void createUserWithEmailAndPassword( email: string, password: string,