Skip to content

Commit 936b1df

Browse files
authored
I18n v2.2 (Scope: strategy.engine.framework.startup.ui) (triplea-game#12841)
* i18n_v2 #1 annotate I18n classes with @NonNls * i18n_v2 #2 annotate @NonNls with .-pattern (.*String .+ *= "\w+\.[A-Za-z]+[A-Za-z\.]*) * i18n_v2 #3 fix via @NonNls imports * i18n_v2 #4 add @NonNls to Strings based on review with pattern (.*String .* = .*\+.*") * i18n_v2 #5 add @NonNls import to AbstractConditionsAttachment.java AbstractImageFactory.java AutoPlacementFinder.java ClipPlayer.java CliProperties.java CommentPanel.java DownloadFile.java FileNameUtils.java FlagIconImageFactory.java GameParser.java GameRunner.java InGameLobbyWatcher.java MapData.java NodeBbForumPoster.java NotificationMessages.java ObjectiveProperties.java PoliticsText.java ProductionRepairPanel.java ProductionTabsProperties.java TooltipProperties.java UnitIconProperties.java UnitImageFactory.java * i18n_v2.1 #6 add @NonNls to Strings based on review with static-String-pattern (.*static final String .* = ") * i18n_v2.1 #7 add @NonNls and Locals to getUpperCase() calls (toUpperCase\()\) * i18n_v2.1 #7 add @NonNls and Locals to toLowerCase() or toUpperCase() calls (?<!NonNls) (p.* static final String) * i18n_v2.1 #8 fix checkstyle error and spotlessJavaApply * LanchesterDebugAction System.out -> log.info * i18n v2.2 Scope: strategy.engine.framework.startup.ui 1. Invoke the Code | Analyse Code | Run Inspection by Name... action. 2. Select the Hardcoded strings inspection. New class HtmlBuilder.java to introduce simple builder pattern for HTML
1 parent 2219d8d commit 936b1df

File tree

20 files changed

+395
-155
lines changed

20 files changed

+395
-155
lines changed

game-app/ai/src/main/java/org/triplea/ai/flowfield/odds/LanchesterDebugAction.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
import java.util.function.Predicate;
3030
import java.util.stream.Collectors;
3131
import lombok.RequiredArgsConstructor;
32+
import lombok.extern.slf4j.Slf4j;
3233
import org.triplea.ai.flowfield.FlowFieldAi;
3334
import org.triplea.ai.flowfield.influence.TerritoryDebugAction;
3435

36+
@Slf4j
3537
@RequiredArgsConstructor
3638
public class LanchesterDebugAction implements Consumer<AiPlayerDebugAction> {
3739

@@ -82,13 +84,13 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
8284
.filter(Predicate.not(Territory::isWater))
8385
.findFirst()
8486
.orElseThrow(() -> new RuntimeException("Land territory is required."));
85-
System.out.println("Using territory " + territory.getName());
87+
log.info("Using territory {}", territory.getName());
8688
final GamePlayer offender = ai.getGamePlayer();
8789
final GamePlayer defender =
8890
relationshipTracker.getEnemies(ai.getGamePlayer()).stream()
8991
.findFirst()
9092
.orElseThrow(() -> new RuntimeException("An enemy is required"));
91-
System.out.println("Defender is " + defender.getName());
93+
log.info("Defender is {}", defender.getName());
9294

9395
final List<Unit> attackingUnits = new ArrayList<>();
9496
final List<Unit> defendingUnits = new ArrayList<>();
@@ -117,8 +119,8 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
117119
defendingUnits.addAll(unitType.create(localRandom.nextInt(10), defender)));
118120
}
119121

120-
System.out.println("Attack Units: " + MyFormatter.unitsToText(attackingUnits));
121-
System.out.println("Defending Units: " + MyFormatter.unitsToText(defendingUnits));
122+
log.info("Attack Units: {}", MyFormatter.unitsToText(attackingUnits));
123+
log.info("Defending Units: {}", MyFormatter.unitsToText(defendingUnits));
122124

123125
final ConcurrentBattleCalculator hardAiCalculator = new ConcurrentBattleCalculator();
124126
hardAiCalculator.setGameData(ai.getGameData());
@@ -162,22 +164,20 @@ public void accept(final AiPlayerDebugAction aiPlayerDebugAction) {
162164
.build()),
163165
1.45);
164166

