Adds localization

This commit is contained in:
Markil3
2021-09-05 15:46:55 -06:00
parent c24d6c2367
commit d453135e03
7 changed files with 120 additions and 29 deletions

View File

@@ -12,12 +12,16 @@ import edu.regis.universeplayer.data.Album;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* This panel will display information on an album.
*/
public class AlbumInfo extends JButton
{
private static final ResourceBundle langs = ResourceBundle.getBundle("lang.interface", Locale.getDefault());
public Album album;
public final JLabel artLabel;
public final JLabel albumName;
@@ -38,13 +42,13 @@ public class AlbumInfo extends JButton
this.artLabel = new JLabel();
this.add(this.artLabel);
this.albumName = new JLabel("Album");
this.albumName = new JLabel(langs.getString("albumInfo.album"));
this.add(this.albumName);
this.artists = new JLabel("Artists");
this.artists = new JLabel(langs.getString("albumInfo.artists"));
this.add(this.artists);
this.genres = new JLabel("Genres");
this.genres = new JLabel(langs.getString("albumInfo.genres"));
this.add(this.genres);
this.year = new JLabel("20XX");
this.year = new JLabel(langs.getString("albumInfo.year"));
this.add(this.year);
/*

View File

@@ -9,12 +9,11 @@ import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.plaf.LabelUI;
import edu.regis.universeplayer.ClickListener;
import edu.regis.universeplayer.data.CollectionType;
import edu.regis.universeplayer.data.Song;
import edu.regis.universeplayer.data.SongProvider;
@@ -27,6 +26,8 @@ import edu.regis.universeplayer.data.SongProvider;
*/
public class Collections extends JPanel
{
private static final ResourceBundle langs = ResourceBundle.getBundle("lang.interface", Locale.getDefault());
/**
* A list of all things interested in knowing when we click a collection.
*/
@@ -44,35 +45,35 @@ public class Collections extends JPanel
this.setFocusable(true);
this.setFocusCycleRoot(true);
this.add(defaultLabel = label = this.createButton("All Songs"));
this.add(defaultLabel = label = this.createButton(langs.getString("collections.all")));
label.setMnemonic('A');
label.addActionListener(mouseEvent -> this
.triggerSongDisplayListeners(new ArrayList<>(SongProvider.INSTANCE.getSongs())));
this.add(label = this.createButton("Artists"));
this.add(label = this.createButton(langs.getString("collections.artists")));
label.setMnemonic('T');
label.addActionListener(mouseEvent -> this
.triggerCollectionDisplayListeners(CollectionType.albumArtist, SongProvider.INSTANCE
.getAlbumArtists()));
this.add(label = this.createButton("Albums"));
this.add(label = this.createButton(langs.getString("collections.albums")));
label.setMnemonic('B');
label.addActionListener(mouseEvent -> this
.triggerCollectionDisplayListeners(CollectionType.album, SongProvider.INSTANCE
.getAlbums()));
this.add(label = this.createButton("Genres"));
this.add(label = this.createButton(langs.getString("collections.genres")));
label.setMnemonic('G');
label.addActionListener(mouseEvent -> this
.triggerCollectionDisplayListeners(CollectionType.genre, SongProvider.INSTANCE
.getGenres()));
this.add(label = this.createButton("Years"));
this.add(label = this.createButton(langs.getString("collections.years")));
label.setMnemonic('Y');
label.addActionListener(mouseEvent -> this
.triggerCollectionDisplayListeners(CollectionType.year, SongProvider.INSTANCE
.getYears()));
this.add(new JLabel("\u23AF".repeat(6)));
this.add(label = this.createButton("Playlists"));
this.add(label = this.createButton(langs.getString("collections.playlists")));
label.setMnemonic('P');
this.add(new JLabel("\u23AF".repeat(6)));
this.add(label = this.createButton("Add External Song"));
this.add(label = this.createButton(langs.getString("actions.external.add.title")));
label.setMnemonic('E');
label.addActionListener(mouseEvent -> this.addNewSong());

View File

@@ -23,6 +23,8 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
/**
@@ -33,7 +35,11 @@ import java.util.Set;
*/
public class Interface extends JFrame implements SongDisplayListener, ComponentListener, WindowListener, UpdateListener, FocusListener
{
// static {
// Locale.setDefault(new Locale("es", "ES"));
// }
private static final Logger logger = LoggerFactory.getLogger(Interface.class);
private static final ResourceBundle langs = ResourceBundle.getBundle("lang.interface", Locale.getDefault());
private static File dataDir;
private static File commDir;
@@ -129,13 +135,13 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL
catch (IOException e)
{
logger.error("Could not open browser background", e);
JOptionPane.showMessageDialog(inter, e, "Could not open browser background", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(inter, e, langs.getString("error.browser.launch"), JOptionPane.ERROR_MESSAGE);
}
}
catch (Throwable e)
{
logger.error("Could not open browser background", e);
JOptionPane.showMessageDialog(inter != null && inter.isVisible() ? inter : null, e, "Error!", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(inter != null && inter.isVisible() ? inter : null, e, langs.getString("error.generic"), JOptionPane.ERROR_MESSAGE);
}
}
@@ -215,7 +221,7 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL
{
super();
this.setTitle("Universal Music Player");
this.setTitle(langs.getString("title"));
this.getContentPane().setLayout(new BorderLayout());
this.setFocusable(true);
this.setFocusCycleRoot(true);

View File

@@ -15,6 +15,8 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -24,6 +26,7 @@ import java.util.concurrent.Future;
public class InternetSongDialog extends JDialog
{
private static final Logger logger = LoggerFactory.getLogger(InternetSongDialog.class);
private static final ResourceBundle langs = ResourceBundle.getBundle("lang.interface", Locale.getDefault());
private final JTextField urlBox;
private final JTextField titleBox;
@@ -48,7 +51,7 @@ public class InternetSongDialog extends JDialog
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 2, 5, 2);
this.getContentPane().add(label = new JLabel("URL"), c);
this.getContentPane().add(label = new JLabel(langs.getString("actions.external.add.url")), c);
this.urlBox = new JTextField();
this.urlBox.addFocusListener(new FocusAdapter()
{
@@ -73,7 +76,7 @@ public class InternetSongDialog extends JDialog
c.gridx = 0;
c.gridy = ++y;
this.getContentPane().add(label = new JLabel("Song Title"), c);
this.getContentPane().add(label = new JLabel(langs.getString("actions.external.add.song")), c);
this.titleBox = new JTextField();
c.gridy = ++y;
this.getContentPane().add(this.titleBox, c);
@@ -81,7 +84,7 @@ public class InternetSongDialog extends JDialog
c.gridx = 0;
c.gridy = ++y;
this.getContentPane().add(label = new JLabel("Album"), c);
this.getContentPane().add(label = new JLabel(langs.getString("actions.external.add.album")), c);
this.albumBox = new JTextField();
c.gridy = ++y;
this.getContentPane().add(this.albumBox, c);
@@ -89,7 +92,7 @@ public class InternetSongDialog extends JDialog
c.gridx = 0;
c.gridy = ++y;
this.getContentPane().add(label = new JLabel("Artists"), c);
this.getContentPane().add(label = new JLabel(langs.getString("actions.external.add.artists")), c);
this.artistBox = new JTextField();
c.gridy = ++y;
this.getContentPane().add(this.artistBox, c);
@@ -97,7 +100,7 @@ public class InternetSongDialog extends JDialog
c.gridx = 0;
c.gridy = ++y;
this.getContentPane().add(label = new JLabel("Genre"), c);
this.getContentPane().add(label = new JLabel(langs.getString("actions.external.add.genre")), c);
this.genreBox = new JTextField();
c.gridy = ++y;
this.getContentPane().add(this.genreBox, c);
@@ -106,11 +109,11 @@ public class InternetSongDialog extends JDialog
c.gridwidth = 1;
c.gridx = 0;
c.gridy = ++y;
JButton cancelButton = new JButton("Cancel");
JButton cancelButton = new JButton(langs.getString("actions.cancel"));
cancelButton.addActionListener(e -> this.dispose());
this.getContentPane().add(cancelButton, c);
c.gridx = 1;
JButton addButton = new JButton("Add");
JButton addButton = new JButton(langs.getString("actions.add"));
addButton.addActionListener(e -> this.confirm());
this.getContentPane().add(addButton, c);
@@ -151,7 +154,7 @@ public class InternetSongDialog extends JDialog
catch (InterruptedException | ExecutionException e)
{
logger.error("Could not evaluate song", e);
JOptionPane.showMessageDialog(InternetSongDialog.this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(InternetSongDialog.this, e.getMessage(), langs.getString("error.generic"), JOptionPane.ERROR_MESSAGE);
}
finally
{

View File

@@ -17,10 +17,13 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.util.Formatter;
import java.util.Locale;
import java.util.ResourceBundle;
public class QueueList extends JPanel implements Queue.SongChangeListener, Queue.QueueChangeListener
{
private static final Logger logger = LoggerFactory.getLogger(QueueList.class);
private static final ResourceBundle langs = ResourceBundle.getBundle("lang.interface", Locale.getDefault());
final JPanel header;
final ScrollablePanel songList;
@@ -42,8 +45,8 @@ public class QueueList extends JPanel implements Queue.SongChangeListener, Queue
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
header.add(new JLabel(" ".repeat(20) + "Queue" + " ".repeat(20)), c);
this.clearButton = new JButton("Clear");
header.add(new JLabel(" ".repeat(20) + langs.getString("interface.queue.title") + " ".repeat(20)), c);
this.clearButton = new JButton(langs.getString("actions.clear"));
this.clearButton.addActionListener(e -> Queue.getInstance().clear());
c.gridy = 1;
c.gridwidth = 1;
@@ -229,8 +232,8 @@ public class QueueList extends JPanel implements Queue.SongChangeListener, Queue
{
public SongMenu(Song song, Queue queue)
{
final JMenuItem play = new JMenuItem("Play");
final JMenuItem remove = new JMenuItem("Remove");
final JMenuItem play = new JMenuItem(langs.getString("actions.play"));
final JMenuItem remove = new JMenuItem(langs.getString("actions.remove"));
play.addActionListener(e -> queue.skipToSong(queue.indexOf(song)));
remove.addActionListener(e -> queue.remove(song));