2 firebase firebase-authentication
当我想在应用程序中重置密码时,我需要根据浏览器的语言更改发送消息的语言。这是我的 onSubmit 函数,我在提交表单上调用它来发送消息。我从状态中获取值并将其放入 languageCode 中。我用的是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,
},
})
})
}
Run Code Online (Sandbox Code Playgroud)
对于 Javascript - 版本 9
import { getAuth } from "firebase/auth"
const auth = getAuth()
auth.useDeviceLanguage() // detects language from user's device
Run Code Online (Sandbox Code Playgroud)
或者你可以手动设置
auth.languageCode = 'sk' // change messages to Slovak language
Run Code Online (Sandbox Code Playgroud)
https://firebase.google.com/docs/reference/js/auth.auth.md#authlanguagecode
| 归档时间: |
|
| 查看次数: |
11454 次 |
| 最近记录: |