Skip to content

Commit

Permalink
refactor: Use 'TranslationFacility.tr' instead of 'HOVerwaltung.insta…
Browse files Browse the repository at this point in the history
…nce().getLanguageString'
  • Loading branch information
sgcr committed Sep 29, 2024
1 parent 0ed42f9 commit 5d3e17a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/main/java/core/gui/LabelWithSignedNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import core.gui.theme.HOColorName;
import core.gui.theme.ThemeManager;
import core.model.HOVerwaltung;
import core.model.TranslationFacility;
import core.util.Helper;

import javax.swing.*;
Expand All @@ -19,7 +19,7 @@ public class LabelWithSignedNumber extends JLabel {

private static final String PLUS_SIGN = "+";

private final String notAvailableString = HOVerwaltung.instance().getLanguageString("ls.general_label.not_available_abbreviation");
private final String notAvailableString = TranslationFacility.tr("ls.general_label.not_available_abbreviation");

public LabelWithSignedNumber(String text, int horizontalAlignment) {
super(text, horizontalAlignment);
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/tool/arenasizer/ArenaInfoPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tool.arenasizer;

import core.model.HOVerwaltung;
import core.model.TranslationFacility;
import core.util.HODateTime;
import core.util.Helper;
import core.util.HumanDuration;
Expand Down Expand Up @@ -41,7 +42,7 @@ public ArenaInfoPanel() {
private void updateValues() {
final Stadium stadium = HOVerwaltung.instance().getModel().getStadium();

final String notAvailableString = HOVerwaltung.instance().getLanguageString("ls.general_label.not_available_abbreviation");
final String notAvailableString = TranslationFacility.tr("ls.general_label.not_available_abbreviation");
final var numberformat = Helper.getNumberFormat(false, 0);

// Current Capacity
Expand All @@ -57,7 +58,7 @@ private void updateValues() {
currentCapacityPanel.labelPercentageVipBoxes.setText(percentString(stadium.getLogen(), stadium.getGesamtgroesse()));
currentCapacityPanel.labelPercentageTotal.setText(percentString(stadium.getGesamtgroesse(), stadium.getGesamtgroesse()));

currentCapacityPanel.label2.setText(Optional.ofNullable(stadium.getRebuiltDate()).map(HODateTime::toLocaleDate).orElse(getLanguageString("ArenaInfoPanel.construction_in_progress")));
currentCapacityPanel.label2.setText(Optional.ofNullable(stadium.getRebuiltDate()).map(HODateTime::toLocaleDate).orElse(TranslationFacility.tr("ArenaInfoPanel.construction_in_progress")));

// Expanded Capacity
expandedCapacityPanel.labelCountTerraces.setNumber(stadium.isAusbau() ? stadium.getAusbauStehplaetze() : null);
Expand Down Expand Up @@ -97,17 +98,17 @@ private void updateValues() {

private void setTranslation() {
currentCapacityPanel.setTranslation();
currentCapacityPanel.setTitle(getLanguageString("ArenaInfoPanel.current"));
currentCapacityPanel.label1.setText(getLanguageString("ArenaInfoPanel.last_improvement"));
currentCapacityPanel.setTitle(TranslationFacility.tr("ArenaInfoPanel.current"));
currentCapacityPanel.label1.setText(TranslationFacility.tr("ArenaInfoPanel.last_improvement"));

expandedCapacityPanel.setTranslation();
expandedCapacityPanel.setTitle(getLanguageString("ArenaInfoPanel.expansion"));
expandedCapacityPanel.labelPercentage.setText(getLanguageString("ArenaInfoPanel.change_in_percent"));
expandedCapacityPanel.label1.setText(getLanguageString("ArenaInfoPanel.completion"));
expandedCapacityPanel.setTitle(TranslationFacility.tr("ArenaInfoPanel.expansion"));
expandedCapacityPanel.labelPercentage.setText(TranslationFacility.tr("ArenaInfoPanel.change_in_percent"));
expandedCapacityPanel.label1.setText(TranslationFacility.tr("ArenaInfoPanel.completion"));

futureCapacityPanel.setTranslation();
futureCapacityPanel.setTitle(getLanguageString("ArenaInfoPanel.future"));
futureCapacityPanel.label1.setText(getLanguageString("ArenaInfoPanel.available"));
futureCapacityPanel.setTitle(TranslationFacility.tr("ArenaInfoPanel.future"));
futureCapacityPanel.label1.setText(TranslationFacility.tr("ArenaInfoPanel.available"));
}

private void updateExpansionFinishedLabel() {
Expand All @@ -118,12 +119,12 @@ private void updateExpansionFinishedLabel() {
if (building) {
final String text = toDurationString(expansionDate);
final String toolTipText = String.format(
getLanguageString("ArenaInfoPanel.finished_in_n_days_format"),
TranslationFacility.tr("ArenaInfoPanel.finished_in_n_days_format"),
HODateTime.daysFromNow(expansionDate, 1));
labelExpansionFinished.setText(text);
labelExpansionFinished.setToolTipText(toolTipText);
} else {
labelExpansionFinished.setText(String.format(getLanguageString("ArenaInfoPanel.built")));
labelExpansionFinished.setText(String.format(TranslationFacility.tr("ArenaInfoPanel.built")));
labelExpansionFinished.setToolTipText(null);
}
},
Expand All @@ -134,10 +135,6 @@ private void updateExpansionFinishedLabel() {
);
}

private static String getLanguageString(String key) {
return HOVerwaltung.instance().getLanguageString(key);
}

private static String toDurationString(HODateTime hoDateTime) {
return HumanDuration.of(HODateTime.between(HODateTime.now(), hoDateTime)).toHumanString();
}
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/tool/arenasizer/CapacityPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tool.arenasizer;

import core.gui.LabelWithSignedNumber;
import core.model.HOVerwaltung;
import core.model.TranslationFacility;

import javax.imageio.ImageIO;
import javax.swing.*;
Expand Down Expand Up @@ -134,42 +134,38 @@ public void setTitle(String titel) {
}

public void setTranslation() {
labelPlaceType.setText(getLanguageString("ArenaInfoPanel.place_type"));
labelPlaces.setText(getLanguageString("ArenaInfoPanel.places"));
labelPercentage.setText(getLanguageString("ArenaInfoPanel.rate_in_percent"));
labelPlaceType.setText(TranslationFacility.tr("ArenaInfoPanel.place_type"));
labelPlaces.setText(TranslationFacility.tr("ArenaInfoPanel.places"));
labelPercentage.setText(TranslationFacility.tr("ArenaInfoPanel.rate_in_percent"));

labelTerraces.setToolTipText(getLanguageString("ls.club.arena.terraces"));
labelTerraces.setToolTipText(TranslationFacility.tr("ls.club.arena.terraces"));
if (LONG_MODE) {
labelTerraces.setText(labelTerraces.getToolTipText());
}

labelBasicSeating.setToolTipText(getLanguageString("ls.club.arena.basicseating"));
labelBasicSeating.setToolTipText(TranslationFacility.tr("ls.club.arena.basicseating"));
if (LONG_MODE) {
labelBasicSeating.setText(labelBasicSeating.getToolTipText());
}

labelSeatsUnderRoof.setToolTipText(getLanguageString("ls.club.arena.seatsunderroof"));
labelSeatsUnderRoof.setToolTipText(TranslationFacility.tr("ls.club.arena.seatsunderroof"));
if (LONG_MODE) {
labelSeatsUnderRoof.setText(labelSeatsUnderRoof.getToolTipText());
}

labelVipBoxes.setToolTipText(getLanguageString("ls.club.arena.seatsinvipboxes"));
labelVipBoxes.setToolTipText(TranslationFacility.tr("ls.club.arena.seatsinvipboxes"));
if (LONG_MODE) {
labelVipBoxes.setText(labelVipBoxes.getToolTipText());
}

labelTotal.setToolTipText(getLanguageString("Gesamtgroesse"));
labelTotal.setToolTipText(TranslationFacility.tr("Gesamtgroesse"));
if (LONG_MODE) {
labelTotal.setText(getLanguageString("ArenaInfoPanel.total_seats_and_sum_sign"));
labelTotal.setText(TranslationFacility.tr("ArenaInfoPanel.total_seats_and_sum_sign"));
} else {
labelTotal.setText(getLanguageString("ArenaInfoPanel.sum_sign"));
labelTotal.setText(TranslationFacility.tr("ArenaInfoPanel.sum_sign"));
}
}

private static String getLanguageString(String key) {
return HOVerwaltung.instance().getLanguageString(key);
}

private static Optional<ImageIcon> loadImageIcon(String name) {
try {
return Optional.of(new ImageIcon(ImageIO.read(ClassLoader.getSystemResource(name))));
Expand Down

0 comments on commit 5d3e17a

Please sign in to comment.