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 Answers3

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.

Community
  • 1
  • 1
tabebqena
  • 1,204
  • 1
  • 13
  • 23
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

miro
  • 735
  • 8
  • 16
  • 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'); – Adam Ri Aug 29 '23 at 10:27
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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Jen Person
  • 7,356
  • 22
  • 30
  • this is my onSubmit func, i take lang from state and put it into this languageCode, but its not working –  Aug 08 '18 at 08:11
  • did u see `firebase.auth().useDeviceLanguage();`? ...not sure if it's what ur looking for but, ...maybe? – Ronnie Royston Aug 09 '18 at 03:02