I do not know if there is a direct way for the translation in java, but a solution can be with static classes. for example
public class Espanyol {
static final Map<String , String> PALABRAS = new HashMap<String , String>() {{
put("Hello", "Hola");
put("World", "Mundo");
}};
}
The same for English
public class ingles{
static final Map<String , String> PALABRAS = new HashMap<String , String>() {{
put("Hello", "Hello");
put("World", "World");
}};
}
Then you create a class that is the one that will identify the language
public class Traduccion {
private idioma;
public Traduccion(string idioma) {
this.idioma = idioma;
}
}
public string palabra(String key) {
if(idioma.equals("es")) {
return Espanyol.PALABRAS.get(key);
} else {
return Ingles.PALABRAS.get(key);
}
in your class you would have to create the translation object and pass the language to it.
Traduccion t = new Traduccion("es");
System.out.println(t.palabra("Hello") + t.palabra("world"));
This would print you hello world, if you change the label it would print you hello world