Firebase error messages in different languages?

The display of Firebase error messages (error.message) in the view leads to a description of the errors in English (for example, for authentication errors, if user estimates contain errors).

How would you display messages in different languages ​​(best option: in phone language)?

+5
source share
3 answers

It's impossible now. I recommend using erros (error.code) code, which is a unique error code, and with this you can create something to associate this error code with your own text / language. There is an accessible page in the Firebase documentation that contains a list of those error codes that may help you. Check out these links: https://firebase.google.com/docs/reference/js/firebase.auth.Auth https://firebase.google.com/docs/reference/js/firebase.auth.Error https: // firebase.google.com/docs/auth/admin/errors?hl=en

Edit : To solve this problem, I translated it myself (in PT-BR, my language) and implemented (in TypeScript) the following steps:

I created an interface for storing an indexed array of strings:

export interface MessagesIndex { [index: string]: string; } 

Then, in some interface or error service, I declared this variable as the interface above:

 params = { 'invalid-argument': 'Erro: Um argumento inválido foi fornecido.', 'invalid-disabled-field': 'Erro: O valor fornecido para a propriedade de usuário é inválido.', /* ADD HERE THE OTHERs IDs AND THE CORRESPONDING MESSAGEs */ } as MessagesIndex; 

After that, I created a function to print it using the given code (from Firebase), do not forget to break it, because the error.code attribute comes as "auth / error-id", and we need only "error-id" here, and if the code no error was found, you can return some "Unknown error" and print error.code if you want:

  public printErrorByCode(code: string): string { code = code.split('/')[1]; if (this.params[code]) { return (this.params[code]); } else { return ('Ocorreu algum erro desconhecido! \n Codigo erro: ' + code); } } 

This is not the best code, but I hope this helps!

+3
source

The Firebase error message is intended for application developers, so it is only in English. Although we would like to provide them in the same languages ​​in which we provide our documentation, which will never cover all the languages ​​of your users.

Thus, you will have to detect the error in your code, register the error in the central system where you can check the problem, and then show the localized error message to your user.

As far as I know, there is no standard way to do this in Angular. But if there is, it will not be related to Firebase.

+2
source

Like Frederico Caesar

Localize Firebase Error Messages in PT-BR

https://gist.github.com/Albejr/a38cdeac247ef177986c99629680afb4

0
source

Source: https://habr.com/ru/post/1264683/


All Articles