Skip to content

Commit

Permalink
localisation for table, buttons
Browse files Browse the repository at this point in the history
* new loc files: Buttons, Headers
  • Loading branch information
hansi-b committed Dec 16, 2024
1 parent 65b0c5b commit 6e8372c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hansib.simplertimes.fx.l10n.Buttons;
import org.hansib.sundries.ResourceLoader;
import org.hansib.sundries.fx.AlertBuilder;
import org.hansib.sundries.prefs.PrimitiveBooleanPref;
Expand Down Expand Up @@ -70,8 +71,8 @@ private boolean askAcceptDisclaimer() {
return new AlertBuilder(AlertType.CONFIRMATION, new VBox(textArea)) //
.withTitle("SimplerTimes - Disclaimer") //
.withHeaderText("SimplerTimes - Disclaimer") //
.withDefaultButton(ButtonType.CANCEL, "Cancel") //
.withButton(ButtonType.OK, "OK") //
.withDefaultButton(ButtonType.CANCEL, Buttons.Cancel.fmt()) //
.withButton(ButtonType.OK, Buttons.Ok.fmt()) //
.resizable(true) //
.showAndWaitFor(ButtonType.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.hansib.simplertimes.fx.data.FxProject;
import org.hansib.simplertimes.fx.data.FxSpan;
import org.hansib.simplertimes.fx.data.ObservableData;
import org.hansib.simplertimes.fx.l10n.Buttons;
import org.hansib.simplertimes.fx.l10n.Headers;
import org.hansib.simplertimes.times.Utils;
import org.hansib.sundries.fx.AlertBuilder;
import org.hansib.sundries.fx.ContextMenuBuilder;
Expand Down Expand Up @@ -127,7 +129,7 @@ void initialize() {
spansTable.setEditable(true);
spansTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

new TableColumnBuilder<>(startCol).headerText("Start") //
new TableColumnBuilder<>(startCol).headerText(Headers.Start.fmt()) //
.value(FxSpan::start) //
.cellFactory(list -> new EditingCell<>(dtHandler.getConverter(), //
(cell, text) -> {
Expand All @@ -138,7 +140,7 @@ void initialize() {
.onEditCommit(e -> setNewDateTime(e, FxSpan::start)) //
.build();

new TableColumnBuilder<>(endCol).headerText("End") //
new TableColumnBuilder<>(endCol).headerText(Headers.End.fmt()) //
.value(FxSpan::end) //
.cellFactory(list -> new EditingCell<>(dtHandler.getConverter(), //
(cell, text) -> {
Expand All @@ -149,14 +151,14 @@ void initialize() {
.onEditCommit(e -> setNewDateTime(e, FxSpan::end)) //
.build();

new TableColumnBuilder<>(projectCol).headerText("Project") //
new TableColumnBuilder<>(projectCol).headerText(Headers.Project.fmt()) //
.value(FxSpan::fxProject) //
.cellFactory(list -> new ProjectComboBoxTableCell(projects, updateHandler)) //
.editable() //
.comparator(FxProject.nameComparator) //
.build();

new TableColumnBuilder<>(durationCol).headerText("Duration") //
new TableColumnBuilder<>(durationCol).headerText(Headers.Duration.fmt()) //
.value(FxSpan::duration) //
.cellFactory(new CellFactoryBuilder<>(durationCol).format(Utils::toHmsString).build()) //
.build();
Expand Down Expand Up @@ -206,8 +208,8 @@ private void deleteSelected() {

boolean userAgreed = new AlertBuilder(AlertType.WARNING,
"The deletion of the %d selected item(s) cannot be undone.".formatted(selectedItems.size())) //
.withDefaultButton(ButtonType.CANCEL, "Cancel") //
.withButton(ButtonType.YES, "Delete") //
.withDefaultButton(ButtonType.CANCEL, Buttons.Cancel.fmt()) //
.withButton(ButtonType.YES, Buttons.Delete.fmt()) //
.showAndWaitFor(ButtonType.YES);

if (userAgreed) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*-
* GPL for SimplerTimes - https://github.com/hansi-b/SimplerTimes
*
* Copyright (C) 2022-2023 Hans Bering
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.hansib.simplertimes.fx.l10n;

import org.hansib.sundries.l10n.FormatKey;

public enum Buttons implements FormatKey {
Ok, //
Cancel, //
Delete
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*-
* GPL for SimplerTimes - https://github.com/hansi-b/SimplerTimes
*
* Copyright (C) 2022-2023 Hans Bering
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.hansib.simplertimes.fx.l10n;

import org.hansib.sundries.l10n.FormatKey;

public enum Headers implements FormatKey {
Start, //
End, //
Project, //
Duration
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public static L10n activateEnglish() {

@VisibleForTesting
static L10n loadEnglish(Consumer<L10nFormatError> errorHandler) {
L10n english = new L10n().with(General.class).with(MenuItems.class).with(Names.class);
L10n english = new L10n().with(General.class) //
.with(MenuItems.class).with(Names.class) //
.with(Buttons.class).with(Headers.class);
english.load("l10n", Locales.en, errorHandler);
return english;
}
Expand Down
6 changes: 6 additions & 0 deletions simplerTimesFx/src/main/resources/l10n/Buttons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Cancel:
en: Cancel
Ok:
en: OK
Delete:
en: Delete
8 changes: 8 additions & 0 deletions simplerTimesFx/src/main/resources/l10n/Headers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Project:
en: Project
Start:
en: Start
End:
en: End
Duration:
en: Duration

0 comments on commit 6e8372c

Please sign in to comment.