Skip to content

Commit

Permalink
Internationalization of MeepleView.java's tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsugu committed Feb 20, 2024
1 parent ad233ce commit 313bc5f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package carcassonne.view.secondary;

import java.lang.System;
import java.util.HashMap;
import java.util.ResourceBundle;
import java.util.Locale;
import java.io.File;
import java.nio.file.Paths;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.MalformedURLException;

/**
* Load text for MeepleView.java
* @author Mitsugu Oyama
*/
public class LoadTextMeepleView {
private HashMap<String, String> hmResult;

public LoadTextMeepleView() {
ResourceBundle rb;
rb = ResourceBundle.getBundle("RBView");
hmResult = new HashMap<String, String>();

hmResult.put("PLACE_MEEPEL", rb.getString("MV_PLACE_MEEPEL.text"));
hmResult.put("BRACKET", rb.getString("MV_BRACKET.text"));
hmResult.put("DONT_PLACE_MEEPLE", rb.getString("MV_DONT_PLACE_MEEPLE.text"));
hmResult.put("CENTER", rb.getString("MV_CENTER.text"));
hmResult.put("EAST", rb.getString("MV_EAST.text"));
hmResult.put("WEST", rb.getString("MV_WEST.text"));
hmResult.put("NORTH", rb.getString("MV_NORTH.text"));
hmResult.put("SOUTH", rb.getString("MV_SOUTH.text"));
hmResult.put("NORTH_EAST", rb.getString("MV_NORTH_EAST.text"));
hmResult.put("NORTH_WEST", rb.getString("MV_NORTH_WEST.text"));
hmResult.put("SOUTH_EAST", rb.getString("MV_SOUTH_EAST.text"));
hmResult.put("SOUTH_WEST", rb.getString("MV_SOUTH_WEST.text"));
}

public String get(String key) {
return " " + hmResult.get(key.toUpperCase().replaceAll(" ","_"));
}
}

18 changes: 15 additions & 3 deletions src/main/java/carcassonne/view/secondary/MeepleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class MeepleView extends SecondaryView {
private Map<GridDirection, JButton> meepleButtons;
private Color defaultButtonColor;
private Tile tile;
private String PLACE_MEEPEL;
private String BRACKET;
private String DONT_PLACE_MEEPLE;
private LoadTextMeepleView properties;

/**
* Creates the view.
Expand All @@ -35,6 +39,7 @@ public class MeepleView extends SecondaryView {
*/
public MeepleView(ControllerFacade controller, MainView ui) {
super(controller, ui);
initResouece();
buildButtonSkip();
buildButtonGrid();
pack();
Expand Down Expand Up @@ -64,7 +69,7 @@ private void buildButtonGrid() {
int index = 0;
for (GridDirection direction : GridDirection.byRow()) {
JButton button = new PlacementButton(controller, direction);
button.setToolTipText("Place Meeple on the " + direction.toReadableString() + " of the tile.");
button.setToolTipText(PLACE_MEEPEL + properties.get(direction.toReadableString()) + BRACKET);
constraints.gridx = index % 3; // from 0 to 2
constraints.gridy = index / 3 + 1; // from 1 to 3
dialogPanel.add(button, constraints);
Expand All @@ -75,7 +80,7 @@ private void buildButtonGrid() {

private void buildButtonSkip() {
JButton buttonSkip = new JButton(ImageLoadingUtil.SKIP.createHighDpiImageIcon());
buttonSkip.setToolTipText("Don't place meeple and preserve for later use");
buttonSkip.setToolTipText(DONT_PLACE_MEEPLE);
defaultButtonColor = buttonSkip.getBackground();
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
Expand Down Expand Up @@ -106,4 +111,11 @@ private void updatePlacementButtons() {
}
}
}
}

private void initResouece() {
properties = new LoadTextMeepleView();
PLACE_MEEPEL = properties.get("PLACE_MEEPEL");
BRACKET = properties.get("BRACKET");
DONT_PLACE_MEEPLE = properties.get("DONT_PLACE_MEEPLE");
}
}
12 changes: 12 additions & 0 deletions src/main/resources/RBView.properties
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,15 @@ TV_SKIP_TURN.text=Don't place tile and skip turn
TV_TOOL_TIP.text=Tile of type
GML_ABOUT.text=\nThe board game Carcassonne is created by Klaus-Jürgen Wrede and published by Hans im Glück.\nThis computer game based on the board game is developed by Timur Sağlam.
GML_TITLE.text=Carcassonne
MV_PLACE_MEEPEL.text=Place Meeple on the
MV_BRACKET.text= of the tile.
MV_DONT_PLACE_MEEPLE.text=Don't place meeple and preserve for later use
MV_CENTER.text=center
MV_EAST.text=east
MV_WEST.text=west
MV_NORTH.text=north
MV_SOUTH.text=south
MV_NORTH_EAST.text=north east
MV_NORTH_WEST.text=north west
MV_SOUTH_EAST.text=south east
MV_SOUTH_WEST.text=south west
12 changes: 12 additions & 0 deletions src/main/resources/RBView_ja_JP.properties
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,15 @@ TV_ROTATE_LEFT.text=左にタイルを回す
TV_ROTATE_RIGHT.text=右にタイルを回す
GML_ABOUT.text=\nボードゲームカルカソンヌは Klaus-Jürgen Wrede によって作成され、Hans im Glück により出版されました。\nボードゲームカルカソンヌをベースにしたこのコンピューター・ゲームは、Timur Sağlam によって開発されました。
GML_TITLE.text=Carcassonne
MV_PLACE_MEEPEL.text=ミープルを
MV_BRACKET.text= のタイルの上に置きます。
MV_DONT_PLACE_MEEPLE.text=ミープルはタイルに置かず、後で使うために取っておきます。
MV_CENTER.text=中央
MV_EAST.text=東
MV_WEST.text=西
MV_NORTH.text=北
MV_SOUTH.text=南
MV_NORTH_EAST.text=北東
MV_NORTH_WEST.text=北西
MV_SOUTH_EAST.text=南東
MV_SOUTH_WEST.text=南西

0 comments on commit 313bc5f

Please sign in to comment.