It is necessary to create an object (It is possible even for each language to have a separate class) which stores all the messages in it. If necessary, display a message to the user depending on the language selected in the settings.
My application is going to support 3 languages: English Russian and Ukraine.
I decided to portray them like this.
public enum Language { RUSSIAN(1), ENGLISH(2), UKRAINE(3); private Integer id; Language(Integer id) { this.id = id; } public static Language reLang(Integer id) { switch (id) { case 1: return RUSSIAN; case 2: return ENGLISH; case 3: return UKRAINE; default: return RUSSIAN; } } public Integer getId() { return id; } } I store the selected user language as a numeric identifier: Russian - 1 English - 2 Ukrainian - 3
An example of how I get the user language.
User user = new User("UserName"); user.getLang(); // Получаю язык пользователя(enum). (Язык берется из базы данных Mysql). The next stage I go through is the output of the message to the user. Here I have problems because I have never done this before (Yes, and I don’t have the best type of implementation).
I created a class under
public class UtilChat { public static void message(Language lang, User user, Messages messages){ //Знаю можно было получать язык юзера здесь. а не в методе его вводить //отдельно } } By this statistical method, I am going to display a message to the user in the language of his choice. Here I have a question.
What is the best way I can store each message language?
There was an option for each language to create its own class, but it never came to me how to get the right messages from the class (taking into account the language).
Can eat somewhere already similar implementation?