165-
System.out.println("Hard AI Results");
166-
System.out.println("Win percentage: " + hardAiResults.getAttackerWinPercent());
167-
System.out.println(
168-
"Avg attacking units remaining: "
169-
+ hardAiResults.getAverageAttackingUnitsRemaining().size()
170-
+ " - "
171-
+ hardAiResults.getAverageAttackingUnitsRemaining());
172-
System.out.println(
173-
"Avg defending units remaining: "
174-
+ hardAiResults.getAverageDefendingUnitsRemaining().size()
175-
+ " - "
176-
+ hardAiResults.getAverageDefendingUnitsRemaining());
177-
178-
System.out.println("Lanchester Results");
179-
System.out.println("Winner: " + lanchesterCalculator.getWon());
180-
System.out.println("Units Remaining: " + lanchesterCalculator.getRemainingUnits());
167+
log.info("Hard AI Results");
168+
log.info("Win percentage: {}", hardAiResults.getAttackerWinPercent());
169+
log.info(
170+
"Avg attacking units remaining: {} - {}",
171+
hardAiResults.getAverageAttackingUnitsRemaining().size(),
172+
hardAiResults.getAverageAttackingUnitsRemaining());
173+
log.info(
174+
"Avg defending units remaining: {} - {}",
175+
hardAiResults.getAverageDefendingUnitsRemaining().size(),
176+
hardAiResults.getAverageDefendingUnitsRemaining());
177+
178+
log.info("Lanchester Results");
179+
log.info("Winner: {}", lanchesterCalculator.getWon());
180+
log.info("Units Remaining: {}", lanchesterCalculator.getRemainingUnits());
181181
}
182182

