Skip to content

Commit

Permalink
l10n (localization) support (#8)
Browse files Browse the repository at this point in the history
* l10n support en+fr

* l10n support en+fr

* added few translations thanks @SzyZuu for German and Polish translations

---------

Co-authored-by: serifpersia <ramiserifpersia@gmail.com>
  • Loading branch information
tobozo and serifpersia authored Apr 16, 2024
1 parent 3110260 commit b78deec
Show file tree
Hide file tree
Showing 20 changed files with 879 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ of this software and associated documentation files (the "Software"), to deal
import com.serifpersia.esp32partitiontool.UI;
import com.serifpersia.esp32partitiontool.UIController;

//import javax.swing.ImageIcon;

// local implementation of rounded borders to overwrite global styles
@SuppressWarnings("serial")
final class CustomBorder extends AbstractBorder {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/serifpersia/esp32partitiontool/FSPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public FSPanel() {

public void updatePartitionFlashTypeLabel() {
FSGenLabel.setText( getPartitionFlashTypes().getSelectedItem().toString() );
FSUploadButton.setText( "Upload " + getPartitionFlashTypes().getSelectedItem().toString() );
FSUploadButton.setText( l10n.getString("fsPanel.uploadButtonLabel") +" " + getPartitionFlashTypes().getSelectedItem().toString() );
}

public JComboBox<?> getPartitionFlashTypes() {
Expand Down Expand Up @@ -91,10 +91,10 @@ public JPanel wrapButton( JButton button ) {
public void initComponents() {
consoleGBC = new GridBagConstraints();
FSInnerLayout = new GridLayout(0, 2);
FSGenLabel = new JLabel("SPIFFS");
mergeBoxLabel = new JLabel("Merge");
FSComboLabel = new JLabel("Filesystem:");
blockSizeLabel = new JLabel("Block Size:");
FSGenLabel = new JLabel();
mergeBoxLabel = new JLabel(l10n.getString("fsPanel.mergeBoxLabel"));
FSComboLabel = new JLabel(l10n.getString("fsPanel.comboLabel")+":");
blockSizeLabel = new JLabel(l10n.getString("fsPanel.blockSizeLabel")+":");
FSGenInnerPanel = new UI.JTransparentPanel( /*Color.MAGENTA*/ );
FSInnerPanel = new UI.JTransparentPanel();
FSGenPanel = new UI.JTransparentPanel();
Expand All @@ -105,10 +105,10 @@ public void initComponents() {
mergeButtonsWrapper = new UI.JTransparentPanel();
FSTypesComboBox = new JComboBox<>(new String[] { "SPIFFS", "LittleFS", "FatFS" });
FSBlockSize = new JTextField("4096");
FSUploadButton = new JButton("Upload SPIFFS");
mergeBinButton = new JButton("Merge Binary");
uploadMergedBinButton = new JButton("Merge Binary & Upload");
cleanLogsButton = new UI.JButtonIcon("Clear logs", "/clear.png");
FSUploadButton = new JButton(l10n.getString("fsPanel.uploadButtonLabel"));
mergeBinButton = new JButton(l10n.getString("fsPanel.mergeBinButtonLabel"));
uploadMergedBinButton = new JButton(l10n.getString("fsPanel.uploadMergedBinButtonLabel"));
cleanLogsButton = new UI.JButtonIcon(l10n.getString("fsPanel.cleanLogsButtonLabel"), "/clear.png");
consoleLogPanel = new JPanel();
consoleScrollPanel = new JScrollPane(consoleLogPanel);
progressBar = new JProgressBar(0, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void importCSV(String fileName) {
String directory;

if (fileName == null) { // show a dialog
FileDialog filedialog = new FileDialog(ui.getFrame(), "Select CSV file to import", FileDialog.LOAD);
FileDialog filedialog = new FileDialog(ui.getFrame(), l10n.getString("importCsv.dialogTitle"), FileDialog.LOAD);
FilenameFilter csvFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean accept(File dir, String name) {
csvName = "partitions.csv";
}

FileDialog filedialog = new FileDialog(ui.getFrame(), "Export as CSV", FileDialog.SAVE);
FileDialog filedialog = new FileDialog(ui.getFrame(), l10n.getString("exportCsv.dialogTitle"), FileDialog.SAVE);
filedialog.setDirectory(sketchDir);
filedialog.setFile(csvName);
filedialog.setFilenameFilter(csvFilter);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/serifpersia/esp32partitiontool/HelpPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class HelpPanel extends JPanel {
private ImageIcon infoIcon;
private int helpTipIndex = 0;

private String[] helpTips = { "The default export path for partitions.csv is the sketch directory.",
"If no partitions.csv file is found is the sketch directory, then the partition selected under <b>Tools > Partition schemes</b> will be used.",
"Partitions like nvs or any other small partitions before the app partition need their value to be a multiple of 4.",
"Partitions before the first app partition should have a total of 28 kB so the offset for the first app partition will always be correct at 0x10000 offset. Any other configuration will cause the ESP32 board to not function properly.",
"The app partition needs to be at 0x10000, and following partitions have to be a multiple of 64.",
"The app partition needs to be a minimum of 1024 kB in size." };
private String[] helpTips = {
l10n.getString("helpPanel.tip1"),
l10n.getString("helpPanel.tip2"),
l10n.getString("helpPanel.tip3"),
l10n.getString("helpPanel.tip4"),
l10n.getString("helpPanel.tip5"),
l10n.getString("helpPanel.tip6")
};

public HelpPanel() {
createPanel();
Expand Down Expand Up @@ -85,7 +87,7 @@ private void creatHelpPanel() {
}

private void createNextButton() {
nextButton = new JButton(" Next tip >> ");
nextButton = new JButton(" " + l10n.getString("helpPanel.nextTip") + " >> ");
nextButton.setAlignmentX(JComponent.CENTER_ALIGNMENT);
nextButton.addActionListener(new ActionListener() {
@Override
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/com/serifpersia/esp32partitiontool/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void setFrameTitleNeedsSaving(boolean needs_saving) {
}
}

private l10n lang = new l10n();
private UIController controller;
public AppSettings settings;

Expand Down Expand Up @@ -136,6 +137,7 @@ private Font loadFont(String fontBaseName, int defaultSize, int fallbackType) {
}

public UI(JFrame frame, String title) {

// Show tool tips immediately
ToolTipManager.sharedInstance().setInitialDelay(0);

Expand Down Expand Up @@ -284,7 +286,15 @@ public JPanel getTitleCSVRow() {
JPanel partitionTitlePanel = new JTransparentPanel();
partitionTitlePanel.setLayout(new BorderLayout());

String labels[] = { "Enable", "Name", "Type", "SubType", "Size(kB)", "Size(hex)", "Offset(hex)" };
String labels[] = {
l10n.getString("columnTitle.enable"),
l10n.getString("columnTitle.name"),
l10n.getString("columnTitle.type"),
l10n.getString("columnTitle.subtype"),
l10n.getString("columnTitle.sizekb"),
l10n.getString("columnTitle.sizehex"),
l10n.getString("columnTitle.offset")
};

JLabel enableLabel = new JLabel(labels[0]);
enableLabel.setFont( condensedFont.deriveFont(Font.BOLD, 13));
Expand Down Expand Up @@ -322,7 +332,7 @@ private void createPanels() {
csvGenPanel.setLayout(new BorderLayout(0, 0));
csvGenPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));

csvGenLabel = new JLabel("Partitions");
csvGenLabel = new JLabel(l10n.getString("csvGenLabel.defaultLabel"));
csvGenLabel.setOpaque(false);
csvGenLabel.setFont(defaultFont.deriveFont(Font.PLAIN, 20));
csvGenLabel.setHorizontalAlignment(SwingConstants.CENTER);
Expand Down Expand Up @@ -363,20 +373,20 @@ private void createPanels() {
actionButtonsPanel.setAlignmentY(Component.CENTER_ALIGNMENT);
actionButtonsPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
actionButtonsPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
importCsvBtn = new JButtonIcon("Import CSV", "/import.png");
importCsvBtn = new JButtonIcon(l10n.getString("importCsvButton.label"), "/import.png");
actionButtonsPanel.add(importCsvBtn);
saveCsvBtn = new JButtonIcon("Save CSV", "/save.png");
saveCsvBtn = new JButtonIcon(l10n.getString("saveCsvButton.label"), "/save.png");
actionButtonsPanel.add(saveCsvBtn);
exporCsvBtn = new JButtonIcon("Export CSV", "/export2.png");
exporCsvBtn = new JButtonIcon(l10n.getString("exportCsvButton.label"), "/export2.png");
actionButtonsPanel.add(exporCsvBtn);
helpButton = new JButtonIcon("Help", "/help.png");
helpButton = new JButtonIcon(l10n.getString("helpButton.label"), "/help.png");
actionButtonsPanel.add(helpButton);
aboutBtn = new JButtonIcon("About", "/about.png");
aboutBtn = new JButtonIcon(l10n.getString("aboutButton.label"), "/about.png");
actionButtonsPanel.add(aboutBtn);
csvBottomPanel.add(actionButtonsPanel, BorderLayout.WEST);

flashSizeFieldSetPanel = new JTransparentPanel();
flashSizeLabel = new JLabel("Flash Size: MB");
flashSizeLabel = new JLabel(l10n.getString("flashSize.label")+" (MB):");
flashSizeLabel.setFont(defaultFont.deriveFont(Font.PLAIN, 13));
flashSizeLabel.setHorizontalAlignment(SwingConstants.CENTER);
flashSizeFieldSetPanel.add(flashSizeLabel);
Expand All @@ -386,7 +396,7 @@ private void createPanels() {
partitionsUtilButtonsPanel.add(flashSizeFieldSetPanel, BorderLayout.CENTER);

// free space box
partitionFlashFreeSpace = new JLabel("Free Space: not set");
partitionFlashFreeSpace = new JLabel(l10n.getString("flash.freeSpace") + ": ...");
partitionFlashFreeSpace.setFont(defaultFont.deriveFont(Font.PLAIN, 13));
partitionsUtilButtonsPanel.add(partitionFlashFreeSpace, BorderLayout.EAST);

Expand Down Expand Up @@ -431,7 +441,7 @@ public void calculateSizeHex() {
}

// Update the free space label
getFlashFreeLabel().setText("Free Space: " + FlashSizeBytes / 1024 + " KB");
getFlashFreeLabel().setText(l10n.getString("flash.freeSpace") + ": " + FlashSizeBytes / 1024 + " KB");
getFlashFreeLabel().setForeground(FlashSizeBytes >= 0 ? Color.BLACK : Color.RED);

// Convert partition sizes to hexadecimal strings
Expand Down Expand Up @@ -614,7 +624,7 @@ public void updatePartitionFlashVisual() {
unusedSpacePanel.setBackground(new Color(130, 135, 145));
gbc.weightx = (double) remainingSpace / (FLASH_SIZE - RESERVED_SPACE);
// Set the text color to white
JLabel label = new JLabel("Free Space");
JLabel label = new JLabel(l10n.getString("flash.freeSpace"));
label.setForeground(Color.BLACK);
label.setFont(monotypeBoldFont.deriveFont(Font.PLAIN, 12));
unusedSpacePanel.add(label);
Expand Down Expand Up @@ -814,7 +824,7 @@ public String getSpiffsOffset() {
String partitionOffset = getPartitionOffsets(spiffsIndex).getText();
result = "0x" + partitionOffset;
} else {
result = "SPIFFS partition not found.";
result = l10n.getString("spiffs.partitionNotFound");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ private void handleComboBoxAction(JComboBox<?> comboBox) {
private void handleAboutButton() {
// modal dialog with icon
ImageIcon icon = new ImageIcon(getClass().getResource("/logo.png"));
JOptionPane.showConfirmDialog(null, ui.aboutPanel, "About ESP32PartitionTool", JOptionPane.DEFAULT_OPTION,
JOptionPane.showConfirmDialog(null, ui.aboutPanel, l10n.getString("aboutPanel.title"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, icon);
}

public void handleHelpButton() {
// modal dialog with minimal decoration
final JDialog dialog = new JDialog((Frame) null, "Help Tips", true);
final JDialog dialog = new JDialog((Frame) null, l10n.getString("helpPanel.title"), true);
dialog.add(ui.helpPanel);
dialog.pack();
dialog.setLocationRelativeTo(null);
Expand Down
Loading

0 comments on commit b78deec

Please sign in to comment.