Skip to content

Commit ef896e2

Browse files
committed
Initial machinery to have friendly strings respecting plurals
1 parent ab59ab3 commit ef896e2

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

src/Objects/Reminder.vala

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,25 @@ namespace Reminduck {
2222
EVERY_MONTH,
2323
NONE;
2424

25-
public string to_friendly_string (int? interval = null) {
25+
public string to_friendly_string (int? interval = 0) {
2626
switch (this) {
2727
case NONE: return _("Don't Repeat");
28-
29-
case EVERY_X_MINUTES:
30-
if (interval == null || interval == 0) {
31-
return _("Minutes");
32-
} else {
33-
return GLib.ngettext ("Every minute", "Every %d minutes", interval).printf (interval);
34-
}
35-
36-
case EVERY_X_HOURS: return _("Hour");
37-
case EVERY_DAY: return _("Day");
38-
case EVERY_WEEK: return _("Week");
39-
case EVERY_MONTH: return _("Month");
40-
41-
default:
42-
assert_not_reached ();
28+
case EVERY_X_MINUTES: return GLib.ngettext ("Minute", "Minutes", interval);
29+
case EVERY_X_HOURS: return GLib.ngettext ("Hour", "Hours", interval);
30+
case EVERY_DAY: return GLib.ngettext ("Day", "Days", interval);
31+
case EVERY_WEEK: return GLib.ngettext ("Week", "Weeks", interval);
32+
case EVERY_MONTH: return GLib.ngettext ("Month", "Months", interval);
33+
default: assert_not_reached ();
4334
}
4435
}
4536

46-
public static string[] choices () {
37+
public static string[] choices (int? interval = 0) {
4738
return {
48-
RecurrencyType.EVERY_X_MINUTES.to_friendly_string (),
49-
RecurrencyType.EVERY_X_HOURS.to_friendly_string (),
50-
RecurrencyType.EVERY_DAY.to_friendly_string (),
51-
RecurrencyType.EVERY_WEEK.to_friendly_string (),
52-
RecurrencyType.EVERY_MONTH.to_friendly_string ()
39+
RecurrencyType.EVERY_X_MINUTES.to_friendly_string (interval),
40+
RecurrencyType.EVERY_X_HOURS.to_friendly_string (interval),
41+
RecurrencyType.EVERY_DAY.to_friendly_string (interval),
42+
RecurrencyType.EVERY_WEEK.to_friendly_string (interval),
43+
RecurrencyType.EVERY_MONTH.to_friendly_string (interval)
5344
};
5445
}
5546
}

src/Widgets/RepeatBox.vala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Reminduck.Repeatbox : Gtk.Box {
5151
};
5252
every_label.add_css_class (Granite.STYLE_CLASS_H4_LABEL);
5353

54-
dropdown = new Gtk.DropDown.from_strings (RecurrencyType.choices ());
54+
dropdown = new Gtk.DropDown.from_strings (RecurrencyType.choices (1));
5555
dropdown.set_selected (RecurrencyType.EVERY_DAY); // Enums are fucking magic
5656

5757
// 60 minutes * 24 hrs = Maximum 1440 minutes. Next up may as well use days
@@ -83,6 +83,14 @@ public class Reminduck.Repeatbox : Gtk.Box {
8383

8484
on_selected_change ();
8585
dropdown.notify["selected"].connect (on_selected_change);
86+
interval_spin.notify["value"].connect (on_spin_changed);
87+
}
88+
89+
private void on_spin_changed () {
90+
debug ("Spin changed!");
91+
// print ("SPIN");
92+
// dropdown = new Gtk.DropDown.from_strings (
93+
// RecurrencyType.choices ((int)interval_spin.value));
8694
}
8795

8896
private void on_selected_change () {

0 commit comments

Comments
 (0)