fleencorp / fleen-feen

Fleen Feen connects you with the world
GNU General Public License v3.0
0 stars 1 forks source link

Add Message Code for all Exception Class #29

Open aalamu opened 2 weeks ago

aalamu commented 2 weeks ago

Description

Add message code for the purpose of localization in all exception classes and test that the code in each exception class works correctly with the help of simple MessageSourceApp class and you are able to retrieve the equivalent message.

You can switch between the two Locale.FR and Locale.US

For example in the

com.fleencorp.feen.exception.auth

There is an exception class AlreadySignedUpException that has a code already.signed.up that is a reference to a code or key in

resources/i18n/errors/messages_en_US.properties

and

resources/i18n/errors/messages_fr.properties

You will find the key and message

already.signed.up=This profile is already signed up and has completed the registration process. for the English message file

and

already.signed.up=Ce profil est déjà inscrit et a terminé le processus d'enregistrement. for the French message file.

There is a class MessageSourceApp that has a main method that contains sample code that test if a message code is valid and if it is valid, it retrieves and print the actual message.

There is another class InvalidAuthenticationException in the same package. You can add a code like

invalid.authentication

and add the equivalent key in the messages file both for English and French Locale and set the appropriate message.

For example: In the InvalidAuthenticationException class. the error message reads

The username or password credential is invalid. ID: %s

but when adding this to the message file it should be

invalid.authentication=The username or password credential is invalid. ID: {0}

If you have another message that reads

The user with username %s has been banned on the date of %s in an exception class BannedUserException

It should be

banned.user=The user with username {0} has been banned on the date of {1}

For help with translation of text in English to French, please go to https://chat.openai.com/

and tell ChatGpt *to give you the equivalent of

banned.user=The user with username {0} has been banned on the date of {1}

to French*

and for subsequent conversations, you can just say

For banned.user=The user with username {0} has been banned on the date of {1}

When you want to run to confirm if a localization code works and the correct message is printed correctly. You can just press or click the play button on the left hand side of the main method.

Screenshot 2024-09-09 at 13 56 53

Note