2

I need to change the language of the message sent in accordance with the browser's language when I want to reset the password in my app. This is my onSubmit func, which i call on submit form to send message. I take value from state and put it into languageCode. I use redux

onSubmit = () => { let error = {} if (!this.state.email) error.email = <FormattedMessage id='common.error.empty' /> if (Object.keys(error).length) { this.setState({error}) return } this.props.languageCode(this.props.locale) this.props.doPasswordReset(this.state.email).then(() => { this.setState({openDialog: true}) }).catch(error => { this.setState({ error: { ...this.state.error, email: error.message, }, }) }) } 

3 Answers 3

5

thanks for @Frank van Puffelen, @Miyo Alpízar @Frederiko Cesar for thier anser in this question & this question

Firebase's error message are targeted at application developers, so are in English only. While we'd love to provide them in the same languages as we provide our documentation in, that will never cover all the languages of your users.

So you will have to detect the error in your code, log the error to a central system where you can inspect the problem and then show a localized error message to your user.

As far as I know there is no standardized way of doing that in Angular. But if there is, it'll be unrelated to Firebase.

Sign up to request clarification or add additional context in comments.

Comments

5

For Javascript - version 9

import { getAuth } from "firebase/auth" const auth = getAuth() auth.useDeviceLanguage() // detects language from user's device 

or you can set it manually

auth.languageCode = 'sk' // change messages to Slovak language 

https://firebase.google.com/docs/reference/js/auth.auth.md#authlanguagecode

1 Comment

Sadly, useDeviceLanguage() did not work for me, but auth.languageCode = 'de' worked. I ended up using RNLocalize in my react-native project to obatain language code: export const auth = (initializeAuth(app, { persistence: getReactNativePersistence(ReactNativeAsyncStorage), }).languageCode = RNLocalize.getLocales()[0]?.languageTag || 'de');
2

Use the languageCode property of Auth to specify a language for the user. Here is the entry for that in JS, but it's also available on iOS and Android.

2 Comments

this is my onSubmit func, i take lang from state and put it into this languageCode, but its not working
did u see firebase.auth().useDeviceLanguage();? ...not sure if it's what ur looking for but, ...maybe?