183183
private Collection<UnitType> getUnitTypes(

game-app/game-core/src/main/java/games/strategy/engine/data/GamePlayer.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class GamePlayer extends NamedAttachable implements NamedUnitHolder {
2929
@NonNls private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";
3030

3131
@RemoveOnNextMajorRelease @Deprecated
32-
private static final GamePlayer NULL_PLAYERID =
32+
private static final GamePlayer NULL_GAME_PLAYER =
3333
// Kept for save game compatibility, or we'll get a class not found error loading neutrals.
3434
new GamePlayer(Constants.PLAYER_NAME_NEUTRAL, true, false, null, false, null) {
3535
private static final long serialVersionUID = -6596127754502509049L;
@@ -50,7 +50,12 @@ public boolean isNull() {
5050
@Getter private ProductionFrontier productionFrontier;
5151
@Getter private RepairFrontier repairFrontier;
5252
private final TechnologyFrontierList technologyFrontiers;
53-
@Getter private String whoAmI = "null:no_one";
53+
54+
@Getter
55+
private String whoAmI =
56+
// @TODO why : separation, no_one also used in ServerSetupPanel; create constant
57+
"null:" + "no_one";
58+
5459
private TechAttachment techAttachment;
5560

5661
public GamePlayer(final String name, final GameData data) {
@@ -171,8 +176,8 @@ public boolean getIsDisabled() {
171176
}
172177

173178
/**
174-
* If I have no units with movement, And I own zero factories or have have no owned land, then I
175-
* am basically dead, and therefore should not participate in things like politics.
179+
* If I have no units with movement and I own zero factories or have no owned land, then I am
180+
* basically dead, and therefore should not participate in things like politics.
176181
*/
177182
public boolean amNotDeadYet() {
178183
for (final Territory t : getData().getMap().getTerritories()) {

game-app/game-core/src/main/java/games/strategy/engine/data/gameparser/GameParser.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package games.strategy.engine.data.gameparser;
22

3+
import static games.strategy.engine.framework.startup.ui.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL;
4+
35
import com.google.common.annotations.VisibleForTesting;
46
import com.google.common.base.Splitter;
57
import com.google.common.base.Strings;
@@ -419,7 +421,8 @@ private void parsePlayerList(final PlayerList playerListData) {
419421
current.getName(),
420422
Optional.ofNullable(current.getOptional()).orElse(false),
421423
Optional.ofNullable(current.getCanBeDisabled()).orElse(false),
422-
Optional.ofNullable(current.getDefaultType()).orElse("Human"),
424+
Optional.ofNullable(current.getDefaultType())
425+
.orElse(PLAYER_TYPE_HUMAN_LABEL),
423426
Optional.ofNullable(current.getIsHidden()).orElse(false),
424427
data)));
425428
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package games.strategy.engine.framework;
2+
3+
import org.jetbrains.annotations.Nls;
4+
5+
public class HtmlBuilder {
6+
final StringBuilder s = new StringBuilder();
7+
8+
public HtmlBuilder() {
9+
s.append("<html>");
10+
}
11+
12+
public HtmlBuilder addText(@Nls String text) {
13+
s.append(text);
14+
return this;
15+
}
16+
17+
public HtmlBuilder lineBreak() {
18+
s.append("</br>");
19+
return this;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return s.toString() + "</html>";
25+
}
26+
}

game-app/game-core/src/main/java/games/strategy/engine/framework/HtmlUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ private HtmlUtils() {}
1313
public static String getHtml(final String text) {
1414
return "<html>" + text + "</html>";
1515
}
16+
17+
public static HtmlBuilder getHtml() {
18+
return new HtmlBuilder();
19+
}
1620
}

game-app/game-core/src/main/java/games/strategy/engine/framework/I18nResourceBundle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.jetbrains.annotations.NonNls;
1212

1313
/**
14-
* This is the main i18n (internationalization) class to retrieve langauge dependent outputs. The
14+
* This is the main i18n (internationalization) class to retrieve language dependent outputs. The
1515
* subclasses of this class should implement a singleton pattern and define the path to the resource
1616
* property file(s).
1717
*/

game-app/game-core/src/main/java/games/strategy/engine/framework/startup/ui/PlayerTypes.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package games.strategy.engine.framework.startup.ui;
22

3+
import games.strategy.engine.framework.I18nEngineFramework;
34
import games.strategy.engine.player.Player;
45
import games.strategy.triplea.ai.fast.FastAi;
56
import games.strategy.triplea.ai.pro.ProAi;
@@ -17,26 +18,30 @@ public class PlayerTypes {
1718

1819
public static final String DOES_NOTHING_PLAYER_LABEL = "Does Nothing (AI)";
1920
public static final Type WEAK_AI =
20-
new Type("Easy (AI)") {
21+
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL")) {
2122
@Override
2223
public Player newPlayerWithName(final String name) {
2324
return new WeakAi(name, getLabel());
2425
}
2526
};
2627
public static final Type FAST_AI =
27-
new Type("Fast (AI)") {
28+
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL")) {
2829
@Override
2930
public Player newPlayerWithName(final String name) {
3031
return new FastAi(name, getLabel());
3132
}
3233
};
3334
public static final Type PRO_AI =
34-
new Type("Hard (AI)") {
35+
new Type(I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL")) {
3536
@Override
3637
public Player newPlayerWithName(final String name) {
3738
return new ProAi(name, getLabel());
3839
}
3940
};
41+
public static final String PLAYER_TYPE_DEFAULT_LABEL =
42+
I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL");
43+
public static final String PLAYER_TYPE_HUMAN_LABEL =
44+
I18nEngineFramework.get().getText("startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL");
4045

4146
Collection<Type> playerTypes;
4247

game-app/game-core/src/main/java/games/strategy/triplea/formatter/MyFormatter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public static String integerUnitMapToString(
408408
}
409409

410410
/**
411-
* Adds HTML line breaks and indentation to a string so it wraps for things like long tooltips.
411+
* Adds HTML line breaks and indentation to a string, so it wraps for things like long tooltips.
412412
*
413413
* <pre>
414414
* string part 1

game-app/game-core/src/main/resources/i18n/games/strategy/engine/framework/ui.properties

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
startup.MainPanel.btn.Cancel.Lbl=Cancel
2+
startup.MainPanel.btn.Network.Lbl=Network...
3+
startup.MainPanel.btn.Play.Lbl=Play
4+
startup.MainPanel.btn.Play.Tltp.line1=Start your game!
5+
startup.MainPanel.btn.Play.Tltp.line2=If not enabled, then you must select a way to play your game first:
6+
startup.MainPanel.btn.Play.Tltp.line3=Play Online, or Local Game, or PBEM, or Host Networked.
7+
startup.MainPanel.btn.Quit.Lbl=Quit
8+
startup.MainPanel.btn.Quit.Tltp=Close TripleA.
9+
startup.PbfSetupPanel.tab.ForumPosterEditor.Lbl=Play By Forum
10+
startup.PlayerSelectorRow.btn.Alliances.Tltp=Click to play {0}
11+
startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL=Client
12+
startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL=Human
13+
startup.ServerSetupPanel.infoPanel.Address.Lbl=Address:
14+
startup.ServerSetupPanel.infoPanel.Name.Lbl=Name:
15+
startup.ServerSetupPanel.infoPanel.Port.Lbl=Port:
16+
startup.SetupPanel.alliance.Lbl=Alliance
17+
startup.SetupPanel.bonusIncome.Lbl=Bonus Income
18+
startup.SetupPanel.btn.PlayerSelection.Lbl=Select Local Players and AI's
19+
startup.SetupPanel.enable.Lbl=Use
20+
startup.SetupPanel.income.Lbl=Income
21+
startup.SetupPanel.local.Lbl=Local
22+
startup.SetupPanel.name.Lbl=Name
23+
startup.SetupPanel.noGameSelected.Lbl=No game selected!
24+
startup.SetupPanel.noPlayers.Lbl=Load a game file first
25+
startup.SetupPanel.player.Lbl=Played By
26+
startup.SetupPanel.PlayerRow.alliance.Play.Tltp=Click to play {0}
27+
startup.SetupPanel.PlayerRow.alliance.Release.Tltp=Click to release {0}
28+
startup.SetupPanel.PlayerRow.Play=Play
29+
startup.SetupPanel.PlayerRow.TakeNoAction.Lbl=Don't Play
30+
startup.SetupPanel.PlayerSelection.Dialog.Title=Select Local Players and AI's
31+
startup.SetupPanel.resourceModifiers.Lbl=Resource Modifiers
32+
startup.SetupPanel.SET_ALL_DEFAULT_LABEL=Default
33+
startup.SetupPanel.setAllTo.Lbl=Set All To:
34+
startup.SetupPanel.type.Lbl=Type
135
startup.SetupPanelModel.btn.ConnectToNetworkedGame.Lbl=Connect to Networked Game
236
startup.SetupPanelModel.btn.EnginePreferences.Lbl=Engine Preferences
337
startup.SetupPanelModel.btn.EnginePreferences.Tltp=Configure certain options related to the engine.
@@ -9,15 +43,18 @@ startup.SetupPanelModel.btn.PlayByForum.Lbl=Play By Forum
943
startup.SetupPanelModel.btn.PlayByForum.Tltp=Starts a game which will be posted to an online forum or a message board.
1044
startup.SetupPanelModel.btn.PlayOnline.ConnectToNetworkedGame.Tltp=Connects to someone''s hosted game\
1145
<br/>=so long as you know their IP address.
46+
startup.SetupPanelModel.btn.PlayOnline.Lbl=Play Online
1247
startup.SetupPanelModel.btn.PlayOnline.HostNetworkGame.Tltp=Hosts a network game, which people can connect to.\
1348
<br/>=Anyone on a LAN will be able to connect.\
1449
<br/>=Anyone from the internet can connect as well, but only if the host has configured port forwarding correctly.
15-
startup.SetupPanelModel.btn.PlayOnline.Lbl=Play Online
1650
startup.SetupPanelModel.btn.PlayOnline.Tltp=Find Games Online on the Lobby Server.\
1751
<br/>=TripleA is MEANT to be played Online against other humans.\
1852
<br/>=Any other way is not as fun!
1953
startup.SetupPanelModel.btn.StartLocalGame.Lbl=Start Local Game
2054
startup.SetupPanelModel.btn.StartLocalGame.Tltp=Start a game on this computer.\
21-
<br/>=You can play against a friend sitting besides you (hotseat mode),\
55+
<br/>=You can play against a friend sitting beside you (hotseat mode),\
2256
<br/>=or against one of the AIs.
2357
startup.SetupPanelModel.btn.UserGuideHelp.Lbl=User Guide & Help
58+
startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL=Easy (AI)
59+
startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL=Fast (AI)
60+
startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL=Hard (AI)

game-app/game-core/src/main/resources/i18n/games/strategy/engine/framework/ui_de.properties

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
startup.MainPanel.btn.Cancel.Lbl=Abbrechen
2+
startup.MainPanel.btn.Network.Lbl=Netzwerk...
3+
startup.MainPanel.btn.Play.Lbl=Spiel
4+
startup.MainPanel.btn.Play.Tltp.line1=Starte Dein Spiel!
5+
startup.MainPanel.btn.Play.Tltp.line2=Wenn nicht ausw\u00E4hlbar, muss erst eine Spielweise ausgew\u00E4hlt werden:
6+
startup.MainPanel.btn.Play.Tltp.line3=Spiele online, ein lokales Spiel, PBEM oder \u00F6ffne ein Netzwerkspiel.
7+
startup.MainPanel.btn.Quit.Lbl=Beenden
8+
startup.MainPanel.btn.Quit.Tltp=Schließe TripleA.
9+
startup.PbfSetupPanel.tab.ForumPosterEditor.Lbl=Spiel per Forum
10+
startup.PlayerSelectorRow.btn.Alliances.Tltp=Klick um {0} zu spielen
11+
startup.PlayerTypes.PLAYER_TYPE_DEFAULT_LABEL=Client
12+
startup.PlayerTypes.PLAYER_TYPE_HUMAN_LABEL=Mensch
13+
startup.ServerSetupPanel.infoPanel.Address.Lbl=Adresse:
14+
startup.ServerSetupPanel.infoPanel.Name.Lbl=Name:
15+
startup.ServerSetupPanel.infoPanel.Port.Lbl=Port:
16+
startup.SetupPanel.alliance.Lbl=Allianz
17+
startup.SetupPanel.bonusIncome.Lbl=Bonuseinkommen
18+
startup.SetupPanel.btn.PlayerSelection.Lbl=W\u00E4hle lokale Spieler und KIs
19+
startup.SetupPanel.enable.Lbl=Use
20+
startup.SetupPanel.income.Lbl=Einkommen
21+
startup.SetupPanel.local.Lbl=Lokal
22+
startup.SetupPanel.name.Lbl=Name
23+
startup.SetupPanel.noGameSelected.Lbl=Kein Spiel ausgew\u00E4hlt!
24+
startup.SetupPanel.noPlayers.Lbl=Lade erst eine Spieldatei
25+
startup.SetupPanel.player.Lbl=Gespielt von
26+
startup.SetupPanel.PlayerRow.alliance.Play.Tltp=Klick um {0} zu spielen
27+
startup.SetupPanel.PlayerRow.alliance.Release.Tltp=Klick um {0} freizugeben
28+
startup.SetupPanel.PlayerRow.Play=Spiel
29+
startup.SetupPanel.PlayerRow.TakeNoAction.Lbl=Nicht spielen
30+
startup.SetupPanel.PlayerSelection.Dialog.Title=W\u00E4hle lokale Spieler und KIs
31+
startup.SetupPanel.resourceModifiers.Lbl=Ressourcen Modifikator
32+
startup.SetupPanel.SET_ALL_DEFAULT_LABEL=Standard
33+
startup.SetupPanel.setAllTo.Lbl=Alle setzen auf:
34+
startup.SetupPanel.type.Lbl=Typ
135
startup.SetupPanelModel.btn.ConnectToNetworkedGame.Lbl=Verbinde zum Netzwerkspiel
236
startup.SetupPanelModel.btn.EnginePreferences.Lbl=Kerneinstellungen
337
startup.SetupPanelModel.btn.EnginePreferences.Tltp=Konfiguriere bestimmte Kerneinstellungen
@@ -9,10 +43,10 @@ startup.SetupPanelModel.btn.PlayByForum.Lbl=Spiel per Forum
943
startup.SetupPanelModel.btn.PlayByForum.Tltp=Beginnt ein Spiel, welches in einem Internetforum oder einem Nachrichtenboard gepostet wird.
1044
startup.SetupPanelModel.btn.PlayOnline.ConnectToNetworkedGame.Tltp=Verbindet sich mit einem gehosteten Spiel,\
1145
<br/>=solange Du deren IP-Adresse kennst.
46+
startup.SetupPanelModel.btn.PlayOnline.Lbl=Spiel Online
1247
startup.SetupPanelModel.btn.PlayOnline.HostNetworkGame.Tltp=Hosted ein Netzwerkspiel, zu welchem sich andere verbinden k\u00F6nnen.\
1348
<br/>=Jeder im LAN wird sich verbinden k\u00F6nnen.\
1449
<br/>=Auch jeder aus dem Internet kann wird sich verbinden k\u00F6nnen, solange der Host Port-Weiterleitung eingestellt hat.
15-
startup.SetupPanelModel.btn.PlayOnline.Lbl=Spiel Online
1650
startup.SetupPanelModel.btn.PlayOnline.Tltp=Finde Spiele online auf dem Lobby-Server.\
1751
<br/>=TripleA ist daf\u00FCr gedacht, online gegen andere Menschen zu spielen.\
1852
<br/>=Alles andere macht keinen Spa\u00DF!
@@ -21,3 +55,6 @@ startup.SetupPanelModel.btn.StartLocalGame.Tltp=Start a game on this computer.\
2155
<br/>=Du kannst gegen einen Freund spielen, der neben Dir sitzt (Hotseat-Modus),\
2256
<br/>=oder gegen eine der KIs.
2357
startup.SetupPanelModel.btn.UserGuideHelp.Lbl=Spielanleitung & Hilfe
58+
startup.PlayerTypes.PLAYER_TYPE_AI_EASY_LABEL=Einfach (KI)
59+
startup.PlayerTypes.PLAYER_TYPE_AI_FAST_LABEL=Schnell (KI)
60+
startup.PlayerTypes.PLAYER_TYPE_AI_HARD_LABEL=Schwer (KI)

0 commit comments

Comments
 (0)