Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Get System and the Scheduler's "when done" drop-down fit in the last languages (part of #192) (#254)

Ahmed Nefzaoui450867d62359
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 835b1f3f..be85661f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -549,6 +549,15 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Get System and the Scheduler's "when done" drop-down fit in every language**
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192), after #247): Options →
+ Proxy's title takes two lines where one leaves Get System too little room (Bulgarian,
+ Armenian, Tamil), and where it ran over the page's icon or past the window's left edge
+ (Greek, Finnish, Catalan, Estonian, Latvian, Lithuanian, Malayalam, Serbian, Afrikaans). In
+ Greek and Malayalam, the Scheduler's "Turn off computer when done" and its choices have
+ shorter machine translations, so the drop-down fits beside the caption; in Belarusian, Welsh,
+ French, Russian, Tamil and Ukrainian, the longer ones the translation review brought (such as
+ Russian's Hibernate) are back to their earlier, shorter wording. English is unchanged.
- **Galleries work with the gallery-dl a Linux distribution ships**
([#236](https://github.com/anefzaoui/misterdownloadmanager/issues/236)): with Ubuntu 24.04's
gallery-dl 1.26.9 chosen in Helpers, every gallery failed at once ("unrecognized arguments:
diff --git a/ROADMAP.md b/ROADMAP.md
index ed8aafe3..f9e977db 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,12 @@ Everything below ships together, in one release, as version 0.3.0.
### Done
+- ✅ Options → Proxy's Get System and the Scheduler's "when done" drop-down fit in the last
+ languages that still cut them (Bulgarian, Armenian, Macedonian, Tamil; Greek, Malayalam, and
+ six the translation review lengthened), and the Proxy
+ page's title no longer runs over its icon or past the window's edge in Greek, Finnish, Catalan
+ and a few more: a title too long for one line beside Get System takes two
+ ([#192](https://github.com/anefzaoui/misterdownloadmanager/issues/192))
- ✅ Linux: galleries work with the gallery-dl the distribution ships (Ubuntu 24.04's 1.26.9
failed at once): MDM passes only the options that release accepts, from 1.20 on, and an older
one gives way to MDM's own copy, saying why; the lab's test streams are real ones, which ffmpeg
diff --git a/crates/app/src/options.rs b/crates/app/src/options.rs
index e05e8d71..e1b158b1 100644
--- a/crates/app/src/options.rs
+++ b/crates/app/src/options.rs
@@ -1360,31 +1360,31 @@ impl OptionsDialog {
.image(true)
.paint_at(ui, r(o, 21.0, 50.0, 32.0, 32.0));
// Get System as wide as its label in this language (#192), its right end kept. A
- // translated title ends where the English one does, unless the button needs that room:
- // then the title moves left (no further than 8 px after the icon) and ends 8 px before it.
+ // translated title ends where the English one does, unless the button needs that room or
+ // it would start less than 8 px after the icon: then it ends 8 px before the button, in
+ // two lines where one doesn't fit there.
+ let font = winui::tahoma_bold();
let english_end =
- 112.0 + winui::text_width_font(&p, winui::tahoma_bold(), "Proxy / socks configuration");
- let title_w = page_title_width(&p, winui::tahoma_bold(), "Proxy / socks configuration");
+ 112.0 + winui::text_width_font(&p, font.clone(), "Proxy / socks configuration");
// The icon ends at 53; the button never moves right of its English place.
- let from = (53.0 + 8.0 + title_w + 8.0).min(307.0);
+ let (start, max_w) = (53.0 + 8.0, 160.0);
+ let get_whole = winui::button_fit_width(&p, "Get System", 93.0, max_w);
+ let room = (400.0 - get_whole).min(307.0) - 8.0 - start;
+ let (lines, title_w) =
+ page_title_lines(&p, font.clone(), "Proxy / socks configuration", room);
+ let from = (start + title_w + 8.0).min(307.0);
let (get_x, get_w) =
- winui::button_row(&p, &[("Get System", 307.0, 93.0)], 0.0, from, 160.0)[0];
- if get_x - 8.0 < english_end {
- page_title_ending(
- &p,
- winui::tahoma_bold(),
- o.x + get_x - 8.0,
- o.y + 69.0,
- "Proxy / socks configuration",
- );
- } else {
+ winui::button_row(&p, &[("Get System", 307.0, 93.0)], 0.0, from, max_w)[0];
+ if lines.len() == 1 && get_x - 8.0 >= english_end && english_end - title_w >= start {
page_title(
&p,
- winui::tahoma_bold(),
+ font,
o.x + 112.0,
o.y + 69.0,
"Proxy / socks configuration",
);
+ } else {
+ page_title_ending(&p, font, o.x + get_x - 8.0, o.y + 69.0, &lines);
}
let s = &mut self.s;
if winui::button_light(
@@ -4179,22 +4179,42 @@ fn page_title(p: &egui::Painter, font: egui::FontId, x: f32, baseline: f32, engl
winui::text_font(p, font, x, baseline, shown, LIGHT_TEXT());
}
-/// How wide [`page_title`] draws `english` translated.
-fn page_title_width(p: &egui::Painter, font: egui::FontId, english: &str) -> f32 {
- winui::text_width_font(p, font, crate::i18n::t(english))
+/// `english` translated, as [`page_title_ending`] draws it in `room` px: one line where it fits,
+/// else two ([`winui::fit_lines`]); and how wide it is drawn.
+fn page_title_lines(
+ p: &egui::Painter,
+ font: egui::FontId,
+ english: &str,
+ room: f32,
+) -> (Vec<String>, f32) {
+ let lines = winui::fit_lines(p, font.clone(), crate::i18n::t(english), room);
+ let w = lines
+ .iter()
+ .map(|l| winui::text_width_font(p, font.clone(), l))
+ .fold(0.0, f32::max);
+ (lines, w)
}
-/// [`page_title`] ending at English x `end` (a control after it needs the room up to there).
+/// A page title's `lines` ([`page_title_lines`]) ending at English x `end` (a control after it
+/// needs the room up to there): one line on `baseline`, two around it (beside the page's icon),
+/// each starting where the wider one does.
fn page_title_ending(
p: &egui::Painter,
font: egui::FontId,
end: f32,
baseline: f32,
- english: &str,
+ lines: &[String],
) {
- let shown = crate::i18n::t(english);
- let x = end - winui::text_width_font(p, font.clone(), shown);
- winui::text_font(p, font, x, baseline, shown, LIGHT_TEXT());
+ let w = lines
+ .iter()
+ .map(|l| winui::text_width_font(p, font.clone(), l))
+ .fold(0.0, f32::max);
+ // Bold Tahoma's rows are 15 px apart; two lines share the one line's middle.
+ let first = baseline - 7.5 * (lines.len() as f32 - 1.0);
+ for (i, line) in lines.iter().enumerate() {
+ let y = (first + 15.0 * i as f32).round();
+ winui::text_font(p, font.clone(), end - w, y, line, LIGHT_TEXT());
+ }
}
/// Group box (`#dcdcdc` frame) with its caption (translated here) at x + 9.
diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rs
index a09ad9c3..13c1aba1 100644
--- a/crates/app/src/winui.rs
+++ b/crates/app/src/winui.rs
@@ -2603,6 +2603,47 @@ pub fn checkbox_caption_end(p: &Painter, x: f32, caption: &str) -> f32 {
x + 16.0 + text_width(p, crate::i18n::t(caption))
}
+/// `s` in one line where it is no wider than `room` px in `font`, else in two, broken where the
+/// wider of the two is narrowest: at a space, after a slash or a hyphen, or between two
+/// characters of Chinese or Japanese (a title given a second line where a control beside it
+/// needs the room). Still one line where it has no such place.
+pub fn fit_lines(p: &Painter, font: FontId, s: &str, room: f32) -> Vec<String> {
+ let width = |t: &str| text_width_font(p, font.clone(), t);
+ if width(s) <= room {
+ return vec![s.to_owned()];
+ }
+ let g: Vec<(usize, &str)> = s.grapheme_indices(true).collect();
+ let mut best: Option<(f32, String, String)> = None;
+ for k in 1..g.len() {
+ let (at, here) = g[k];
+ let before = g[k - 1].1;
+ let first = |gr: &str| gr.chars().next().unwrap_or(' ');
+ let (a, b) = if before == " " {
+ (&s[..g[k - 1].0], &s[at..])
+ } else if here != " "
+ && (before == "/"
+ || before == "-"
+ || ((cjk(first(before)) || cjk(first(here))) && !here.chars().all(no_line_start)))
+ {
+ (&s[..at], &s[at..])
+ } else {
+ continue;
+ };
+ let (a, b) = (a.trim_end(), b.trim_start());
+ if a.is_empty() || b.is_empty() {
+ continue;
+ }
+ let w = width(a).max(width(b));
+ if best.as_ref().is_none_or(|(bw, ..)| w < *bw) {
+ best = Some((w, a.to_owned(), b.to_owned()));
+ }
+ }
+ match best {
+ Some((_, a, b)) => vec![a, b],
+ None => vec![s.to_owned()],
+ }
+}
+
/// How wide a [`combo_light`] must be for each of its translated `items` to show whole before
/// its chevron (the widest decides, so the box keeps its size as the choice changes): at least
/// `min` (its English width: English items fit it, so English never changes), at most `max`
@@ -5630,6 +5671,31 @@ mod tests {
});
}
+ #[test]
+ fn a_title_takes_a_second_line_only_where_one_is_too_long() {
+ with_painter(|p| {
+ let font = tahoma_bold();
+ let s = "Proxy socks configuration page";
+ let whole = text_width_font(p, font.clone(), s);
+ // Room for it: one line, as it is.
+ assert_eq!(fit_lines(p, font.clone(), s, whole), vec![s]);
+ // Short of room: two lines, broken where the wider is narrowest.
+ let two = fit_lines(p, font.clone(), s, whole - 1.0);
+ assert_eq!(two, vec!["Proxy socks", "configuration page"]);
+ // After a slash or a hyphen, the mark kept on the first line.
+ let two = fit_lines(p, font.clone(), "Proxyserver/SOCKS-konfiguration", 10.0);
+ assert_eq!(two.concat(), "Proxyserver/SOCKS-konfiguration");
+ assert!(two[0].ends_with('/') || two[0].ends_with('-'), "{two:?}");
+ // A word with no place to break stays whole.
+ assert_eq!(
+ fit_lines(p, font.clone(), "Konfiguration", 10.0),
+ vec!["Konfiguration"]
+ );
+ // Chinese breaks between its characters.
+ assert_eq!(fit_lines(p, font, "代理服务器配置", 10.0).len(), 2);
+ });
+ }
+
#[test]
fn a_drop_down_is_as_wide_as_its_widest_choice() {
with_painter(|p| {
diff --git a/i18n/be.tsv b/i18n/be.tsv
index 360b4437..81b52c91 100644
--- a/i18n/be.tsv
+++ b/i18n/be.tsv
@@ -1823,7 +1823,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: hibernate it)
#, machine
- Hibernate Перавесці ў рэжым гібернацыі
+ Hibernate Гібернацыя
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
#, machine
diff --git a/i18n/cy.tsv b/i18n/cy.tsv
index 9b82a69b..93d6eae8 100644
--- a/i18n/cy.tsv
+++ b/i18n/cy.tsv
@@ -4442,7 +4442,7 @@
Turn off computer Diffodd cyfrifiadur
#. checkbox in a download's progress window; checkbox in the Scheduler window
#, machine
- Turn off computer when done Diffodd y cyfrifiadur pan fydd y lawrlwythiad wedi'i gwblhau
+ Turn off computer when done Diffodd y cyfrifiadur pan fydd wedi gorffen
#. button in a dialog box
#, machine
Turn off now Diffodd nawr
diff --git a/i18n/el.tsv b/i18n/el.tsv
index c9759d4f..a25cdae6 100644
--- a/i18n/el.tsv
+++ b/i18n/el.tsv
@@ -4442,7 +4442,7 @@
Turn off computer Απενεργοποίηση υπολογιστή
#. checkbox in a download's progress window; checkbox in the Scheduler window
#, machine
- Turn off computer when done Απενεργοποίηση υπολογιστή μετά την ολοκλήρωση
+ Turn off computer when done Απενεργοποίηση υπολογιστή στο τέλος
#. button in a dialog box
#, machine
Turn off now Απενεργοποίηση τώρα
diff --git a/i18n/fr.tsv b/i18n/fr.tsv
index 45706fc6..28b8c5e8 100644
--- a/i18n/fr.tsv
+++ b/i18n/fr.tsv
@@ -4442,7 +4442,7 @@
Turn off computer Éteindre l’ordinateur
#. checkbox in a download's progress window; checkbox in the Scheduler window
#, machine
- Turn off computer when done Éteindre l’ordinateur une fois le téléchargement terminé
+ Turn off computer when done Éteindre l’ordinateur une fois terminé
#. button in a dialog box
#, machine
Turn off now Éteindre maintenant
diff --git a/i18n/ml.tsv b/i18n/ml.tsv
index 41b864e0..e0b4ff90 100644
--- a/i18n/ml.tsv
+++ b/i18n/ml.tsv
@@ -1823,7 +1823,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: hibernate it)
#, machine
- Hibernate ഹൈബർനേറ്റ് ചെയ്യുക
+ Hibernate ഹൈബർനേറ്റ്
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
#, machine
@@ -3549,7 +3549,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: shut down the computer)
#, machine
- Shut down ഷട്ട് ഡൗൺ ചെയ്യുക
+ Shut down ഷട്ട് ഡൗൺ
#. text in countries.rs
#. a country's name (where a download's server is)
#, machine
@@ -4442,7 +4442,7 @@
Turn off computer കമ്പ്യൂട്ടർ ഓഫ് ചെയ്യുക
#. checkbox in a download's progress window; checkbox in the Scheduler window
#, machine
- Turn off computer when done പൂർത്തിയാകുമ്പോൾ കമ്പ്യൂട്ടർ ഓഫ് ചെയ്യുക
+ Turn off computer when done പൂർത്തിയായാൽ കമ്പ്യൂട്ടർ ഓഫാക്കുക
#. button in a dialog box
#, machine
Turn off now ഇപ്പോൾ ഓഫ് ചെയ്യുക
diff --git a/i18n/ru.tsv b/i18n/ru.tsv
index a903f452..7f3ab089 100644
--- a/i18n/ru.tsv
+++ b/i18n/ru.tsv
@@ -1823,7 +1823,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: hibernate it)
#, machine
- Hibernate Перевести компьютер в спящий режим
+ Hibernate Гибернация
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
#, machine
diff --git a/i18n/ta.tsv b/i18n/ta.tsv
index 540bdae1..646904e1 100644
--- a/i18n/ta.tsv
+++ b/i18n/ta.tsv
@@ -1823,7 +1823,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: hibernate it)
#, machine
- Hibernate உறக்கநிலைக்கு மாற்று
+ Hibernate உறக்கநிலை
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
#, machine
diff --git a/i18n/uk.tsv b/i18n/uk.tsv
index d5d0cc77..7d20794f 100644
--- a/i18n/uk.tsv
+++ b/i18n/uk.tsv
@@ -1823,7 +1823,7 @@
#. text in the queues
#. what the computer does when the queue is done (verb: hibernate it)
#, machine
- Hibernate Перевести комп’ютер у режим гібернації
+ Hibernate Гібернація
#. message or event log entry in the main window
#. & marks the keyboard shortcut letter: keep one & before a letter of the translation
#, machine
diff --git a/tools/i18n/extract.py b/tools/i18n/extract.py
index c0862325..72396272 100644
--- a/tools/i18n/extract.py
+++ b/tools/i18n/extract.py
@@ -59,9 +59,9 @@ SINKS = {
"why_disabled": (2, ""),
# A button's width measured for its label (winui::button_fit_width): the label of a button.
"button_fit_width": (1, ""),
- # Where a checkbox's caption ends (winui::checkbox_caption_end); a page title's width and the
- # title ending before a control (options.rs).
- "checkbox_caption_end": (2, ""), "page_title_width": (2, ""), "page_title_ending": (4, ""),
+ # Where a checkbox's caption ends (winui::checkbox_caption_end); a page title's lines before a
+ # control (options.rs).
+ "checkbox_caption_end": (2, ""), "page_title_lines": (2, ""),
}
SINK_CALL = re.compile(
r"\b(?:winui::|MenuEntry::|crate::i18n::|i18n::)?(" + "|".join(SINKS) + r")\s*\(")
@@ -96,8 +96,7 @@ ROLES = {
"tn": "count", "link": "link (opens a web page)", "header": "page title",
"group": "group box title", "disabled_label": "label", "page_title": "page title",
"why_disabled": "tooltip (why a control is greyed)", "button_fit_width": "button",
- "checkbox_caption_end": "checkbox", "page_title_width": "page title",
- "page_title_ending": "page title",
+ "checkbox_caption_end": "checkbox", "page_title_lines": "page title",
}
CONTEXT_ROLES = {
"menu": "menu command", "toolbar": "toolbar button", "column": "column title",