Siema, chciałbym napisać wielojęzyczną aplikację, tylko nie wiem jak to zaimplementować...
Najlepsze rozwiązanie jakie mi przyszło do głowy:
public class Test extends JFrame {
private void msg(final String msg) {
JOptionPane.showMessageDialog(rootPane, msg);
}
public Test() {
Translator.language = Translator.Languages.PL;
JButton button = new JButton(Translator.get("Close"));
button.addActionListener( ae -> msg(Translator.get("You have entered a wrong value")));
add(button);
setSize(300, 300);
setDefaultCloseOperation(2);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Test().setVisible(true));
}
}
class Translator {
public enum Languages {
PL, EN, DE
}
public static String get(final String key) {
if(language == Languages.EN) return key;
switch(key) {
case "Close":
switch(language) {
case PL: return "Zamknij";
case DE: return "schließen";
}
case "You have entered a wrong value":
switch(language) {
case PL: return "Wprowadzono błędną wartość.";
case DE: return "Sie haben einen falschen Wert eingegeben";
}
default: return "";
}
}
public static Languages language = Languages.EN;
}
Język angielski jest kluczem.
Nie wiem, według mnie to trochę śmiesznie wygląda, dlatego szukam innego rozwiązania.
Jak Wy to robicie? :D