Commit 9edfab5d authored by Kristyna Fuchsova's avatar Kristyna Fuchsova Committed by Ondřej Hrdlička
Browse files

Adds localisation dependant on the count or values

parent cb8181af
Loading
Loading
Loading
Loading
+5 −17
Original line number Original line Diff line number Diff line
package cz.muni.fi.pv168.project.data.category;
package cz.muni.fi.pv168.project.data.category;


import cz.muni.fi.pv168.project.data.Identifiable;
import cz.muni.fi.pv168.project.data.Identifiable;
import cz.muni.fi.pv168.project.ui.i18n.I18N;
import org.joda.time.Duration;
import org.joda.time.Duration;
import org.joda.time.PeriodType;
import org.joda.time.PeriodType;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;


import java.awt.Color;
import java.awt.*;
import java.time.LocalDate;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
@@ -14,18 +13,17 @@ import java.util.Objects;


public class Category implements Identifiable {
public class Category implements Identifiable {


    private static final I18N I18N = new I18N(Category.class);

    private Long id;
    private Long id;
    private String name;
    private String name;
    private Color color;
    private Color color;
    private List<CategoryTime> timeSpents;
    private List<CategoryTime> timeSpents;


    private final PeriodFormatter periodicFormatter;

    public Category(String name, Color color) {
    public Category(String name, Color color) {
        this.timeSpents = new ArrayList<>();
        this.timeSpents = new ArrayList<>();
        this.name = name;
        this.name = name;
        this.color = color;
        this.color = color;
        this.periodicFormatter = createFormatter();
    }
    }


    public String getName() {
    public String getName() {
@@ -51,7 +49,7 @@ public class Category implements Identifiable {


    public String getTimeDurationFormatted(LocalDate fromDate, LocalDate toDate) {
    public String getTimeDurationFormatted(LocalDate fromDate, LocalDate toDate) {
        final var dayTimePeriod = getTotalDuration(fromDate, toDate).toPeriod().normalizedStandard(PeriodType.dayTime());
        final var dayTimePeriod = getTotalDuration(fromDate, toDate).toPeriod().normalizedStandard(PeriodType.dayTime());
        return periodicFormatter.print(dayTimePeriod).strip();
        return I18N.getFormattedMessage("timePeriodFormat", dayTimePeriod.getDays(), dayTimePeriod.getHours());
    }
    }


    public Duration getTotalDuration(LocalDate fromDate, LocalDate toDate) {
    public Duration getTotalDuration(LocalDate fromDate, LocalDate toDate) {
@@ -79,16 +77,6 @@ public class Category implements Identifiable {
        timeSpents.removeIf(categoryTime -> categoryTime.getTaskId().equals(taskId));
        timeSpents.removeIf(categoryTime -> categoryTime.getTaskId().equals(taskId));
    }
    }


    //TODO: add support for language structures in localization
    private PeriodFormatter createFormatter() {
        return new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" days ")
                .appendHours()
                .appendSuffix(" hours")
                .toFormatter();
    }

    public Long getId() {
    public Long getId() {
        return id;
        return id;
    }
    }
+4 −4
Original line number Original line Diff line number Diff line
package cz.muni.fi.pv168.project.data.task;
package cz.muni.fi.pv168.project.data.task;


import java.util.Locale;
import cz.muni.fi.pv168.project.ui.i18n.I18N;


public enum TaskStatus {
public enum TaskStatus {
    ALL,
    ALL,
@@ -8,11 +8,11 @@ public enum TaskStatus {
    IN_PROGRESS,
    IN_PROGRESS,
    FINISHED;
    FINISHED;


    private static final I18N I18N = new I18N(TaskStatus.class);

    @Override
    @Override
    public String toString() {
    public String toString() {
        String value = this.name().replace("_", " ");
        return I18N.getString(this);
        //TODO: solve hardcoded locale of root
        return value.charAt(0) + value.substring(1).toLowerCase(Locale.ROOT);
    }
    }


    public String upperCaseString() {
    public String upperCaseString() {
+0 −1
Original line number Original line Diff line number Diff line
@@ -10,7 +10,6 @@ public final class I18N {


    public I18N(Class<?> clazz) {
    public I18N(Class<?> clazz) {
        var packagePath = clazz.getPackageName().replace(".", "/") + '/';
        var packagePath = clazz.getPackageName().replace(".", "/") + '/';
        System.out.println(packagePath);
        bundle = ResourceBundle.getBundle(packagePath + "i18n");
        bundle = ResourceBundle.getBundle(packagePath + "i18n");
        prefix = clazz.getSimpleName() + ".";
        prefix = clazz.getSimpleName() + ".";
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -43,7 +43,7 @@ public class CategoryAndStatisticsView implements Tab<Category> {
        TabActions tabActions = TabActions.builder()
        TabActions tabActions = TabActions.builder()
                .addLeftSideAction(new AddAction<>(this, Icons.ADD_CATEGORY_ICON, I18N.getString("addActionDesc")))
                .addLeftSideAction(new AddAction<>(this, Icons.ADD_CATEGORY_ICON, I18N.getString("addActionDesc")))
                .addLeftSideAction(new EditAction<>(this, Icons.EDIT_CATEGORY_ICON, I18N.getString("editActionDesc")))
                .addLeftSideAction(new EditAction<>(this, Icons.EDIT_CATEGORY_ICON, I18N.getString("editActionDesc")))
                //TODO: edit locale accroding to count
                //TODO: needs refactor with a variable holding selectedCount of categories to be deleted for a proper localisation
                .addLeftSideAction(new DeleteAction<>(this, Icons.REMOVE_CATEGORY_BIN_ICON, I18N.getString("deleteActionDesc"))
                .addLeftSideAction(new DeleteAction<>(this, Icons.REMOVE_CATEGORY_BIN_ICON, I18N.getString("deleteActionDesc"))
                        .addEnabledCondition(selectedCount -> daoHolder
                        .addEnabledCondition(selectedCount -> daoHolder
                                .getTaskDao()
                                .getTaskDao()
+2 −2
Original line number Original line Diff line number Diff line
@@ -80,8 +80,8 @@ public class TaskView implements Tab<Task> {
                .addLeftSideAction(new AddAction<>(this, Icons.ADD_TASK_ICON, I18N.getString("addActionDesc")))
                .addLeftSideAction(new AddAction<>(this, Icons.ADD_TASK_ICON, I18N.getString("addActionDesc")))
                .addLeftSideAction(new EditAction<>(this, Icons.EDIT_TASK_ICON, I18N.getString("editActionDesc"), headerList::getSelectedValue)
                .addLeftSideAction(new EditAction<>(this, Icons.EDIT_TASK_ICON, I18N.getString("editActionDesc"), headerList::getSelectedValue)
                        .addUpdatable(taskPanel))
                        .addUpdatable(taskPanel))
                //TODO: edit locale accroding to count
                //TODO: needs refactor with a variable holding selectedCount of tasks to be deleted for a proper localisation
                .addLeftSideAction(new DeleteAction<>(this, Icons.REMOVE_TASK_BIN_ICON, I18N.getString("deleteActionDesc"))
                .addLeftSideAction(new DeleteAction<>(this, Icons.REMOVE_TASK_BIN_ICON, I18N.getFormattedMessage("deleteActionDesc"))
                        .addEnabledCondition(selectedCount -> daoHolder
                        .addEnabledCondition(selectedCount -> daoHolder
                                .getTaskDao()
                                .getTaskDao()
                                .getAll()
                                .getAll()
Loading