Skip to content

Commit 8dce57d

Browse files
committed
2 parents b0e9339 + d752266 commit 8dce57d

7 files changed

Lines changed: 386 additions & 262 deletions

File tree

.gitignore

-76 Bytes
Binary file not shown.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ This tool simplifies your work by providing an intuitive interface to work with.
1313
* This will load all the existing translations side by side with the key on the left side. You can then edit any field and the program will do the rest.
1414
* Yes you can drag and drop columns or sort them differently.
1515
* Do you want to delete or add a translation key ? Right click in the table to open the context menu.
16+
* If you run out of inspiration, you can use the 'Joker' button. This will autocomplete the cell based on Google Translate's answer. If you use this feature, please double check the result and keep the wacky translations at a minimum.
1617
* When you are done, click the save button to apply the changes. This will only affect changed files.
1718

1819
Note : this program doesn't care about comments and fancy line separators. Upon hitting save, all irrelevant information will be erased from any edited file.
1920

20-
![screenshot](https://cdn.discordapp.com/attachments/308583533667024907/340906115107913737/unknown.png)
21+
![screenshot](https://cdn.discordapp.com/attachments/308583533667024907/346244324897587202/unknown.png)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package ladysnake.translatorhelper.application;
2+
3+
import java.io.File;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Collectors;
8+
9+
import javafx.beans.property.SimpleBooleanProperty;
10+
import javafx.beans.property.SimpleStringProperty;
11+
import javafx.collections.FXCollections;
12+
import javafx.collections.ObservableList;
13+
import javafx.scene.control.ButtonType;
14+
import javafx.scene.control.Dialog;
15+
import javafx.scene.control.TableColumn;
16+
import javafx.scene.control.TableView;
17+
import javafx.scene.control.cell.CheckBoxTableCell;
18+
19+
public class SelectFilesDialog extends Dialog<Map<File, Boolean>> {
20+
21+
public SelectFilesDialog(List<File> files) {
22+
ObservableList<ExtendedFile> list = FXCollections
23+
.observableArrayList(files.stream()
24+
.map(f -> new ExtendedFile(f, true, false))
25+
.collect(Collectors.toList()));
26+
TableView<ExtendedFile> table = new TableView<>();
27+
table.setEditable(true);
28+
{
29+
TableColumn<ExtendedFile, String> col1 = new TableColumn<>("Open");
30+
col1.setCellFactory(c -> new CheckBoxTableCell<ExtendedFile, String>(i -> list.get(i).isToOpen()));
31+
col1.setEditable(true);
32+
table.getColumns().add(col1);
33+
}
34+
{
35+
TableColumn<ExtendedFile, String> col2 = new TableColumn<>("Lock");
36+
col2.setCellFactory(c -> new CheckBoxTableCell<ExtendedFile, String>(i -> list.get(i).isToLock()));
37+
col2.setEditable(true);
38+
table.getColumns().add(col2);
39+
}
40+
{
41+
TableColumn<ExtendedFile, String> col3 = new TableColumn<>("File");
42+
col3.setCellValueFactory(f -> new SimpleStringProperty(f.getValue().file.getName()));
43+
table.getColumns().add(col3);
44+
}
45+
table.setItems(list);
46+
this.getDialogPane().setContent(table);
47+
this.setTitle("File Selector");
48+
this.setHeaderText("Choose which files you wish to load or lock");
49+
this.getDialogPane().getButtonTypes().add(ButtonType.OK);
50+
this.setResultConverter(type -> {
51+
if(type == ButtonType.OK) {
52+
Map<File, Boolean> lockedMap = new HashMap<>();
53+
list.stream().peek(System.out::println).filter(f -> f.isToOpen().getValue()).forEach(f -> lockedMap.put(f.getFile(), f.isToLock().getValue()));
54+
return lockedMap;
55+
}
56+
return null;
57+
});
58+
}
59+
60+
private static class ExtendedFile {
61+
private File file;
62+
private SimpleBooleanProperty toOpen, toLock;
63+
64+
protected ExtendedFile(File file, boolean toOpen, boolean toLock) {
65+
super();
66+
this.file = file;
67+
this.toOpen = new SimpleBooleanProperty(toOpen);
68+
this.toLock = new SimpleBooleanProperty(toLock);
69+
}
70+
protected File getFile() {
71+
return file;
72+
}
73+
protected SimpleBooleanProperty isToOpen() {
74+
return toOpen;
75+
}
76+
protected SimpleBooleanProperty isToLock() {
77+
return toLock;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return "ExtendedFile [file=" + file + ", toOpen=" + toOpen + ", toLock=" + toLock + "]";
83+
}
84+
85+
}
86+
87+
}

src/ladysnake/translatorhelper/application/TranslationHelper.java

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package ladysnake.translatorhelper.application;
2-
2+
3+
import java.util.List;
34
import java.util.Map;
5+
import java.util.concurrent.ExecutorService;
6+
import java.util.concurrent.Executors;
7+
import java.util.function.Predicate;
48

59
import javafx.application.Application;
610
import javafx.collections.ObservableList;
@@ -9,6 +13,8 @@
913
import javafx.scene.Scene;
1014
import javafx.scene.control.Button;
1115
import javafx.scene.control.ContextMenu;
16+
import javafx.scene.control.Label;
17+
import javafx.scene.control.MenuButton;
1218
import javafx.scene.control.MenuItem;
1319
import javafx.scene.control.TableCell;
1420
import javafx.scene.control.TableColumn;
@@ -25,15 +31,33 @@
2531

2632

2733
public class TranslationHelper extends Application {
28-
34+
35+
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
36+
2937
private ControllerFx control;
3038
private Stage stage;
3139
private BorderPane borderPane;
32-
private ContextMenu contextMenu;
40+
private ContextMenu contextMenuTable;
3341
private TableView<Map<String, String>> trTable;
34-
42+
private Label statusLabel;
43+
3544
private Button wimpTrnslBtn;
3645
private Button saveBtn;
46+
private MenuButton newThing;
47+
48+
private static Callback<TableColumn<Map<String, String>, String>, TableCell<Map<String, String>, String>>
49+
cellFactoryForMap = p -> new TextFieldTableCell<Map<String, String>, String>(new StringConverter<String>() {
50+
@Override
51+
public String toString(String t) {
52+
if(t == null)
53+
return "";
54+
return t.toString();
55+
}
56+
@Override
57+
public String fromString(String string) {
58+
return string;
59+
}
60+
});
3761

3862
@Override
3963
public void start(Stage primaryStage) {
@@ -43,10 +67,10 @@ public void start(Stage primaryStage) {
4367
control = new ControllerFx(this);
4468

4569
stage.setOnCloseRequest(control::onExit);
46-
70+
4771
borderPane = new BorderPane();
4872
borderPane.setOnKeyPressed(control::onKeyPressed);
49-
73+
5074
GridPane grid = new GridPane();
5175
grid.setAlignment(Pos.CENTER);
5276
grid.setHgap(10);
@@ -56,98 +80,101 @@ public void start(Stage primaryStage) {
5680

5781
Scene scene = new Scene(borderPane,900,400);
5882
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
59-
83+
6084
{ // load button
61-
Button loadBtn = new Button();
62-
loadBtn.setText("Load a lang folder");
85+
Button loadBtn = new Button("Load a lang folder");
6386
loadBtn.setOnAction(control::onChooseFolder);
6487
grid.add(loadBtn, 0, 0, 2, 1);
6588
}
66-
89+
6790
{ // save button
68-
saveBtn = new Button();
69-
saveBtn.setText("Save");
91+
saveBtn = new Button("Save");
7092
saveBtn.setOnAction(control::onSave);
7193
saveBtn.setDisable(true);
7294
grid.add(saveBtn, 2, 0);
7395
}
74-
96+
7597
{
76-
wimpTrnslBtn = new Button();
77-
wimpTrnslBtn.setText("Joker");
98+
wimpTrnslBtn = new Button("Joker");
7899
wimpTrnslBtn.setOnAction(control::onJoker);
79100
Tooltip.install(wimpTrnslBtn, new Tooltip("Uses Google Translate to complete the cell based on the english value."));
80101
wimpTrnslBtn.setDisable(true);
81102
grid.add(wimpTrnslBtn, 3, 0);
82103
}
83104

105+
{
106+
MenuItem newLang = new MenuItem("language file");
107+
newLang.setOnAction(control::onNewFile);
108+
MenuItem newRow = new MenuItem("translation key");
109+
newRow.setOnAction(control::onInsertRow);
110+
newThing = new MenuButton("Add...", null, newLang, newRow);
111+
newThing.setDisable(true);
112+
grid.add(newThing, 4, 0);
113+
}
114+
84115
{ // context menu (right click)
85-
contextMenu = new ContextMenu();
116+
contextMenuTable = new ContextMenu();
86117
MenuItem item1 = new MenuItem("Delete row");
87118
item1.setOnAction(control::onDeleteRow);
88-
MenuItem item2 = new MenuItem("New translation key");
89-
item2.setOnAction(control::onInsertRow);
90-
contextMenu.getItems().addAll(item1, item2);
119+
MenuItem item2 = new MenuItem("Change translation key");
120+
item2.setOnAction(control::onEditRowKey);
121+
contextMenuTable.getItems().addAll(item1, item2);
91122
}
92-
123+
124+
{
125+
borderPane.setBottom(statusLabel = new Label("status: no lang folder selected"));
126+
}
127+
93128
primaryStage.setScene(scene);
94129
primaryStage.setTitle("Translation O Matik");
95130
primaryStage.show();
96-
131+
97132
} catch(Exception e) {
98133
e.printStackTrace();
99134
}
100135
}
101-
102-
public void generateTable(ObservableList<Map<String, String>> allTranslations, String[] langNames) {
136+
137+
public void generateTable(ObservableList<Map<String, String>> allTranslations, List<String> langNames, Predicate<String> isLocked) {
103138
trTable = new TableView<Map<String, String>>(allTranslations);
104139
trTable.setEditable(true);
105-
trTable.setContextMenu(contextMenu);
140+
trTable.setContextMenu(contextMenuTable);
106141
trTable.setOnSort(control::onSort);
107142
saveBtn.setDisable(false);
108143
wimpTrnslBtn.setDisable(false);
109-
110-
Callback<TableColumn<Map<String, String>, String>, TableCell<Map<String, String>, String>>
111-
cellFactoryForMap = p -> new TextFieldTableCell<Map<String, String>, String>(new StringConverter<String>() {
112-
@Override
113-
public String toString(String t) {
114-
if(t == null)
115-
return "";
116-
return t.toString();
117-
}
118-
@Override
119-
public String fromString(String string) {
120-
return string;
121-
}
122-
});
123-
144+
newThing.setDisable(false);
145+
124146
trTable.getColumns().clear();
125147

126-
for(int i = 0; i < langNames.length; i++) {
127-
TableColumn<Map<String, String>, String> langColumn = new TableColumn<>(langNames[i]);
128-
langColumn.setPrefWidth(300);
129-
langColumn.setCellValueFactory(new MapValueFactory(langNames[i]));
130-
langColumn.setCellFactory(cellFactoryForMap);
131-
if(i == 0)
132-
langColumn.setOnEditCommit(control::onEditCommitKey);
133-
else
134-
langColumn.setOnEditCommit(control::onEditCommit);
135-
trTable.getColumns().add(langColumn);
148+
for(String lang : langNames) {
149+
addColumn(lang, isLocked.test(lang));
136150
}
137-
138-
System.out.println(allTranslations);
139-
151+
140152
borderPane.setCenter(trTable);
141153
}
142-
154+
155+
@SuppressWarnings("rawtypes")
156+
public void addColumn(String lang, boolean locked) {
157+
TableColumn<Map<String, String>, String> langColumn = new TableColumn<>(lang);
158+
langColumn.setPrefWidth(300);
159+
langColumn.setCellValueFactory(new MapValueFactory(lang));
160+
langColumn.setCellFactory(cellFactoryForMap);
161+
langColumn.setEditable(!locked);
162+
langColumn.setOnEditCommit(control::onEditCommit);
163+
trTable.getColumns().add(langColumn);
164+
}
165+
166+
public void setStatus(String status) {
167+
this.statusLabel.setText("status: " + status);
168+
}
169+
143170
public TableView<Map<String, String>> getTable() {
144171
return this.trTable;
145172
}
146-
173+
147174
public Stage getStage() {
148175
return this.stage;
149176
}
150-
177+
151178
public static void main(String[] args) {
152179
launch(args);
153180
}

0 commit comments

Comments
 (0)