implement basic i18n

This commit is contained in:
mykola2312 2024-04-08 08:00:29 +03:00
parent 0e3886157a
commit 39dc9bf963
3 changed files with 33 additions and 1 deletions

View 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;
}
}
}

View file

@ -1,13 +1,18 @@
package com.mykola2312.mptv.ui;
import com.mykola2312.mptv.I18n;
import javax.swing.*;
public class MainFrame {
private JFrame frame;
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.setVisible(true);
}

View file

@ -0,0 +1 @@
MainFrame_Title=MPTV