Skip to content

Commit d37f00c

Browse files
committed
I18n stuff for the task properties dialog
1 parent 4c439af commit d37f00c

3 files changed

Lines changed: 45 additions & 16 deletions

File tree

ganttproject/src/main/java/biz/ganttproject/app/PropertySheet.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class PropertyPaneBuilder(private val localizer: Localizer, private val gridPane
8585
rowBuilders.add(LabelRowBuilder(title.value, "title"))
8686
}
8787

88+
fun title(title: String) = title(localizer.create(title))
89+
8890
fun skip(rowNum: Int = 1) {
8991
rowBuilders.add(LabelRowBuilder("\n".repeat(rowNum), "skip"))
9092
}
@@ -181,7 +183,9 @@ class PropertyPaneBuilder(private val localizer: Localizer, private val gridPane
181183
private fun <E: Enum<E>> createEnumerationOptionEditor(
182184
option: ObservableEnum<E>, displayOptions: DropdownDisplayOptions<E>? = null): Node {
183185

184-
val key2i18n: List<Pair<E, String>> = option.allValues.map { it to localizer.formatText("$it.label") }.toList()
186+
val key2i18n: List<Pair<E, String>> = option.allValues.map {
187+
it to localizer.formatText("${option.id}.value.${it.name.lowercase()}")
188+
}.toList()
185189
return ComboBox(FXCollections.observableArrayList(key2i18n)).also { comboBox ->
186190
comboBox.onAction = EventHandler{
187191
option.set(comboBox.value.first, comboBox)

ganttproject/src/main/java/net/sourceforge/ganttproject/gui/taskproperties/MainPropertiesPanel.kt

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
1919
package net.sourceforge.ganttproject.gui.taskproperties
2020

2121
import biz.ganttproject.app.LabelPosition
22+
import biz.ganttproject.app.MappingLocalizer
2223
import biz.ganttproject.app.PropertySheetBuilder
2324
import biz.ganttproject.app.RootLocalizer
2425
import biz.ganttproject.colorFromUiManager
@@ -46,20 +47,21 @@ import javax.swing.SwingUtilities
4647

4748
class MainPropertiesPanel(private val task: Task, private val taskView: TaskView) {
4849
val title: String = RootLocalizer.formatText("general")
50+
4951
private val nameOption = ObservableString("name", task.name)
5052
private val milestoneOption = ObservableBoolean("milestone", task.isMilestone)
5153
private val taskDatesController = TaskDatesController(task, milestoneOption)
5254
private val projectTaskOption = ObservableBoolean("projectTask", task.isProjectTask)
5355
private val hasEarliestStart = ObservableBoolean("hasEarliestStart", task.thirdDateConstraint == 1)
54-
private val earliestStartOption = ObservableDate("earliestStart", if (task.thirdDateConstraint == 1 ) task.third.toLocalDate() else null)
56+
private val earliestStartOption = ObservableDate("earliestBegin", if (task.thirdDateConstraint == 1 ) task.third.toLocalDate() else null)
5557
private val priorityOption = ObservableEnum<Priority>("priority", task.priority, Priority.entries.toTypedArray())
5658
private val progressOption = ObservableInt("progress", task.completionPercentage)
5759
private val showInTimelineOption = ObservableBoolean("showInTimeline", taskView.timelineTasks.contains(task))
5860
private val colorOption = ObservableColor("color", Style.Color.parse(ColorOption.Util.getColor(task.color)))
5961
private val notesOption = ObservableString("notes", task.notes)
6062
private val webLinkOption = ObservableString("webLink", task.webLink)
6163
private val textureOption = ObservableEnum("texture", TaskTexture.find(task.shape) ?: TaskTexture.TRANSPARENT, TaskTexture.values())
62-
private val copyStartDateAction = GPAction.create("Copy Start Date") {
64+
private val copyStartDateAction = GPAction.create("option.taskProperties.main.earliestBegin.copyBeginDate") {
6365
earliestStartOption.set(taskDatesController.startDateOption.value)
6466
}.also {
6567
it.putValue(GPAction.TEXT_DISPLAY, ContentDisplay.TEXT_ONLY)
@@ -77,10 +79,10 @@ class MainPropertiesPanel(private val task: Task, private val taskView: TaskView
7779
}
7880

7981
fun getFxNode() = StackPane().apply {
80-
background = Background(BackgroundFill("Panel.background".colorFromUiManager(), CornerRadii.EMPTY, Insets.EMPTY))
81-
val leftPane = PropertySheetBuilder(RootLocalizer).pane {
82+
background = Background(BackgroundFill("Panel.background".colorFromUiManager(), CornerRadii.EMPTY, Insets.EMPTY))
83+
val leftPane = PropertySheetBuilder(i18n).pane {
8284
stylesheet("/biz/ganttproject/task/TaskPropertiesDialog.css")
83-
title(RootLocalizer.create("Main Properties"))
85+
title("section.main")
8486
text(nameOption)
8587
if (task.canBeProjectTask()) {
8688
checkbox(projectTaskOption)
@@ -121,7 +123,7 @@ class MainPropertiesPanel(private val task: Task, private val taskView: TaskView
121123
}
122124

123125
skip()
124-
title(RootLocalizer.create("View"))
126+
title("section.view")
125127
checkbox(showInTimelineOption)
126128
color(colorOption)
127129
dropdown(textureOption) {
@@ -134,16 +136,16 @@ class MainPropertiesPanel(private val task: Task, private val taskView: TaskView
134136
}
135137
val grid = GridPane()
136138

137-
val rightPane = PropertySheetBuilder(RootLocalizer).pane {
139+
val rightPane = PropertySheetBuilder(i18n).pane {
138140
stylesheet("/biz/ganttproject/task/TaskPropertiesDialog.css")
139-
title(RootLocalizer.create("Documents"))
141+
title("section.documents")
140142
text(notesOption) {
141143
isMultiline = true
142144
labelPosition = LabelPosition.ABOVE
143145
}
144146
text(webLinkOption) {
145147
editorStyles.add("weblink")
146-
rightNode = Button("Open", FontAwesomeIconView(FontAwesomeIcon.EXTERNAL_LINK)).also {
148+
rightNode = Button(i18n.formatTextOrNull("btn.open"), FontAwesomeIconView(FontAwesomeIcon.EXTERNAL_LINK)).also {
147149
it.contentDisplay = ContentDisplay.LEFT
148150
it.onAction = EventHandler { e ->
149151
webLinkOption.value?.let {
@@ -232,3 +234,26 @@ private fun Task.isProjectTaskOrContainsProjectTask(): Boolean {
232234
}
233235
return this.nestedTasks.any { it.isProjectTaskOrContainsProjectTask() }
234236
}
237+
238+
private val labelLocalizer = MappingLocalizer(mapOf(
239+
"startDate" to { RootLocalizer.create("dateOfBegining") },
240+
"endDate" to { RootLocalizer.create("dateOfEnd") },
241+
"progress" to { RootLocalizer.create("advancement") },
242+
"milestone" to { RootLocalizer.create("meetingPoint") },
243+
"notes" to { RootLocalizer.create("notesTask") },
244+
"color" to { RootLocalizer.create("colors") },
245+
"texture" to { RootLocalizer.create("shape") },
246+
), unhandledKey = RootLocalizer::create)
247+
248+
private val fallback = MappingLocalizer(mapOf(
249+
), unhandledKey = {
250+
when {
251+
it.endsWith(".label") -> labelLocalizer.create(it.removeSuffix(".label"))
252+
it.startsWith("priority.value.") -> RootLocalizer.create("priority.${it.removePrefix("priority.value.")}")
253+
it == "btn.open" -> RootLocalizer.create("storage.action.open")
254+
else -> null
255+
}
256+
})
257+
258+
private val i18n = RootLocalizer.createWithRootKey("option.taskProperties.main", baseLocalizer = fallback)
259+

ganttproject/src/main/java/net/sourceforge/ganttproject/gui/taskproperties/TaskDatesController.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class TaskDatesController(private val task: Task, milestoneOption: ObservableBoo
4343
internal val startDateOption = ObservableDate("startDate", task.start.toLocalDate())
4444
internal val endDateOption = ObservableDate("endDate", task.end.toLocalDate())
4545
internal val durationOption = ObservableInt("duration", task.duration.value.toInt())
46-
internal val schedulingOptions = ObservableEnum("schedulingOptions", CalculatedPart.END_DATE,
46+
internal val schedulingOptions = ObservableEnum("scheduling.manual", CalculatedPart.END,
4747
CalculatedPart.entries.toTypedArray()
4848
)
4949

5050
private fun onSchedulingOptionChange(calculatedPart: CalculatedPart) {
5151
when (calculatedPart) {
52-
CalculatedPart.START_DATE -> {
52+
CalculatedPart.START -> {
5353
startDateOption.setWritable(false)
5454
endDateOption.setWritable(true)
5555
durationOption.setWritable(true)
5656
}
57-
CalculatedPart.END_DATE -> {
57+
CalculatedPart.END -> {
5858
endDateOption.setWritable(false)
5959
startDateOption.setWritable(true)
6060
durationOption.setWritable(true)
@@ -107,13 +107,13 @@ class TaskDatesController(private val task: Task, milestoneOption: ObservableBoo
107107
private fun setLength(length: Int) {
108108
durationOption.set(length, this)
109109
when (schedulingOptions.value) {
110-
CalculatedPart.START_DATE -> {
110+
CalculatedPart.START -> {
111111
val startDate =
112112
if (isMilestone) endDateOption.value!!
113113
else DateParser.toLocalDate(calendar.shiftDate(DateParser.toJavaDate(endDateOption.value), durationOption.asTaskDuration().reverse()))
114114
setStart(startDate, false)
115115
}
116-
CalculatedPart.END_DATE -> {
116+
CalculatedPart.END -> {
117117
val endDate =
118118
if (isMilestone) startDateOption.value!!
119119
else DateParser.toLocalDate(calendar.shiftDate(DateParser.toJavaDate(startDateOption.value), durationOption.asTaskDuration()))
@@ -167,5 +167,5 @@ class TaskDatesController(private val task: Task, milestoneOption: ObservableBoo
167167
}
168168

169169
internal enum class CalculatedPart {
170-
START_DATE, END_DATE, DURATION
170+
START, END, DURATION
171171
}

0 commit comments

Comments
 (0)