Amplify-js: How to localize aws-amplify error messages

Created on 19 May 2018  路  10Comments  路  Source: aws-amplify/amplify-js

I tried to use aws-amplify i18n to localize error messages.
e.g. when user tries to signup with an existing username the following error is thrown:
{
code:"UsernameExistsException"
message:"User already exists"
name:"UsernameExistsException"
}
I tried to use i18n to get a localized error message, but I18n.get('UsernameExistsException') return the same UsernameExistsException code. How to localize aws-amplify error messages?

Could the reason be that the translation itself does not exist, so it fails back to default English message?

question

Most helpful comment

Where can we find all signup, signin, totp, sms confirmation, setup, etc error codes/messages?

All 10 comments

Please follow the user guide on how to properly use the i18n library:
https://aws.github.io/aws-amplify/media/i18n_guide
You can use the putVocabularies() method to put custom vocabulary dictionary, the input are key value pairs for a particular language.

Closing the issue. Feel free to reopen if you still have any question

@powerful23 can we reopen this issue as I have added the vocabulary but the error message still the same. The root cause if the angular authenticator component does not use i18n to get the message from the dictionary. I think it is great if we can provide a function to customize the error message

image

Auth.signUp just throws strings as errors. Besides setting a language with I18n from the amplify package does nothing for this, I have no way of localizing these errors.

@powerful23 I'm also looking to be able to localize error messages, but in react native. Currently the error message is a string returned from the server that does not use I18n.get to translate it. So adding a translation using putVocabularies won't work. Can we reopen the issue?

This is the reason I needed to build a totally custom UI on top of Amplify Auth as my app supports multi languages. Maybe Amplify should catch the error and provide its own error message which would make translation easier.

This is the reason I needed to build a totally custom UI on top of Amplify Auth as my app supports multi languages. Maybe Amplify should catch the error and provide its own error message which would make translation easier.

Do you have a good tutorial on that?

+1 Please open this issue?!

Where can we find all signup, signin, totp, sms confirmation, setup, etc error codes/messages?

Created PR 6301 to add I18n support for the Sign In errors. Hopefully it'll pass inspection/testing and get merged soon.

Was this page helpful?
0 / 5 - 0 ratings