summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-02-23 17:48:55 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-02-23 20:32:03 -0500
commita62fd9e6b4519ffcbd0503c45b159207ce438243 (patch)
treef12d11d11cd33ec4a779b73b18581544de6935ba
parentf1ca636346f4fe4da66035ae30469f1503261a83 (diff)
Localize all user-facing strings
-rw-r--r--src/main/java/sevenUnitsGUI/TabbedView.java114
-rw-r--r--src/main/resources/locales/en.txt30
2 files changed, 110 insertions, 34 deletions
diff --git a/src/main/java/sevenUnitsGUI/TabbedView.java b/src/main/java/sevenUnitsGUI/TabbedView.java
index 1da119e..ca9f23c 100644
--- a/src/main/java/sevenUnitsGUI/TabbedView.java
+++ b/src/main/java/sevenUnitsGUI/TabbedView.java
@@ -24,13 +24,16 @@ import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.util.AbstractSet;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
+import java.util.function.Consumer;
import java.util.function.Function;
import javax.swing.BorderFactory;
@@ -200,6 +203,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
private StandardRoundingType roundingType;
private int precision;
+ private final Map<String, Consumer<String>> localizedTextSetters;
+
/**
* Creates the view and makes it visible to the user
*
@@ -226,9 +231,13 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
this.masterPane = new JTabbedPane();
this.frame.add(this.masterPane);
+ this.localizedTextSetters = new HashMap<>();
+
// ============ UNIT CONVERSION TAB ============
final JPanel convertUnitPanel = new JPanel();
this.masterPane.addTab("Convert Units", convertUnitPanel);
+ this.localizedTextSetters.put("tv.convert_units.title",
+ txt -> this.masterPane.setTitleAt(0, txt));
this.masterPane.setMnemonicAt(0, KeyEvent.VK_U);
convertUnitPanel.setLayout(new BorderLayout());
@@ -264,7 +273,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
outputPanel.setLayout(new BorderLayout());
outputPanel.setBorder(new EmptyBorder(3, 6, 6, 6));
- final JLabel valuePrompt = new JLabel("Value to convert: ");
+ final JLabel valuePrompt = new JLabel();
+ this.localizedTextSetters.put("tv.convert_units.value_prompt",
+ valuePrompt::setText);
outputPanel.add(valuePrompt, BorderLayout.LINE_START);
this.valueInput = new JTextField();
@@ -272,6 +283,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// conversion button
this.convertUnitButton = new JButton("Convert");
+ this.localizedTextSetters.put("tv.convert_units.convert_btn",
+ this.convertUnitButton::setText);
outputPanel.add(this.convertUnitButton, BorderLayout.LINE_END);
this.convertUnitButton
.addActionListener(e -> this.presenter.convertUnits());
@@ -287,20 +300,26 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
final JPanel convertExpressionPanel = new JPanel();
this.masterPane.addTab("Convert Unit Expressions",
convertExpressionPanel);
+ this.localizedTextSetters.put("tv.convert_expressions.title",
+ txt -> this.masterPane.setTitleAt(1, txt));
this.masterPane.setMnemonicAt(1, KeyEvent.VK_E);
convertExpressionPanel.setLayout(new GridLayout(4, 1));
// from and to expressions
this.fromEntry = new JTextField();
convertExpressionPanel.add(this.fromEntry);
- this.fromEntry.setBorder(BorderFactory.createTitledBorder("From"));
+ this.localizedTextSetters.put("tv.convert_expressions.from",
+ txt -> this.fromEntry.setBorder(BorderFactory.createTitledBorder(txt)));
this.toEntry = new JTextField();
convertExpressionPanel.add(this.toEntry);
- this.toEntry.setBorder(BorderFactory.createTitledBorder("To"));
+ this.localizedTextSetters.put("tv.convert_expressions.to",
+ txt -> this.toEntry.setBorder(BorderFactory.createTitledBorder(txt)));
// button to convert
- this.convertExpressionButton = new JButton("Convert");
+ this.convertExpressionButton = new JButton();
+ this.localizedTextSetters.put("tv.convert_expressions.convert_btn",
+ this.convertExpressionButton::setText);
convertExpressionPanel.add(this.convertExpressionButton);
this.convertExpressionButton
@@ -310,13 +329,15 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// output of conversion
this.expressionOutput = new JTextArea(2, 32);
convertExpressionPanel.add(this.expressionOutput);
- this.expressionOutput
- .setBorder(BorderFactory.createTitledBorder("Output"));
+ this.localizedTextSetters.put("tv.convert_expressions.output",
+ txt -> this.expressionOutput.setBorder(BorderFactory.createTitledBorder(txt)));
this.expressionOutput.setEditable(false);
// =========== UNIT VIEWER ===========
final JPanel unitLookupPanel = new JPanel();
this.masterPane.addTab("Unit Viewer", unitLookupPanel);
+ this.localizedTextSetters.put("tv.unit_viewer.title",
+ txt -> this.masterPane.setTitleAt(2, txt));
this.masterPane.setMnemonicAt(2, KeyEvent.VK_V);
unitLookupPanel.setLayout(new GridLayout());
@@ -334,6 +355,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// ============ PREFIX VIEWER =============
final JPanel prefixLookupPanel = new JPanel();
this.masterPane.addTab("Prefix Viewer", prefixLookupPanel);
+ this.localizedTextSetters.put("tv.prefix_viewer.title",
+ txt -> this.masterPane.setTitleAt(3, txt));
this.masterPane.setMnemonicAt(3, KeyEvent.VK_P);
prefixLookupPanel.setLayout(new GridLayout(1, 2));
@@ -389,7 +412,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
{
final JPanel roundingPanel = new JPanel();
settingsPanel.add(roundingPanel);
- roundingPanel.setBorder(new TitledBorder("Rounding Settings"));
+ this.localizedTextSetters.put("tv.settings.rounding.title",
+ txt -> roundingPanel.setBorder(new TitledBorder(txt)));
roundingPanel.setLayout(new GridBagLayout());
// rounding rule selection
@@ -399,13 +423,17 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
"Presenter loaded non-standard rounding rule"));
this.precision = this.getPresenterPrecision().orElse(6);
- final JLabel roundingRuleLabel = new JLabel("Rounding Rule:");
+ final JLabel roundingRuleLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.rounding.rule",
+ roundingRuleLabel::setText);
roundingPanel.add(roundingRuleLabel, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
// sigDigSlider needs to be first so that the rounding-type buttons can
// show and hide it
- final JLabel sliderLabel = new JLabel("Precision:");
+ final JLabel sliderLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.rounding.precision",
+ sliderLabel::setText);
sliderLabel.setVisible(
this.roundingType != StandardRoundingType.UNCERTAINTY);
roundingPanel.add(sliderLabel, new GridBagBuilder(0, 4)
@@ -431,8 +459,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
});
// significant digit rounding
- final JRadioButton fixedPrecision = new JRadioButton(
- "Fixed Precision");
+ final JRadioButton fixedPrecision = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.fixed_sigfig",
+ fixedPrecision::setText);
if (this.roundingType == StandardRoundingType.SIGNIFICANT_DIGITS) {
fixedPrecision.setSelected(true);
}
@@ -447,8 +476,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
.setAnchor(GridBagConstraints.LINE_START).build());
// decimal place rounding
- final JRadioButton fixedDecimals = new JRadioButton(
- "Fixed Decimal Places");
+ final JRadioButton fixedDecimals = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.fixed_places",
+ fixedDecimals::setText);
if (this.roundingType == StandardRoundingType.DECIMAL_PLACES) {
fixedDecimals.setSelected(true);
}
@@ -463,8 +493,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
.setAnchor(GridBagConstraints.LINE_START).build());
// scientific rounding
- final JRadioButton relativePrecision = new JRadioButton(
- "Uncertainty-Based Rounding");
+ final JRadioButton relativePrecision = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.rounding.uncertainty",
+ relativePrecision::setText);
if (this.roundingType == StandardRoundingType.UNCERTAINTY) {
relativePrecision.setSelected(true);
}
@@ -483,8 +514,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
{
final JPanel prefixRepetitionPanel = new JPanel();
settingsPanel.add(prefixRepetitionPanel);
- prefixRepetitionPanel
- .setBorder(new TitledBorder("Prefix Repetition Settings"));
+ this.localizedTextSetters.put("tv.settings.repetition.title",
+ txt -> prefixRepetitionPanel.setBorder(new TitledBorder(txt)));
prefixRepetitionPanel.setLayout(new GridBagLayout());
final var prefixRule = this.getPresenterPrefixRule()
@@ -494,7 +525,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
// prefix rules
final ButtonGroup prefixRuleButtons = new ButtonGroup();
- final JRadioButton noRepetition = new JRadioButton("No Repetition");
+ final JRadioButton noRepetition = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.no",
+ noRepetition::setText);
if (prefixRule == DefaultPrefixRepetitionRule.NO_REPETITION) {
noRepetition.setSelected(true);
}
@@ -507,7 +540,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
prefixRepetitionPanel.add(noRepetition, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton noRestriction = new JRadioButton("No Restriction");
+ final JRadioButton noRestriction = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.any",
+ noRestriction::setText);
if (prefixRule == DefaultPrefixRepetitionRule.NO_RESTRICTION) {
noRestriction.setSelected(true);
}
@@ -520,8 +555,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
prefixRepetitionPanel.add(noRestriction, new GridBagBuilder(0, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton customRepetition = new JRadioButton(
- "Complex Repetition");
+ final JRadioButton customRepetition = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.repetition.complex",
+ customRepetition::setText);
if (prefixRule == DefaultPrefixRepetitionRule.COMPLEX_REPETITION) {
customRepetition.setSelected(true);
}
@@ -539,7 +575,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
{
final JPanel searchingPanel = new JPanel();
settingsPanel.add(searchingPanel);
- searchingPanel.setBorder(new TitledBorder("Search Settings"));
+ this.localizedTextSetters.put("tv.settings.search.title",
+ txt -> searchingPanel.setBorder(new TitledBorder(txt)));
searchingPanel.setLayout(new GridBagLayout());
// searching rules
@@ -547,8 +584,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
final var searchRule = this.presenter.getSearchRule();
- final JRadioButton noPrefixes = new JRadioButton(
- "Never Include Prefixed Units");
+ final JRadioButton noPrefixes = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.no_prefixes",
+ noPrefixes::setText);
noPrefixes.addActionListener(e -> {
this.presenter.setSearchRule(PrefixSearchRule.NO_PREFIXES);
this.presenter.updateView();
@@ -558,8 +596,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
searchingPanel.add(noPrefixes, new GridBagBuilder(0, 0)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton commonPrefixes = new JRadioButton(
- "Include Common Prefixes");
+ final JRadioButton commonPrefixes = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.common_prefixes",
+ commonPrefixes::setText);
commonPrefixes.addActionListener(e -> {
this.presenter.setSearchRule(PrefixSearchRule.COMMON_PREFIXES);
this.presenter.updateView();
@@ -569,8 +608,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
searchingPanel.add(commonPrefixes, new GridBagBuilder(0, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JRadioButton alwaysInclude = new JRadioButton(
- "Include All Single Prefixes");
+ final JRadioButton alwaysInclude = new JRadioButton();
+ this.localizedTextSetters.put("tv.settings.search.all_prefixes",
+ alwaysInclude::setText);
alwaysInclude.addActionListener(e -> {
this.presenter
.setSearchRule(this.presenter.getUniversalSearchRule());
@@ -599,7 +639,8 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
settingsPanel.add(miscPanel);
miscPanel.setLayout(new GridBagLayout());
- final JCheckBox oneWay = new JCheckBox("Convert One Way Only");
+ final JCheckBox oneWay = new JCheckBox();
+ this.localizedTextSetters.put("tv.settings.oneway", oneWay::setText);
oneWay.setSelected(this.presenter.oneWayConversionEnabled());
oneWay.addItemListener(e -> {
this.presenter.setOneWayConversionEnabled(
@@ -609,8 +650,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
miscPanel.add(oneWay, new GridBagBuilder(0, 0, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JCheckBox showAllVariations = new JCheckBox(
- "Show Duplicate Units & Prefixes");
+ final JCheckBox showAllVariations = new JCheckBox();
+ this.localizedTextSetters.put("tv.settings.show_duplicate",
+ showAllVariations::setText);
showAllVariations.setSelected(this.presenter.duplicatesShown());
showAllVariations.addItemListener(e -> {
this.presenter
@@ -620,7 +662,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
miscPanel.add(showAllVariations, new GridBagBuilder(0, 1, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
- final JLabel localeLabel = new JLabel("Locale:");
+ final JLabel localeLabel = new JLabel();
+ this.localizedTextSetters.put("tv.settings.locale",
+ localeLabel::setText);
miscPanel.add(localeLabel, new GridBagBuilder(0, 2, 1, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
@@ -634,7 +678,9 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
miscPanel.add(localeSelector, new GridBagBuilder(1, 2, 1, 1)
.setAnchor(GridBagConstraints.LINE_END).build());
- final JButton unitFileButton = new JButton("Manage Unit Data Files");
+ final JButton unitFileButton = new JButton();
+ this.localizedTextSetters.put("tv.settings.unitfiles.button",
+ unitFileButton::setText);
unitFileButton.setEnabled(false);
miscPanel.add(unitFileButton, new GridBagBuilder(0, 3, 2, 1)
.setAnchor(GridBagConstraints.LINE_START).build());
@@ -849,5 +895,7 @@ final class TabbedView implements ExpressionConversionView, UnitConversionView {
public void updateText() {
this.frame.setTitle(this.presenter.getLocalizedText("tv.title")
.replace("[v]", ProgramInfo.VERSION.toString()));
+ this.localizedTextSetters.forEach((id, action) ->
+ action.accept(this.presenter.getLocalizedText(id)));
}
}
diff --git a/src/main/resources/locales/en.txt b/src/main/resources/locales/en.txt
index 9d453c9..19ed781 100644
--- a/src/main/resources/locales/en.txt
+++ b/src/main/resources/locales/en.txt
@@ -1 +1,29 @@
-tv.title=7Units [v] \ No newline at end of file
+tv.title=7Units [v]
+tv.convert_units.title=Convert Units
+tv.convert_units.value_prompt=Value to convert:
+tv.convert_units.convert_btn=Convert
+tv.convert_expressions.title=Convert Unit Expressions
+tv.convert_expressions.from=From
+tv.convert_expressions.to=To
+tv.convert_expressions.convert_btn=Convert
+tv.convert_expressions.output=Output
+tv.unit_viewer.title=Unit Viewer
+tv.prefix_viewer.title=Prefix Viewer
+tv.settings.rounding.title=Rounding Settings
+tv.settings.rounding.rule=Rounding Rule:
+tv.settings.rounding.precision=Precision:
+tv.settings.rounding.fixed_sigfig=Fixed Precision
+tv.settings.rounding.fixed_places=Fixed Decimal Places
+tv.settings.rounding.uncertainty=Uncertainty-based Rounding
+tv.settings.repetition.title=Prefix Repetition Settings
+tv.settings.repetition.no=No Repetition
+tv.settings.repetition.any=No Restriction
+tv.settings.repetition.complex=Complex Repetition
+tv.settings.search.title=Search Settings
+tv.settings.search.no_prefixes=Never Include Prefixed Units
+tv.settings.search.common_prefixes=Include Common Prefixes
+tv.settings.search.all_prefixes=Include All Single Prefixes
+tv.settings.oneway=Convert One Way Only
+tv.settings.show_duplicate=Show Duplicate Units & Prefixes
+tv.settings.locale=🌐 Locale:
+tv.settings.unitfiles.button=Manage Unit Data Files