I have a Java program and I have more than one languages, I'm using i18n with this structure:
package languages;
import languages.it.ItLanguage;
enum ListLanguages {
IT,
EN,
FR
}
public class Languages {
ItLanguage language;
public Languages(ListLanguages lan) {
switch (lan) {
case IT: {
this.language = new ItLanguage();
break;
}
case EN: {
// this.language = new EnLanguage();
break;
}
}
}
public String[] getStrings(String item) {
return this.language.getStringArray(item);
}
public String getString(String item) {
return this.language.getString(item);
}
}
I wish to call the constructor Languages passing the language to use and after to call this object to have the string, like in following way:
Languages lan = new Languages(it);
lan.getString("s1");
[...]
Languages lan = new Languages(fr);
lan.getString("s2");
But I cannot find a solution to avoid the switch inside the methods like getString:
switch(languageChosen) {
case("it"): return this.itLanguage.getString(item);
case("en"): return this.enLanguage.getString(item);
}
is there a solution to avoid this switch`?
The other class (for more information) is:
package it.bper.languages.it;
import java.util.ListResourceBundle;
public class ItLanguage extends ListResourceBundle {
@Override
protected Object[][] getContents() {
return new Object[][] {
{"name", "Pippo"},
{
"ourfeatures", new String[]
{
"Б, Г, Д, ё, Ж, П, Ф, И, й, Л, Ц, Ш, Щ, Э, e Ю Я",
"Null",
"Empty"
}
}
};
}
}