implement basic i18n
This commit is contained in:
parent
0e3886157a
commit
39dc9bf963
3 changed files with 33 additions and 1 deletions
26
src/main/java/com/mykola2312/mptv/I18n.java
Normal file
26
src/main/java/com/mykola2312/mptv/I18n.java
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.mykola2312.mptv;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class I18n {
|
||||||
|
private static ResourceBundle bundle;
|
||||||
|
|
||||||
|
public static String get(String key) {
|
||||||
|
if (bundle == null) {
|
||||||
|
String locale = Locale.getDefault().toString();
|
||||||
|
bundle = ResourceBundle.getBundle("i18n_" + locale);
|
||||||
|
if (bundle == null) {
|
||||||
|
bundle = ResourceBundle.getBundle("i18n_enUS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return bundle.getString(key);
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
System.err.println(e.toString());
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
package com.mykola2312.mptv.ui;
|
package com.mykola2312.mptv.ui;
|
||||||
|
|
||||||
|
import com.mykola2312.mptv.I18n;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class MainFrame {
|
public class MainFrame {
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
this.frame = new JFrame("MPTV");
|
this.frame = new JFrame(I18n.get("MainFrame_Title"));
|
||||||
|
|
||||||
|
frame.setUndecorated(true);
|
||||||
|
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
|
||||||
|
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
src/main/resources/i18n_en_US.properties
Normal file
1
src/main/resources/i18n_en_US.properties
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
MainFrame_Title=MPTV
|
||||||
Loading…
Add table
Reference in a new issue