From c1665fad9109b9163d64985242891eb343b0060c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Mart=C3=ADnez?= <171921708+rubenitx@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:52:46 +0100 Subject: [PATCH] fix(i18n): Fit quick windows, confirmations, the scroll bar and the backdrop panel in every language and format numbers in the interface language --- src/Capture/ScrollCapture.cs | 35 +- src/Design/Controls.cs | 5 +- src/Design/HighContrastPaint.cs | 2 +- src/Editor/BgPanel.cs | 5 +- src/Home/FocusClock.cs | 4 +- src/Home/HomeHistoryPage.cs | 4 +- src/Home/Recents.cs | 2 +- src/I18n.German.Capture.cs | 4 +- src/I18n.German.Editor.cs | 2 +- src/I18n.Korean.Capture.cs | 6 +- src/I18n.Korean.Core.cs | 2 +- src/I18n.Korean.Editor.cs | 2 +- src/Markdown/DocControls.cs | 21 +- src/Markdown/FindBar.cs | 2 +- src/Markdown/MarkdownWindow.Pdf.cs | 2 +- src/Markdown/MarkdownWindow.XmlCompare.cs | 10 +- src/Markdown/MarkdownWindow.cs | 8 +- src/QuickWindow.cs | 20 +- src/Xml/XmlDiffView.cs | 10 +- src/Xml/XmlTreeView.cs | 8 +- tests/app/AppTestsI18n.cs | 9 + tests/app/AppTestsI18nLayout.cs | 558 ++++++++++++++++++++++ 22 files changed, 663 insertions(+), 58 deletions(-) create mode 100644 tests/app/AppTestsI18nLayout.cs diff --git a/src/Capture/ScrollCapture.cs b/src/Capture/ScrollCapture.cs index 3d1e005..bb83ff5 100644 --- a/src/Capture/ScrollCapture.cs +++ b/src/Capture/ScrollCapture.cs @@ -871,7 +871,7 @@ public ScrollCaptureBar(ScrollSession session, Rectangle area) Screen scr = Screen.FromRectangle(area); s = ShotStack.ScaleFor(scr); Pad = P(22); - Size sz = new Size(P(480), P(48)); + Size sz = new Size(P(BarWidth), P(48)); Rectangle wa = scr.WorkingArea; int x = area.X + (area.Width - sz.Width) / 2; int y = area.Bottom + P(14); @@ -903,28 +903,37 @@ public void Poll() Redraw(); } - string State() + string State() { return StateText(saving, session.EscArmed, session.DoneArmed, session.Full, session.WentUp, session.Losing, hot, session.Auto, session.Stuck); } + + // The status line, in the order that decides which of them is shown. It has StatusRoom pixels (before scaling) in + // one line: a text any longer is cut with an ellipsis. + internal static string StateText(bool saving, bool escArmed, bool doneArmed, bool full, bool wentUp, bool losing, int hot, bool auto, bool stuck) { if (saving) return I18n.T("Componiendo\u2026", "Composing\u2026"); - if (session.EscArmed) return I18n.T("Esc otra vez para descartar", "Esc again to discard"); - if (session.DoneArmed) return I18n.T("No has bajado \u00B7 Listo otra vez la guarda", "You haven't scrolled \u00B7 Done again saves it"); - if (session.Full) return I18n.T("Altura m\u00E1xima", "Maximum height"); - if (session.WentUp) return I18n.T("Solo hacia abajo", "Downward only"); - if (session.Losing) return I18n.T("M\u00E1s despacio", "Slow down"); + if (escArmed) return I18n.T("Esc otra vez para descartar", "Esc again to discard"); + if (doneArmed) return I18n.T("No has bajado \u00B7 Listo otra vez la guarda", "You haven't scrolled \u00B7 Done again saves it"); + if (full) return I18n.T("Altura m\u00E1xima", "Maximum height"); + if (wentUp) return I18n.T("Solo hacia abajo", "Downward only"); + if (losing) return I18n.T("M\u00E1s despacio", "Slow down"); // What the button under the mouse does. - if (hot == 0) return session.Auto ? I18n.T("Pausa: paro y sigues t\u00FA con la rueda", "Pause: stop and continue scrolling with wheel") : I18n.T("Auto: bajo yo solo, poco a poco", "Auto: scroll automatically"); + if (hot == 0) return auto ? I18n.T("Pausa: paro y sigues t\u00FA con la rueda", "Pause: stop and scroll with the wheel") : I18n.T("Auto: bajo yo solo, poco a poco", "Auto: scroll automatically"); if (hot == 1) return I18n.T("Listo: guarda la captura (Enter)", "Done: save capture (Enter)"); if (hot == 2) return I18n.T("Cancela sin guardar (Esc)", "Cancel without saving (Esc)"); - if (session.Auto) return I18n.T("Bajando solo\u2026", "Scrolling down\u2026"); - if (session.Stuck) return I18n.T("\u00BFNo baja? Pulsa Auto", "Not scrolling? Click Auto"); + if (auto) return I18n.T("Bajando solo\u2026", "Scrolling down\u2026"); + if (stuck) return I18n.T("\u00BFNo baja? Pulsa Auto", "Not scrolling? Click Auto"); return I18n.T("Baja con la rueda \u00B7 Enter termina", "Scroll with wheel \u00B7 Enter to finish"); } + // The room of the text beside the badge and before the buttons, at 100 % (the bar is BarWidth wide). + internal const int BarWidth = 480, StatusRoom = BarWidth - 50 - 8 - 6 - 64 - 78 - 40; + // "2,5 pantallas · 2.140 px": how far it has gone, in screens of the area. - string HeightText(int h) + string HeightText(int h) { return HeightText(h, session.AreaHeight); } + + internal static string HeightText(int h, int areaHeight) { if (h <= 0) return I18n.T("Preparando\u2026", "Preparing\u2026"); - double screens = (double)h / Math.Max(1, session.AreaHeight); + double screens = (double)h / Math.Max(1, areaHeight); string sc = screens < 1.05 ? I18n.T("1 pantalla", "1 screen") : screens.ToString("0.#", I18n.Culture) + I18n.T(" pantallas", " screens"); return sc + " \u00B7 " + h.ToString("N0", I18n.Culture) + " px"; } @@ -966,7 +975,7 @@ protected override void PaintSurface(System.Windows.Media.DrawingContext dc, int double gs = P(16); Glyph.Draw(dc, "down", ic.X + (ic.Width - gs) / 2, cy - gs / 2 + P(1), gs, Palette.OnHudFill(white), Math.Max(1.6, 2 * s)); - int tx = P(50), tw = AutoRect().X - tx - P(8); + int tx = P(50), tw = AutoRect().X - tx - P(8); // StatusRoom at 100 % string hs = HeightText(shownHeight); System.Windows.Media.FormattedText ht = Line(hs, Ds.Semibold, P(14), white, tw); dc.DrawText(ht, new System.Windows.Point(tx, Math.Round(cy - ht.Height + P(2)))); diff --git a/src/Design/Controls.cs b/src/Design/Controls.cs index 0358a51..5b63e4e 100644 --- a/src/Design/Controls.cs +++ b/src/Design/Controls.cs @@ -514,6 +514,9 @@ public class MacSegmented : Drawn, IStrip int selected, hover = -1; public event Action Changed; + // Room left around a segment's text before it is cut with an ellipsis. + internal const double TextPad = 4; + public MacSegmented(string[] options, int selected) { this.options = options; @@ -613,7 +616,7 @@ protected override void Paint(DrawingContext dc) { bool on = i == selected; FormattedText t = Text(options[i], on ? Ds.Semibold : Ds.Regular, 12.5, on ? pal.Label : Mix(pal.Label2, pal.Label, i == hov ? 0.6 : 0)); - t.MaxTextWidth = Math.Max(1, seg - 8); + t.MaxTextWidth = Math.Max(1, seg - TextPad); t.MaxLineCount = 1; t.Trimming = TextTrimming.CharacterEllipsis; Ink.Center(dc, t, new Rect(2 + seg * i, 0, seg, h)); diff --git a/src/Design/HighContrastPaint.cs b/src/Design/HighContrastPaint.cs index 91202d4..d93fd46 100644 --- a/src/Design/HighContrastPaint.cs +++ b/src/Design/HighContrastPaint.cs @@ -73,7 +73,7 @@ public static void Segmented(DrawingContext dc, Size size, string[] options, dou bool on = i == selected; if (i == hover && !on && enabled) dc.DrawRoundedRectangle(null, Line(s.Highlight, px), new Rect(2 + seg * i + px / 2, 2 + px / 2, seg - px, h - 4 - px), 5.5, 5.5); FormattedText t = Ink.Text(options[i], on ? Ds.Semibold : Ds.Regular, 12.5, on ? (enabled ? s.HighlightText : s.Window) : ink); - t.MaxTextWidth = Math.Max(1, seg - 8); + t.MaxTextWidth = Math.Max(1, seg - MacSegmented.TextPad); t.MaxLineCount = 1; t.Trimming = TextTrimming.CharacterEllipsis; Ink.Center(dc, t, new Rect(2 + seg * i, 0, seg, h)); diff --git a/src/Editor/BgPanel.cs b/src/Editor/BgPanel.cs index c047f3d..cd93256 100644 --- a/src/Editor/BgPanel.cs +++ b/src/Editor/BgPanel.cs @@ -149,7 +149,10 @@ void Arrange(int width) // Gradients, five to a row. int gap = P(8), sw = (w - 4 * gap) / 5; Add(Kind.Header, 0, I18n.T("Degradados", "Gradients"), new Rectangle(m, y, w, P(16))); - Add(Kind.More, 0, allGradients ? I18n.T("Ver menos", "Show less") : I18n.T("Ver m\u00E1s", "Show more"), new Rectangle(m + w - P(84), y - P(3), P(84), P(22))); + // Wide enough for its own label (it is longer in some languages) so the whole word can be clicked. + string more = allGradients ? I18n.T("Ver menos", "Show less") : I18n.T("Ver m\u00E1s", "Show more"); + int moreW = Math.Max(P(84), TextKit.Measure(more, Small(), Size.Empty, TextFormatFlags.NoPadding).Width + P(18)); + Add(Kind.More, 0, more, new Rectangle(m + w - moreW, y - P(3), moreW, P(22))); y += P(26); int col = 0, shown = 0; for (int i = 0; i < Backdrop.Count; i++) diff --git a/src/Home/FocusClock.cs b/src/Home/FocusClock.cs index d9bfcb6..8efb673 100644 --- a/src/Home/FocusClock.cs +++ b/src/Home/FocusClock.cs @@ -119,9 +119,11 @@ public static string Clock(TimeSpan t) return s >= 3600 ? (s / 3600) + ":" + (s / 60 % 60).ToString("00") + ":" + (s % 60).ToString("00") : (s / 60) + ":" + (s % 60).ToString("00"); } - // "25 min", "1 h 15 min". + // "25 min", "1 h 15 min" ("25분", "1시간 15분" in Korean, which has its own units). public static string Minutes(int m) { + if (I18n.IsKorean) + return m < 60 ? I18n.Fmt("", "{0} min", m) : I18n.Fmt("", "{0} h", m / 60) + (m % 60 > 0 ? " " + I18n.Fmt("", "{0} min", m % 60) : ""); return m < 60 ? m + " min" : (m / 60) + " h" + (m % 60 > 0 ? " " + (m % 60) + " min" : ""); } } diff --git a/src/Home/HomeHistoryPage.cs b/src/Home/HomeHistoryPage.cs index 5e6a564..7d8e7c2 100644 --- a/src/Home/HomeHistoryPage.cs +++ b/src/Home/HomeHistoryPage.cs @@ -561,12 +561,12 @@ void HistoryShow(List shown, string[] words, bool fromTop) if (historyAll == null || historyAll.Count == 0 || n == 0) historyCount.Text = ""; else if (words.Length > 0) { - historyCount.Text = I18n.IsKorean ? string.Format(I18n.Localize("{0:N0} results"), n) + historyCount.Text = I18n.IsKorean ? string.Format(HistoryEs, I18n.Localize("{0:N0} results"), n) : n == 1 ? I18n.T("1 resultado", "1 result") : I18n.Fmt("{0} resultados", "{0} results", n.ToString("N0", HistoryEs)); } else { - historyCount.Text = I18n.IsKorean ? string.Format(I18n.Localize("{0:N0} items"), n) + historyCount.Text = I18n.IsKorean ? string.Format(HistoryEs, I18n.Localize("{0:N0} items"), n) : n == 1 ? I18n.T("1 elemento", "1 item") : I18n.Fmt("{0} elementos", "{0} items", n.ToString("N0", HistoryEs)); } } diff --git a/src/Home/Recents.cs b/src/Home/Recents.cs index 50c6088..8d39e93 100644 --- a/src/Home/Recents.cs +++ b/src/Home/Recents.cs @@ -197,7 +197,7 @@ public static string Size(long bytes) if (kb < 1024) return kb + " KB"; double mb = Math.Max(1, bytes / 1048576.0); if (mb < 1024 && Math.Round(mb) >= 1024) mb = 1024; - return mb >= 1024 ? (mb / 1024).ToString("0.0") + " GB" : mb.ToString(mb < 10 ? "0.0" : "0") + " MB"; + return mb >= 1024 ? (mb / 1024).ToString("0.0", I18n.Culture) + " GB" : mb.ToString(mb < 10 ? "0.0" : "0", I18n.Culture) + " MB"; } // Thumbnail of a capture at px (device pixels) on its long side; ready is called on the UI thread. diff --git a/src/I18n.German.Capture.cs b/src/I18n.German.Capture.cs index c033eb8..32415a9 100644 --- a/src/I18n.German.Capture.cs +++ b/src/I18n.German.Capture.cs @@ -84,11 +84,11 @@ static void RegisterGermanCapture(Action reg) reg("The area did not scroll, so it was saved as a normal capture. Choose only the part that scrolls (the list or text), without the fixed header.", null, "Der Bereich wurde als normale Aufnahme gespeichert, weil er sich nicht bewegt hat. Wähle nur die scrollbare Liste oder den Textbereich ohne festen Kopfbereich."); reg("Composing…", null, "Bild wird zusammengesetzt…"); reg("Esc again to discard", null, "Zum Verwerfen erneut Esc drücken"); - reg("You haven't scrolled · Done again saves it", null, "Es wurde noch nicht gescrollt · Erneut „Fertig“ wählen, um zu speichern"); + reg("You haven't scrolled · Done again saves it", null, "Nichts gescrollt · Erneut „Fertig“ speichert"); reg("Maximum height", null, "Maximale Höhe"); reg("Downward only", null, "Nur nach unten"); reg("Slow down", null, "Langsamer scrollen"); - reg("Pause: stop and continue scrolling with wheel", null, "Pausieren und mit dem Mausrad weiterscrollen"); + reg("Pause: stop and scroll with the wheel", null, "Pausieren, per Mausrad weiterscrollen"); reg("Auto: scroll automatically", null, "Auto: automatisch scrollen"); reg("Done: save capture (Enter)", null, "Fertig: Aufnahme speichern (Eingabe)"); reg("Cancel without saving (Esc)", null, "Ohne Speichern abbrechen (Esc)"); diff --git a/src/I18n.German.Editor.cs b/src/I18n.German.Editor.cs index 1635b6c..fe2f9fb 100644 --- a/src/I18n.German.Editor.cs +++ b/src/I18n.German.Editor.cs @@ -327,7 +327,7 @@ static void RegisterGermanEditor(Action reg) reg("Blur", null, "Unschärfe"); reg("Solid color", null, "Volltonfarbe"); reg("Other color\u2026", null, "Andere Farbe\u2026"); - reg("Auto-balance", null, "Automatisch ausbalancieren"); + reg("Auto-balance", null, "Auto-Ausgleich"); reg("Alignment", null, "Ausrichtung"); reg("Aspect ratio", "Proporción", "Seitenverhältnis"); reg("Saved styles\u2026", null, "Gespeicherte Stile\u2026"); diff --git a/src/I18n.Korean.Capture.cs b/src/I18n.Korean.Capture.cs index f520db8..ffb7c48 100644 --- a/src/I18n.Korean.Capture.cs +++ b/src/I18n.Korean.Capture.cs @@ -309,11 +309,11 @@ static void RegisterKoreanCapture(Dictionary map) map["The area did not scroll, so it was saved as a normal capture. Choose only the part that scrolls (the list or text), without the fixed header."] = "\uC601\uC5ED\uC774 \uC6C0\uC9C1\uC774\uC9C0 \uC54A\uC544 \uC77C\uBC18 \uCEA1\uCC98\uB85C \uC800\uC7A5\uD588\uC2B5\uB2C8\uB2E4. \uACE0\uC815\uB41C \uBA38\uB9AC\uAE00\uC744 \uBE7C\uACE0 \uC2A4\uD06C\uB864\uB418\uB294 \uBAA9\uB85D\uC774\uB098 \uBCF8\uBB38\uB9CC \uC120\uD0DD\uD558\uC138\uC694."; map["Composing\u2026"] = "\uC774\uBBF8\uC9C0 \uD569\uCE58\uB294 \uC911\u2026"; map["Esc again to discard"] = "Esc\uB97C \uB2E4\uC2DC \uB20C\uB7EC \uBC84\uB9AC\uAE30"; - map["You haven't scrolled \u00B7 Done again saves it"] = "\uC2A4\uD06C\uB864\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 \u00B7 \uC644\uB8CC\uB97C \uB2E4\uC2DC \uB20C\uB7EC \uC800\uC7A5"; + map["You haven't scrolled \u00B7 Done again saves it"] = "\uC2A4\uD06C\uB864 \uC548 \uD568 \u00B7 \uC644\uB8CC\uB97C \uB2E4\uC2DC \uB20C\uB7EC \uC800\uC7A5"; map["Maximum height"] = "\uCD5C\uB300 \uB192\uC774 \uB3C4\uB2EC"; map["Downward only"] = "\uC544\uB798\uB85C\uB9CC \uC2A4\uD06C\uB864"; map["Slow down"] = "\uB354 \uCC9C\uCC9C\uD788 \uC2A4\uD06C\uB864\uD558\uC138\uC694"; - map["Pause: stop and continue scrolling with wheel"] = "\uC77C\uC2DC \uC815\uC9C0: \uC790\uB3D9 \uC2A4\uD06C\uB864\uC744 \uBA48\uCD94\uACE0 \uD720\uB85C \uACC4\uC18D"; + map["Pause: stop and scroll with the wheel"] = "\uC77C\uC2DC \uC815\uC9C0: \uC790\uB3D9 \uC2A4\uD06C\uB864\uC744 \uBA48\uCD94\uACE0 \uD720\uB85C \uACC4\uC18D"; map["Auto: scroll automatically"] = "\uC790\uB3D9: \uC790\uB3D9\uC73C\uB85C \uC2A4\uD06C\uB864"; map["Done: save capture (Enter)"] = "\uC644\uB8CC: \uCEA1\uCC98 \uC800\uC7A5(Enter)"; map["Cancel without saving (Esc)"] = "\uC800\uC7A5\uD558\uC9C0 \uC54A\uACE0 \uCDE8\uC18C(Esc)"; @@ -406,7 +406,7 @@ static void RegisterKoreanCapture(Dictionary map) map["No sensitive data found."] = "\uBBFC\uAC10 \uC815\uBCF4\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4."; map["Sensitive data is already redacted."] = "\uBBFC\uAC10 \uC815\uBCF4\uAC00 \uC774\uBBF8 \uAC00\uB824\uC838 \uC788\uC2B5\uB2C8\uB2E4."; map["Redacted {0} more items; {1} were already covered."] = "{0}\uAC1C\uB97C \uCD94\uAC00\uB85C \uAC00\uB838\uC2B5\uB2C8\uB2E4. \uB098\uBA38\uC9C0 {1}\uAC1C\uB294 \uC774\uBBF8 \uAC00\uB824\uC838 \uC788\uC5C8\uC2B5\uB2C8\uB2E4."; - map["{0} items redacted: {1}. You can remove the marks."] = "\uBBFC\uAC10 \uC815\uBCF4 {0}\uAC1C\uB97C \uAC00\uB838\uC2B5\uB2C8\uB2E4({1}). \uAC00\uB9AC\uAE30 \uD45C\uC2DC\uB294 \uC81C\uAC70\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4."; + map["{0} items redacted: {1}. You can remove the marks."] = "\uBBFC\uAC10 \uC815\uBCF4 {0}\uAC1C \uAC00\uB9BC({1}). \uD45C\uC2DC\uB294 \uC81C\uAC70 \uAC00\uB2A5\uD569\uB2C8\uB2E4."; map["Original"] = "\uC6D0\uBCF8"; map["Sunset"] = "\uB178\uC744"; map["Mint"] = "\uBBFC\uD2B8"; diff --git a/src/I18n.Korean.Core.cs b/src/I18n.Korean.Core.cs index b0d5929..c7f0f85 100644 --- a/src/I18n.Korean.Core.cs +++ b/src/I18n.Korean.Core.cs @@ -74,7 +74,7 @@ static void RegisterKoreanCore(Dictionary map) map["Start a line with \u201C- [ ] \u201D for a task list."] = "\uD560 \uC77C \uBAA9\uB85D\uC740 \uAC01 \uC904\uC744 \u2018- [ ] \u2019\uB85C \uC2DC\uC791\uD558\uC138\uC694."; map["When?"] = "\uC5B8\uC81C \uC54C\uB824\uB4DC\uB9B4\uAE4C\uC694?"; map["Tomorrow"] = "\uB0B4\uC77C"; - map["At\u2026"] = "\uC2DC\uAC04 \uC9C0\uC815\u2026"; + map["At\u2026"] = "\uC2DC\uAC01\u2026"; map["I'll remind you {0}."] = "{0}\uC5D0 \uC54C\uB824\uB4DC\uB9B4\uAC8C\uC694."; map["Time"] = "\uC2DC\uAC04"; map["(for example 16:30)"] = "(\uC608: 16:30)"; diff --git a/src/I18n.Korean.Editor.cs b/src/I18n.Korean.Editor.cs index 318d4dc..0c5aaa9 100644 --- a/src/I18n.Korean.Editor.cs +++ b/src/I18n.Korean.Editor.cs @@ -64,7 +64,7 @@ static void RegisterKoreanEditor(Dictionary map) map["Padding"] = "\uC5EC\uBC31"; map["Corners"] = "\uBAA8\uC11C\uB9AC"; map["Shadow"] = "\uADF8\uB9BC\uC790"; - map["Border inset"] = "\uD14C\uB450\uB9AC \uC548\uCABD \uC5EC\uBC31"; + map["Border inset"] = "\uC548\uCABD \uC5EC\uBC31"; // BgPanel.Styles map[" \u00B7 padding "] = " \u00B7 \uC5EC\uBC31 "; diff --git a/src/Markdown/DocControls.cs b/src/Markdown/DocControls.cs index 8b5a721..67a019d 100644 --- a/src/Markdown/DocControls.cs +++ b/src/Markdown/DocControls.cs @@ -322,7 +322,6 @@ void UseIcon(string icon, Color c1, Color c2) Grid row = new Grid { Margin = new Thickness(0, 20, 0, 0) }; Grid.SetRow(row, 2); Grid.SetColumnSpan(row, 2); - StackPanel right = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right }; MacButton main = null; MacButton[] all = new MacButton[buttons.Length]; for (int i = 0; i < buttons.Length; i++) @@ -338,12 +337,26 @@ void UseIcon(string icon, Color c1, Color c2) if (primary >= 0 && primary < all.Length) order.Add(primary); for (int i = 0; i < all.Length; i++) if (i != primary && i != cancel) order.Add(i); if (cancel >= 0 && cancel < all.Length && cancel != primary) order.Add(cancel); + // One row; when a language makes the buttons longer than the room they have, the rest go on a second row + // (still on the right, in the same order) instead of running off the edge. + double room = Width - g.Margin.Left - g.Margin.Right, used = 0; + StackPanel rows = new StackPanel(); + StackPanel right = null; for (int n = 0; n < order.Count; n++) { - all[order[n]].Margin = new Thickness(n == 0 ? 0 : 8, 0, 0, 0); - right.Children.Add(all[order[n]]); + MacButton b = all[order[n]]; + double w = Math.Max(b.Width, b.MinWidth); + if (right == null || used + 8 + w > room) + { + right = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, right == null ? 0 : 8, 0, 0) }; + rows.Children.Add(right); + used = 0; + } + b.Margin = new Thickness(used == 0 ? 0 : 8, 0, 0, 0); + used += (used == 0 ? 0 : 8) + w; + right.Children.Add(b); } - row.Children.Add(right); + row.Children.Add(rows); g.Children.Add(row); Root.Children.Add(g); KeepCaptionsOnTop(); diff --git a/src/Markdown/FindBar.cs b/src/Markdown/FindBar.cs index a9479ea..f06f696 100644 --- a/src/Markdown/FindBar.cs +++ b/src/Markdown/FindBar.cs @@ -290,7 +290,7 @@ public void Show(int index, int total, string error, bool partial) if (error != null) count.Text = error; else if (Query.Text.Length == 0) count.Text = ""; else if (total == 0) count.Text = partial ? I18n.T("Sin resultados (b\u00FAsqueda cortada)", "No results (search cut short)") : I18n.T("Sin resultados", "No results"); - else count.Text = (index >= 0 ? (index + 1).ToString("N0") + I18n.T(" de ", " of ") : "") + total.ToString("N0") + (total >= TextSearch.MaxHits || partial ? "+" : "") + (index >= 0 ? "" : total == 1 ? I18n.T(" resultado", " result") : I18n.T(" resultados", " results")); + else count.Text = (index >= 0 ? (index + 1).ToString("N0", I18n.Culture) + I18n.T(" de ", " of ") : "") + total.ToString("N0", I18n.Culture) + (total >= TextSearch.MaxHits || partial ? "+" : "") + (index >= 0 ? "" : total == 1 ? I18n.T(" resultado", " result") : I18n.T(" resultados", " results")); } public void FocusQuery() diff --git a/src/Markdown/MarkdownWindow.Pdf.cs b/src/Markdown/MarkdownWindow.Pdf.cs index 27fb48d..82b75a4 100644 --- a/src/Markdown/MarkdownWindow.Pdf.cs +++ b/src/Markdown/MarkdownWindow.Pdf.cs @@ -116,7 +116,7 @@ void PdfExported(int my, string path, int pages, string err) return; } pdfPages = pages; - Say(I18n.Fmt(pages == 1 ? "PDF exportado: {0} ({1} p\u00E1gina)." : "PDF exportado: {0} ({1} p\u00E1ginas).", pages == 1 ? "PDF exported: {0} ({1} page)." : "PDF exported: {0} ({1} pages).", System.IO.Path.GetFileName(path), pages.ToString("N0")), false); + Say(I18n.Fmt(pages == 1 ? "PDF exportado: {0} ({1} p\u00E1gina)." : "PDF exportado: {0} ({1} p\u00E1ginas).", pages == 1 ? "PDF exported: {0} ({1} page)." : "PDF exported: {0} ({1} pages).", System.IO.Path.GetFileName(path), pages.ToString("N0", I18n.Culture)), false); } } } diff --git a/src/Markdown/MarkdownWindow.XmlCompare.cs b/src/Markdown/MarkdownWindow.XmlCompare.cs index 6dbd927..4d4142b 100644 --- a/src/Markdown/MarkdownWindow.XmlCompare.cs +++ b/src/Markdown/MarkdownWindow.XmlCompare.cs @@ -83,9 +83,9 @@ internal string CompareStatus() DiffResult r = compare.Result; if (r.Total == 0) return I18n.T("Sin diferencias", "No differences"); List parts = new List(); - if (r.Changed > 0) parts.Add(I18n.Fmt(r.Changed == 1 ? "{0} cambio" : "{0} cambios", r.Changed == 1 ? "{0} change" : "{0} changes", r.Changed.ToString("N0"))); - if (r.Added > 0) parts.Add(I18n.Fmt(r.Added == 1 ? "{0} a\u00F1adido" : "{0} a\u00F1adidos", r.Added == 1 ? "{0} added" : "{0} added", r.Added.ToString("N0"))); - if (r.Removed > 0) parts.Add(I18n.Fmt(r.Removed == 1 ? "{0} quitado" : "{0} quitados", r.Removed == 1 ? "{0} removed" : "{0} removed", r.Removed.ToString("N0"))); + if (r.Changed > 0) parts.Add(I18n.Fmt(r.Changed == 1 ? "{0} cambio" : "{0} cambios", r.Changed == 1 ? "{0} change" : "{0} changes", r.Changed.ToString("N0", I18n.Culture))); + if (r.Added > 0) parts.Add(I18n.Fmt(r.Added == 1 ? "{0} a\u00F1adido" : "{0} a\u00F1adidos", r.Added == 1 ? "{0} added" : "{0} added", r.Added.ToString("N0", I18n.Culture))); + if (r.Removed > 0) parts.Add(I18n.Fmt(r.Removed == 1 ? "{0} quitado" : "{0} quitados", r.Removed == 1 ? "{0} removed" : "{0} removed", r.Removed.ToString("N0", I18n.Culture))); return string.Join(" \u00B7 ", parts.ToArray()); } @@ -145,7 +145,7 @@ void UpdateComparePos() { if (compare == null || comparePos == null) return; int total = compare.Result.Stops.Count, cur = compare.View != null ? compare.View.Current : -1; - comparePos.Text = cur >= 0 ? I18n.Fmt("{0} de {1}", "{0} of {1}", (cur + 1).ToString("N0"), total.ToString("N0")) : total == 0 ? I18n.T("Sin diferencias", "No differences") : I18n.Fmt(total == 1 ? "{0} diferencia" : "{0} diferencias", total == 1 ? "{0} difference" : "{0} differences", total.ToString("N0")); + comparePos.Text = cur >= 0 ? I18n.Fmt("{0} de {1}", "{0} of {1}", (cur + 1).ToString("N0", I18n.Culture), total.ToString("N0", I18n.Culture)) : total == 0 ? I18n.T("Sin diferencias", "No differences") : I18n.Fmt(total == 1 ? "{0} diferencia" : "{0} diferencias", total == 1 ? "{0} difference" : "{0} differences", total.ToString("N0", I18n.Culture)); if (compareUp != null) compareUp.IsEnabled = total > 0; if (compareDown != null) compareDown.IsEnabled = total > 0; } @@ -290,7 +290,7 @@ void StartCompare(DiffResult r, string oldPath, bool cut) if (r.Stops.Count > 0) compare.View.Step(1); else compare.View.List.Focus(); UpdateComparePos(); - if (cut) Say(I18n.Fmt("El XML es muy grande: solo se comparan sus primeros {0} nodos.", "The XML is very large: only its first {0} nodes are compared.", XmlDoc.MaxNodes.ToString("N0")), false); + if (cut) Say(I18n.Fmt("El XML es muy grande: solo se comparan sus primeros {0} nodos.", "The XML is very large: only its first {0} nodes are compared.", XmlDoc.MaxNodes.ToString("N0", I18n.Culture)), false); } internal void ExitCompare() diff --git a/src/Markdown/MarkdownWindow.cs b/src/Markdown/MarkdownWindow.cs index effdf19..ef19c6a 100644 --- a/src/Markdown/MarkdownWindow.cs +++ b/src/Markdown/MarkdownWindow.cs @@ -1034,14 +1034,14 @@ void Stats() } if (CompareShown()) { statusLabel.Text = CompareStatus(); return; } if (selPath != null && !editing) { statusLabel.Text = selPath; return; } - string extra = tree != null && tree.Filtering ? " \u00B7 " + tree.Matches.ToString("N0") + (tree.Matches == 1 ? I18n.T(" coincidencia", " match") : I18n.T(" coincidencias", " matches")) : ""; + string extra = tree != null && tree.Filtering ? " \u00B7 " + tree.Matches.ToString("N0", I18n.Culture) + (tree.Matches == 1 ? I18n.T(" coincidencia", " match") : I18n.T(" coincidencias", " matches")) : ""; int n = model != null ? model.Count : 0; string ok = editing && model != null ? I18n.T(" \u00B7 bien formado", " \u00B7 well-formed") : ""; - statusLabel.Text = head + " \u00B7 " + n.ToString("N0") + (n == 1 ? I18n.T(" nodo", " node") : I18n.T(" nodos", " nodes")) + (model != null && model.Truncated ? I18n.T(" (los primeros)", " (the first ones)") : "") + extra + ok + tail; + statusLabel.Text = head + " \u00B7 " + n.ToString("N0", I18n.Culture) + (n == 1 ? I18n.T(" nodo", " node") : I18n.T(" nodos", " nodes")) + (model != null && model.Truncated ? I18n.T(" (los primeros)", " (the first ones)") : "") + extra + ok + tail; return; } int w = MarkdownTools.Words(text); - statusLabel.Text = head + " \u00B7 " + w.ToString("N0") + (w == 1 ? I18n.T(" palabra", " word") : I18n.T(" palabras", " words")) + tail; + statusLabel.Text = head + " \u00B7 " + w.ToString("N0", I18n.Culture) + (w == 1 ? I18n.T(" palabra", " word") : I18n.T(" palabras", " words")) + tail; } void Say(string msg, bool bad) @@ -1642,7 +1642,7 @@ void ReplaceAll() editor.SetText(t); text = editor.Text; RefreshHits(false); - Say(n == 1 ? I18n.T("1 reemplazo.", "1 replacement.") : I18n.Fmt("{0} reemplazos.", "{0} replacements.", n.ToString("N0")), false); + Say(n == 1 ? I18n.T("1 reemplazo.", "1 replacement.") : I18n.Fmt("{0} reemplazos.", "{0} replacements.", n.ToString("N0", I18n.Culture)), false); } // ---- Input diff --git a/src/QuickWindow.cs b/src/QuickWindow.cs index f2912f7..41cf1f7 100644 --- a/src/QuickWindow.cs +++ b/src/QuickWindow.cs @@ -111,7 +111,7 @@ void Build() { page.Children.Add(Text(I18n.T("\u00BFCu\u00E1ndo?", "When?"), Ds.Semibold, 12.5, pal.Label, new Thickness(0, 16, 0, 6))); // Short labels across the whole width; the line below says exactly when. - MacSegmented seg = new MacSegmented(new string[] { "10 min", "30 min", "1 h", "2 h", I18n.T("Ma\u00F1ana", "Tomorrow"), I18n.T("A las\u2026", "At\u2026") }, when); + MacSegmented seg = new MacSegmented(new string[] { FocusClock.Minutes(Minutes[0]), FocusClock.Minutes(Minutes[1]), FocusClock.Minutes(Minutes[2]), FocusClock.Minutes(Minutes[3]), I18n.T("Ma\u00F1ana", "Tomorrow"), I18n.T("A las\u2026", "At\u2026") }, when); seg.ClearValue(WidthProperty); seg.HorizontalAlignment = HorizontalAlignment.Stretch; seg.Changed += delegate(int i) { Keep(); when = i; Build(); if (i == 5 && time != null) { time.Focus(); time.SelectAll(); } }; @@ -225,15 +225,23 @@ void Build() StackPanel buttons = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 18, 0, 0) }; MacButton cancel = new MacButton(I18n.Cancel, ButtonKind.Secondary, null, null, 32) { Margin = new Thickness(8, 0, 0, 0) }; cancel.Click += delegate { Close(); }; - MacButton save = new MacButton(note ? I18n.T("Apuntar", "Take note") : I18n.T("Recu\u00E9rdamelo", "Remind me"), ButtonKind.Primary, note ? "check" : "clock", note ? I18n.T("Ctrl+Intro", "Ctrl+Enter") : null, 32); - save.Click += Save; - buttons.Children.Add(save); + MacButton savePin = null; if (note) { - MacButton savePin = new MacButton(I18n.T("Guardar y fijar", "Save and pin"), ButtonKind.Secondary, "pin", null, 32) { Margin = new Thickness(8, 0, 0, 0) }; + savePin = new MacButton(I18n.T("Guardar y fijar", "Save and pin"), ButtonKind.Secondary, "pin", null, 32) { Margin = new Thickness(8, 0, 0, 0) }; savePin.Click += SavePin; - buttons.Children.Add(savePin); } + string saveLabel = note ? I18n.T("Apuntar", "Take note") : I18n.T("Recu\u00E9rdamelo", "Remind me"); + string shortcut = note ? I18n.T("Ctrl+Intro", "Ctrl+Enter") : null; + MacButton save = new MacButton(saveLabel, ButtonKind.Primary, note ? "check" : "clock", shortcut, 32); + // The shortcut written inside the main button is the first thing to go when a language makes the row too long + // for the window; it stays in the tooltip. + double room = Width - page.Margin.Left - page.Margin.Right; + if (shortcut != null && save.Width + cancel.Width + cancel.Margin.Left + (savePin != null ? savePin.Width + savePin.Margin.Left : 0) > room) + save = new MacButton(saveLabel, ButtonKind.Primary, note ? "check" : "clock", null, 32) { ToolTip = shortcut }; + save.Click += Save; + buttons.Children.Add(save); + if (savePin != null) buttons.Children.Add(savePin); buttons.Children.Add(cancel); page.Children.Add(buttons); } diff --git a/src/Xml/XmlDiffView.cs b/src/Xml/XmlDiffView.cs index 598dd4b..ef9d517 100644 --- a/src/Xml/XmlDiffView.cs +++ b/src/Xml/XmlDiffView.cs @@ -92,7 +92,7 @@ static void Value(List o, string v, Seg kind, int mark, bool full, bo if (cut && v.Length <= Shown) { o.Add(new DiffPiece(raw ? v : XmlDoc.Esc(v, attr), kind, mark)); o.Add(new DiffPiece("\u2026", Seg.Hint, 0)); return; } if (v.Length > Shown) { - string rest = (cut ? total - Shown : v.Length - Shown).ToString("N0"); + string rest = (cut ? total - Shown : v.Length - Shown).ToString("N0", I18n.Culture); o.Add(new DiffPiece(raw ? v.Substring(0, Shown) : XmlDoc.Esc(v.Substring(0, Shown), attr), kind, mark)); o.Add(new DiffPiece("\u2026 (+" + rest + ")", Seg.Hint, 0)); return; @@ -150,7 +150,7 @@ static void Attrs(List o, DiffNode d, bool full) } } - static string Hidden(int n) { return "\u22EF " + n.ToString("N0") + (n == 1 ? I18n.T(" nodo sin cambios", " unchanged node") : I18n.T(" nodos sin cambios", " unchanged nodes")); } + static string Hidden(int n) { return "\u22EF " + n.ToString("N0", I18n.Culture) + (n == 1 ? I18n.T(" nodo sin cambios", " unchanged node") : I18n.T(" nodos sin cambios", " unchanged nodes")); } public static List Pieces(DiffRow r, bool full) { @@ -213,7 +213,7 @@ public static List Pieces(DiffRow r, bool full) o.Add(new DiffPiece(">", Seg.Punct, 0)); o.Add(new DiffPiece(" \u2026 ", Seg.Hint, 0)); o.Add(new DiffPiece("", Seg.Punct, 0)); - o.Add(new DiffPiece(" " + d.Kids.Count.ToString("N0") + (d.Kids.Count == 1 ? I18n.T(" nodo", " node") : I18n.T(" nodos", " nodes")) + (n.Inner ? I18n.T(" \u00B7 XML interno", " \u00B7 inner XML") : ""), Seg.Hint, 0)); + o.Add(new DiffPiece(" " + d.Kids.Count.ToString("N0", I18n.Culture) + (d.Kids.Count == 1 ? I18n.T(" nodo", " node") : I18n.T(" nodos", " nodes")) + (n.Inner ? I18n.T(" \u00B7 XML interno", " \u00B7 inner XML") : ""), Seg.Hint, 0)); } else { @@ -677,7 +677,7 @@ public void CopySelection() { string t = SelectionText(); int n = list.SelectedItems.Count; - if (t.Length > 0 && CopyRequest != null) CopyRequest(t, n == 1 ? I18n.T("Copiado.", "Copied.") : I18n.Fmt("Copiadas {0} l\u00EDneas.", "{0} lines copied.", n.ToString("N0"))); + if (t.Length > 0 && CopyRequest != null) CopyRequest(t, n == 1 ? I18n.T("Copiado.", "Copied.") : I18n.Fmt("Copiadas {0} l\u00EDneas.", "{0} lines copied.", n.ToString("N0", I18n.Culture))); } // ---- Picture @@ -700,7 +700,7 @@ public static BitmapSource Render(List rows, XmlDiffLook look, out stri sp.Children.Add(new DiffRowView(new DiffRow { Node = r.Node, Depth = r.Depth, Gap = r.Gap, Close = r.Close, Collapsed = r.Collapsed, Look = look })); } if (n < rows.Count) - sp.Children.Add(new TextBlock { Text = I18n.Fmt("\u2026 y {0} l\u00EDneas m\u00E1s", "\u2026 and {0} more lines", (rows.Count - n).ToString("N0")), Foreground = look.Syntax.Hint, FontSize = 12.5, Margin = new Thickness(XmlRowView.Gutter, 8, 0, 0) }); + sp.Children.Add(new TextBlock { Text = I18n.Fmt("\u2026 y {0} l\u00EDneas m\u00E1s", "\u2026 and {0} more lines", (rows.Count - n).ToString("N0", I18n.Culture)), Foreground = look.Syntax.Hint, FontSize = 12.5, Margin = new Thickness(XmlRowView.Gutter, 8, 0, 0) }); page = new Border { Background = Ds.Brush(look.Dark ? Ds.Rgb(30, 30, 32) : Colors.White), Padding = new Thickness(28, 26, 28, 28), Width = W + 56, UseLayoutRounding = true, Child = sp }; TextOptions.SetTextFormattingMode(page, TextFormattingMode.Ideal); TextOptions.SetTextRenderingMode(page, TextRenderingMode.Grayscale); diff --git a/src/Xml/XmlTreeView.cs b/src/Xml/XmlTreeView.cs index 750a771..ec89b28 100644 --- a/src/Xml/XmlTreeView.cs +++ b/src/Xml/XmlTreeView.cs @@ -180,7 +180,7 @@ static void Value(List o, string v, Seg kind, bool full, bool attr, bool if (cut) v = v.Substring(0, Shown * 4); v = WsRx.Replace(v, " ").Trim(); if (cut && v.Length <= Shown) { o.Add(new Piece(raw ? v : XmlDoc.Esc(v, attr), kind)); o.Add(new Piece("\u2026", Seg.Hint)); return; } - if (v.Length > Shown) { string rest = (cut ? total - Shown : v.Length - Shown).ToString("N0"); o.Add(new Piece(raw ? v.Substring(0, Shown) : XmlDoc.Esc(v.Substring(0, Shown), attr), kind)); o.Add(new Piece("\u2026 (+" + rest + ")", Seg.Hint)); return; } + if (v.Length > Shown) { string rest = (cut ? total - Shown : v.Length - Shown).ToString("N0", I18n.Culture); o.Add(new Piece(raw ? v.Substring(0, Shown) : XmlDoc.Esc(v.Substring(0, Shown), attr), kind)); o.Add(new Piece("\u2026 (+" + rest + ")", Seg.Hint)); return; } } else v = v.Trim(); o.Add(new Piece(raw ? v : XmlDoc.Esc(v, attr), kind)); @@ -389,7 +389,7 @@ public void SetCount(int index, int matches) void Sync() { bool typed = Box.Text.Trim().Length > 0; - count.Text = !typed ? "" : total == 0 ? I18n.T("Sin resultados", "No results") : filter.On ? total.ToString("N0") : (at >= 0 ? I18n.Fmt("{0} de {1}", "{0} of {1}", (at + 1).ToString("N0"), total.ToString("N0")) : total.ToString("N0")); + count.Text = !typed ? "" : total == 0 ? I18n.T("Sin resultados", "No results") : filter.On ? total.ToString("N0", I18n.Culture) : (at >= 0 ? I18n.Fmt("{0} de {1}", "{0} of {1}", (at + 1).ToString("N0", I18n.Culture), total.ToString("N0", I18n.Culture)) : total.ToString("N0", I18n.Culture)); Visibility nav = typed && !filter.On ? Visibility.Visible : Visibility.Collapsed; prev.Visibility = next.Visibility = nav; prev.IsEnabled = next.IsEnabled = total > 0; @@ -813,7 +813,7 @@ public void CopySelection() bool cut; string t = SelectionText(out cut); int n = list.SelectedItems.Count; - if (t.Length > 0) Ask(t, cut ? I18n.T("Copiado en parte: la selecci\u00F3n es demasiado grande.", "Partially copied: selection is too large.") : n == 1 ? I18n.T("Copiado.", "Copied.") : I18n.Fmt("Copiadas {0} l\u00EDneas.", "{0} lines copied.", n.ToString("N0"))); + if (t.Length > 0) Ask(t, cut ? I18n.T("Copiado en parte: la selecci\u00F3n es demasiado grande.", "Partially copied: selection is too large.") : n == 1 ? I18n.T("Copiado.", "Copied.") : I18n.Fmt("Copiadas {0} l\u00EDneas.", "{0} lines copied.", n.ToString("N0", I18n.Culture))); } // ---- Text positions (for moving between the tree and the editor) @@ -893,7 +893,7 @@ public static BitmapSource Render(List rows, XmlLook look, out string erro StackPanel sp = new StackPanel { Width = W }; for (int i = 0; i < n; i++) sp.Children.Add(new XmlRowView(ForExport(rows[i], look))); if (n < rows.Count) - sp.Children.Add(new TextBlock { Text = I18n.Fmt("\u2026 y {0} l\u00EDneas m\u00E1s (contrae lo que no necesites para verlas)", "\u2026 and {0} more lines (collapse what you don't need to see them)", (rows.Count - n).ToString("N0")), Foreground = look.Hint, FontSize = 12.5, Margin = new Thickness(XmlRowView.Gutter, 8, 0, 0) }); + sp.Children.Add(new TextBlock { Text = I18n.Fmt("\u2026 y {0} l\u00EDneas m\u00E1s (contrae lo que no necesites para verlas)", "\u2026 and {0} more lines (collapse what you don't need to see them)", (rows.Count - n).ToString("N0", I18n.Culture)), Foreground = look.Hint, FontSize = 12.5, Margin = new Thickness(XmlRowView.Gutter, 8, 0, 0) }); page = new Border { Background = Ds.Brush(look.Dark ? Ds.Rgb(30, 30, 32) : Colors.White), Padding = new Thickness(28, 26, 28, 28), Width = W + 56, UseLayoutRounding = true, Child = sp }; TextOptions.SetTextFormattingMode(page, TextFormattingMode.Ideal); TextOptions.SetTextRenderingMode(page, TextRenderingMode.Grayscale); diff --git a/tests/app/AppTestsI18n.cs b/tests/app/AppTestsI18n.cs index 3b66c21..14eaf8f 100644 --- a/tests/app/AppTestsI18n.cs +++ b/tests/app/AppTestsI18n.cs @@ -76,6 +76,15 @@ public static void Suite() T("sensitive-notice-bodies-fit", AppTestsI18nAudit.SensitiveNoticeBodiesFit); T("old-release-bodies-still-read", AppTestsI18nAudit.OldReleaseBodiesStillRead); T("workflow-writes-the-markers", AppTestsI18nAudit.WorkflowWritesTheMarkers); + T("quick-window-buttons-fit-in-every-language", AppTestsI18nLayout.QuickWindowButtonsFit); + T("quick-reminder-choices-fit-in-every-language", AppTestsI18nLayout.QuickReminderChoicesFit); + T("confirmation-buttons-fit-in-every-language", AppTestsI18nLayout.AlertButtonsFit); + T("scroll-bar-texts-fit-in-every-language", AppTestsI18nLayout.ScrollBarTextsFit); + T("backdrop-panel-labels-fit-in-every-language", AppTestsI18nLayout.BackdropPanelLabelsFit); + T("sensitive-results-fit-the-editor-hint-in-every-language", AppTestsI18nLayout.SensitiveResultsFit); + T("numbers-follow-the-interface-language-not-windows", AppTestsI18nLayout.NumbersFollowTheInterfaceLanguage); + T("no-number-takes-the-windows-format", AppTestsI18nLayout.NoNumberTakesTheWindowsFormat); + T("focus-minutes-are-localized", AppTestsI18nLayout.FocusMinutesAreLocalized); } finally { diff --git a/tests/app/AppTestsI18nLayout.cs b/tests/app/AppTestsI18nLayout.cs new file mode 100644 index 0000000..d00983c --- /dev/null +++ b/tests/app/AppTestsI18nLayout.cs @@ -0,0 +1,558 @@ +// Suite "i18n", layout checks that every interface language has to pass: windows are built and laid out at their real +// width, never shown, and what they draw has to sit inside the window instead of running off its edge. With +// STACKSHOT_UI_SHOTS set to a folder, the German, Korean and English ones are also saved there as PNG to be looked at. +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization; +using System.Text.RegularExpressions; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace Stackshot.Tests +{ + static class AppTestsI18nLayout + { + internal static readonly string[] AllLanguages = { "es", "en", "de", "ko", "fr", "pt", "zh", "hi", "ar", "bn" }; + const BindingFlags NP = BindingFlags.NonPublic | BindingFlags.Instance; + + static void Check(bool ok, string what) { if (!ok) throw new InvalidOperationException(what); } + + static string Ascii(string s) { return Regex.Replace(s ?? "", "[^\\x20-\\x7e]", "?"); } + + // The window's content laid out at the width the window has (its height follows the content). + static FrameworkElement Lay(Window w, double width) + { + FrameworkElement root = (FrameworkElement)w.Content; + root.Measure(new Size(width, double.PositiveInfinity)); + root.Arrange(new Rect(0, 0, width, root.DesiredSize.Height)); + root.UpdateLayout(); + return root; + } + + // The content as a PNG, on the window's own background (a window's background is not part of its Content). + static void Shot(FrameworkElement root, string name) + { + string dir = Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"); + if (string.IsNullOrEmpty(dir)) return; + Directory.CreateDirectory(dir); + int w = (int)Math.Ceiling(root.ActualWidth), h = (int)Math.Ceiling(root.ActualHeight); + if (w <= 0 || h <= 0) return; + DrawingVisual dv = new DrawingVisual(); + using (DrawingContext dc = dv.RenderOpen()) + { + dc.DrawRectangle(Ds.Brush(Ds.Brushes.Window), null, new Rect(0, 0, w, h)); + dc.DrawRectangle(new VisualBrush(root), null, new Rect(0, 0, w, h)); + } + RenderTargetBitmap rtb = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32); + rtb.Render(dv); + PngBitmapEncoder enc = new PngBitmapEncoder(); + enc.Frames.Add(BitmapFrame.Create(rtb)); + using (FileStream fs = File.Create(Path.Combine(dir, "i18n-layout-" + name + ".png"))) enc.Save(fs); + } + + // A window that was built and laid out but never shown still listens to theme changes until it is closed. + static void Dispose(Window w) { try { w.Close(); } catch (Exception) { } } + + static bool Pictured(string lang) { return lang == "de" || lang == "ko" || lang == "en"; } + + // A WinForms control as a PNG, without showing it. + static void ShotControl(System.Windows.Forms.Control c, int height, string name) + { + string dir = Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"); + if (string.IsNullOrEmpty(dir)) return; + Directory.CreateDirectory(dir); + c.Height = height; + using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(c.Width, c.Height)) + { + c.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, c.Width, c.Height)); + bmp.Save(Path.Combine(dir, "i18n-layout-" + name + ".png"), System.Drawing.Imaging.ImageFormat.Png); + } + } + + // The room a button has: it starts inside the window and ends before the window's padding, and is not squeezed. + static void ButtonsInside(FrameworkElement root, string where, List bad) + { + int buttons = 0; + AppTestsI18n.Walk(root, new HashSet(), delegate(DependencyObject d) + { + MacButton b = d as MacButton; + if (b == null) return; + buttons++; + Rect r = b.TransformToAncestor(root).TransformBounds(new Rect(0, 0, b.ActualWidth, b.ActualHeight)); + if (b.ActualWidth < b.Width - 0.5) bad.Add(where + ": \"" + Ascii(b.Label) + "\" squeezed to " + (int)b.ActualWidth + " of " + (int)b.Width); + else if (r.Left < 8 || r.Right > root.ActualWidth - 8) + bad.Add(where + ": \"" + Ascii(b.Label) + "\" runs from " + (int)r.Left + " to " + (int)r.Right + " in a window " + (int)root.ActualWidth + " wide"); + }); + if (buttons == 0) bad.Add(where + ": no button found"); + } + + static void Report(List bad, string what) + { + foreach (string s in bad) Console.WriteLine(" " + what + ": " + s); + Check(bad.Count == 0, bad.Count + " " + what); + } + + // ---- Quick note and reminder + + static ShotStack Owner(bool reminders) + { + ShotStack owner = (ShotStack)FormatterServices.GetUninitializedObject(typeof(ShotStack)); + FieldInfo f = typeof(ShotStack).GetField("reminders", NP); // uninitialized owner: the list is still null + if (reminders && f != null && f.GetValue(owner) == null) + f.SetValue(owner, Activator.CreateInstance(typeof(List<>).MakeGenericType(f.FieldType.GetGenericArguments()[0]))); + return owner; + } + + static QuickWindow Quick(bool note) + { + return (QuickWindow)typeof(QuickWindow).GetConstructor(NP, null, new[] { typeof(ShotStack), typeof(bool) }, null).Invoke(new object[] { Owner(!note), note }); + } + + // The save, pin and cancel buttons of the small window the mascot opens sit in one row: in no language does the + // row run past the window's edge (German used to cut the primary button). + public static void QuickWindowButtonsFit() + { + List bad = new List(); + try + { + foreach (bool note in new[] { true, false }) + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + QuickWindow w = Quick(note); + FrameworkElement root = Lay(w, w.Width); + ButtonsInside(root, lang + (note ? "/note" : "/reminder"), bad); + if (Pictured(lang)) Shot(root, "quick-" + (note ? "note" : "reminder") + "-" + lang); + Dispose(w); + } + } + finally { I18n.Apply("es"); } + Report(bad, "quick window buttons out of the window"); + } + + // "When?" gives its six choices one sixth of the width each: none of them is cut with an ellipsis. + public static void QuickReminderChoicesFit() + { + List bad = new List(); + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + QuickWindow w = Quick(false); + FrameworkElement root = Lay(w, w.Width); + int found = 0; + AppTestsI18n.Walk(root, new HashSet(), delegate(DependencyObject d) + { + MacSegmented seg = d as MacSegmented; + if (seg == null) return; + found++; + string[] options = (string[])typeof(MacSegmented).GetField("options", NP).GetValue(seg); + double room = (seg.ActualWidth - 4) / options.Length - MacSegmented.TextPad; + foreach (string o in options) + { + double need = Ink.Text(o, Ds.Semibold, 12.5, Colors.Black).WidthIncludingTrailingWhitespace; + if (need > room + 0.5) bad.Add(lang + ": \"" + Ascii(o) + "\" needs " + (int)Math.Ceiling(need) + " px, has " + (int)room); + } + }); + if (found != 1) bad.Add(lang + ": expected one choice strip, found " + found); + Dispose(w); + } + } + finally { I18n.Apply("es"); } + Report(bad, "reminder time choices cut"); + } + + // ---- Confirmation dialogs + + // The button sets of the confirmations the app asks (editor, documents, settings), as the call sites write them. + static List AlertSets() + { + string cancel = I18n.Cancel; + return new List + { + new[] { I18n.T("Guardar", "Save"), I18n.T("No guardar", "Don't save"), I18n.T("Cancelar", "Cancel") }, // document: unsaved changes + new[] { I18n.T("Exportar", "Export"), I18n.T("Descartar cambios", "Discard changes"), I18n.T("Seguir editando", "Keep editing") }, // editor: recording, closing + new[] { I18n.T("Conservar", "Keep"), I18n.T("Descartar cambios", "Discard changes"), I18n.T("Seguir editando", "Keep editing") }, // editor: capture, closing + new[] { I18n.T("Exportar", "Export"), I18n.T("Salir sin exportar", "Exit without exporting"), I18n.T("Seguir editando", "Keep editing") }, // editor: recording, exiting + new[] { I18n.T("Guardar", "Save"), I18n.T("No guardar", "Don't save"), I18n.T("Seguir editando", "Keep editing") }, // editor: capture, exiting + new[] { I18n.T("S\u00ED", "Yes", "Ja"), I18n.T("No", "No", "Nein"), cancel }, // Dialogs: Yes / No / Cancel + new[] { I18n.T("Cancelar la exportaci\u00F3n", "Cancel export"), I18n.T("Seguir exportando", "Keep exporting") }, + new[] { I18n.T("Cancelar y salir", "Cancel and exit"), I18n.T("Seguir exportando", "Keep exporting") }, + new[] { I18n.T("Descartar", "Discard"), I18n.T("Seguir escribiendo", "Keep typing") }, + new[] { I18n.T("Detener y salir", "Stop and exit"), I18n.T("Seguir grabando", "Keep recording") }, + new[] { I18n.T("Guardar igualmente", "Save anyway"), cancel }, + new[] { I18n.T("Guardar en UTF-8", "Save in UTF-8"), cancel }, + new[] { I18n.T("Guardar como PDF", "Save as PDF"), cancel }, + new[] { I18n.T("Guardar como\u2026", "Save as\u2026"), cancel }, + new[] { I18n.T("Borrar el \u00EDndice", "Delete index"), cancel }, + }; + } + + public static void AlertButtonsFit() + { + List bad = new List(); + ConstructorInfo ctor = typeof(DocAlert).GetConstructor(NP, null, new[] { typeof(string), typeof(string), typeof(string[]), typeof(int), typeof(int) }, null); + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + List sets = AlertSets(); + for (int k = 0; k < sets.Count; k++) + { + string[] set = sets[k]; + int primary = 0, cancel = set.Length - 1; + DocAlert w = (DocAlert)ctor.Invoke(new object[] { I18n.Fmt("\u00BFGuardar los cambios en {0} antes de salir?", "Save changes in {0} before exiting?", "captura.png"), I18n.T("Si no los guardas, se perder\u00E1n.", "If you don't save them, they will be lost."), set, primary, cancel }); + FrameworkElement root = Lay(w, w.Width); + string where = lang + "/" + Ascii(string.Join(" | ", set)); + ButtonsInside(root, where, bad); + if (Pictured(lang) && k == 1) Shot(root, "alert-" + lang); + Dispose(w); + } + } + } + finally { I18n.Apply("es"); } + Report(bad, "confirmation buttons out of the dialog"); + } + + // ---- Scrolling-capture bar + + // The bar's two text lines (what it shows and what the button under the mouse does) have one line of StatusRoom + // pixels: every status text, and the height line at its longest, fits it in every language. + public static void ScrollBarTextsFit() + { + List bad = new List(); + // saving, esc, done, full, wentUp, losing, hot, auto, stuck: one case for every branch of the status line. + object[][] cases = + { + new object[] { true, false, false, false, false, false, -1, false, false }, + new object[] { false, true, false, false, false, false, -1, false, false }, + new object[] { false, false, true, false, false, false, -1, false, false }, + new object[] { false, false, false, true, false, false, -1, false, false }, + new object[] { false, false, false, false, true, false, -1, false, false }, + new object[] { false, false, false, false, false, true, -1, false, false }, + new object[] { false, false, false, false, false, false, 0, true, false }, + new object[] { false, false, false, false, false, false, 0, false, false }, + new object[] { false, false, false, false, false, false, 1, false, false }, + new object[] { false, false, false, false, false, false, 2, false, false }, + new object[] { false, false, false, false, false, false, -1, true, false }, + new object[] { false, false, false, false, false, false, -1, false, true }, + new object[] { false, false, false, false, false, false, -1, false, false }, + }; + int statusPx = (int)Math.Round(11.5f), heightPx = 14; + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + foreach (object[] c in cases) + { + string text = ScrollCaptureBar.StateText((bool)c[0], (bool)c[1], (bool)c[2], (bool)c[3], (bool)c[4], (bool)c[5], (int)c[6], (bool)c[7], (bool)c[8]); + double need = Ink.Px(text, Ds.Regular, statusPx, Colors.White).WidthIncludingTrailingWhitespace; + if (need > ScrollCaptureBar.StatusRoom + 0.5) bad.Add(lang + ": \"" + Ascii(text) + "\" needs " + (int)Math.Ceiling(need) + " px of " + ScrollCaptureBar.StatusRoom); + } + foreach (int h in new[] { 0, 900, 12345, 99999 }) + { + string text = ScrollCaptureBar.HeightText(h, 700); + double need = Ink.Px(text, Ds.Semibold, heightPx, Colors.White).WidthIncludingTrailingWhitespace; + if (need > ScrollCaptureBar.StatusRoom + 0.5) bad.Add(lang + ": \"" + Ascii(text) + "\" needs " + (int)Math.Ceiling(need) + " px of " + ScrollCaptureBar.StatusRoom); + } + } + } + finally { I18n.Apply("es"); } + ScrollBarShots(); + Report(bad, "scrolling-capture bar texts cut"); + } + + // The bar itself, painted without showing it (the real window would sit on the user's screen): the longest status + // line ("Done again saves it") and the hint of the Pause button, 1.6 screens of the page behind it. + static void ScrollBarShot(string lang, string name, bool doneArmed, int hot, bool auto) + { + const BindingFlags Any = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; + I18n.Apply(lang); + ScrollSession session = new ScrollSession((ShotStack)FormatterServices.GetUninitializedObject(typeof(ShotStack)), new System.Drawing.Rectangle(0, 0, 800, 600)); + typeof(Stitcher).GetField("height", Any).SetValue(typeof(ScrollSession).GetField("stitcher", Any).GetValue(session), 960); + if (doneArmed) typeof(ScrollSession).GetField("doneArmed", Any).SetValue(session, 0L); + if (auto) typeof(ScrollSession).GetField("auto", Any).SetValue(session, true); + ScrollCaptureBar bar = (ScrollCaptureBar)FormatterServices.GetUninitializedObject(typeof(ScrollCaptureBar)); + typeof(ScrollCaptureBar).GetField("session", Any).SetValue(bar, session); + typeof(ScrollCaptureBar).GetField("hot", Any).SetValue(bar, hot); + typeof(ScrollCaptureBar).GetField("s", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy).SetValue(bar, 1f); + typeof(FloatWindow).GetField("Pad", Any).SetValue(bar, 22); + typeof(FloatWindow).GetField("body", Any).SetValue(bar, new System.Drawing.Size(ScrollCaptureBar.BarWidth, 48)); + int w = ScrollCaptureBar.BarWidth + 44, h = 48 + 44; + DrawingVisual dv = new DrawingVisual(); + using (DrawingContext dc = dv.RenderOpen()) + { + dc.DrawRectangle(new SolidColorBrush(Color.FromRgb(236, 236, 240)), null, new Rect(0, 0, w, h)); + typeof(ScrollCaptureBar).GetMethod("PaintSurface", Any).Invoke(bar, new object[] { dc, w, h }); + } + RenderTargetBitmap rtb = new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32); + rtb.Render(dv); + PngBitmapEncoder enc = new PngBitmapEncoder(); + enc.Frames.Add(BitmapFrame.Create(rtb)); + using (FileStream fs = File.Create(Path.Combine(Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"), "i18n-layout-scroll-bar-" + name + "-" + lang + ".png"))) enc.Save(fs); + } + + public static void ScrollBarShots() + { + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"))) return; + try + { + foreach (string lang in new[] { "de", "ko", "en" }) + { + ScrollBarShot(lang, "done-again", true, -1, false); + ScrollBarShot(lang, "pause-hint", false, 0, true); + } + } + finally { I18n.Apply("es"); } + } + + // ---- Editor backdrop panel + + static int TextW(BgPanel panel, string method, string text) + { + System.Drawing.Font f = (System.Drawing.Font)typeof(BgPanel).GetMethod(method, NP).Invoke(panel, null); + return TextKit.Measure(text, f, System.Drawing.Size.Empty, System.Windows.Forms.TextFormatFlags.NoPadding).Width; + } + + // The sidebar draws its labels in one line with no room to wrap: the checkbox beside "Border inset", the two + // headers over the half columns, a slider's name beside its value, the pop-up buttons: all of them fit their + // space in every language, at the sidebar's width. + public static void BackdropPanelLabelsFit() + { + List bad = new List(); + Type kind = typeof(BgPanel).GetNestedType("Kind", BindingFlags.NonPublic); + Type itemType = typeof(BgPanel).GetNestedType("Item", BindingFlags.NonPublic); + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + foreach (bool video in new[] { false, true }) + { + BgPanel panel = new BgPanel { S = 1f, Bg = new Settings(), Video = video }; + panel.Width = (int)BgPanel.Wide; + typeof(BgPanel).GetMethod("Arrange", NP).Invoke(panel, new object[] { panel.Width }); + System.Collections.IList items = (System.Collections.IList)typeof(BgPanel).GetField("items", NP).GetValue(panel); + int seen = 0; + foreach (object it in items) + { + string name = itemType.GetField("Kind").GetValue(it).ToString(); + string label = (string)itemType.GetField("Label").GetValue(it); + System.Drawing.Rectangle r = (System.Drawing.Rectangle)itemType.GetField("R").GetValue(it); + if (label == null) continue; + int need, room; + string how; + switch (name) + { + case "Check": need = TextW(panel, "Small", label); room = r.Width - 16 - 8; how = "beside its box"; break; + case "Slider": need = TextW(panel, "Small", label) + 8 + TextW(panel, "Small", "100"); room = r.Width; how = "with its value"; break; + case "Header": need = TextW(panel, "Small", label); room = r.Width; how = "as a header"; break; + case "None": need = TextW(panel, "Semibold", label); room = r.Width; how = "on its button"; break; + case "More": need = TextW(panel, "Small", label) + 18; room = r.Width; how = "beside its arrow"; break; + default: continue; + } + seen++; + if (need > room) bad.Add(lang + (video ? "/video" : "") + ": \"" + Ascii(label) + "\" (" + how + ") needs " + need + " px, has " + room); + } + foreach (string text in new[] { I18n.T("Estilos guardados\u2026", "Saved styles\u2026"), I18n.Fmt("Estilos guardados ({0})", "Saved styles ({0})", 12) }) + { + int need = TextW(panel, "Regular", text), room = (int)BgPanel.Wide - 28 - 38 - 30; + if (need > room) bad.Add(lang + ": \"" + Ascii(text) + "\" (saved styles button) needs " + need + " px, has " + room); + } + if (seen < 8) bad.Add(lang + ": only " + seen + " labels found"); + if (!video && Pictured(lang)) ShotControl(panel, (int)typeof(BgPanel).GetField("contentH", NP).GetValue(panel), "backdrop-panel-" + lang); + } + } + } + finally { I18n.Apply("es"); } + Report(bad, "backdrop panel labels cut"); + } + + // ---- Editor hint strip: what the sensitive-data search says + + // The result of "Hide sensitive data" is said in the hint strip, one line between its left edge and the drag handle + // (or the size line): at the editor's usual 1264 px every wording of it, in every language, fits without the ellipsis. + public static void SensitiveResultsFit() + { + List bad = new List(); + List four = Sensitive.Scan("12345678Z ES91 2100 0418 4502 0005 1332 a@b.es c@d.es"); + List one = Sensitive.Scan("600 123 456"); + Check(four.Count >= 3 && one.Count == 1, "the sample text should be found: " + four.Count + " / " + one.Count); + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + List messages = new List + { + Editor.SensitiveResult(four, four.Count), Editor.SensitiveResult(four, 1), Editor.SensitiveResult(four, 0), + Editor.SensitiveResult(one, 1), Editor.SensitiveResult(one, 0), Editor.SensitiveResult(new List(), 0), + // What the editor says when it opens a capture that was covered when it was taken. + I18n.T("El dato sensible se tap\u00F3 al capturar: es una marca y puedes quitarla.", "Sensitive data was redacted on capture: it is a mark and you can remove it."), + I18n.T("Los datos sensibles se taparon al capturar: son marcas y puedes quitar cualquiera.", "Sensitive data was redacted on capture: they are marks and you can remove any."), + }; + string action = I18n.T("Enter copia y cierra", "Enter copies and closes"); + using (Hint hint = new Hint { S = 1f, Width = 1264, Height = 34 }) + { + hint.DragOut += delegate { }; + hint.RightText = "1264 \u00D7 700 px \u00B7 " + action; + System.Drawing.Font f = Fonts.Get(EdLook.Text, 12f); + System.Drawing.Rectangle handle = hint.HandleRect; + int right = hint.Width - TextKit.Measure(hint.RightText, f, System.Drawing.Size.Empty, System.Windows.Forms.TextFormatFlags.NoPadding).Width - 14; + int room = (handle.IsEmpty ? right : handle.X) - 2 * 14; // the left text's rectangle, as the strip paints it + foreach (string m in messages) + { + int need = TextKit.Measure(m, f, System.Drawing.Size.Empty, System.Windows.Forms.TextFormatFlags.NoPadding).Width; + if (need > room) bad.Add(lang + ": \"" + Ascii(m) + "\" needs " + need + " px, has " + room); + } + if (Pictured(lang)) { hint.LeftText = messages[0]; ShotControl(hint, 34, "sensitive-result-" + lang); } + } + } + } + finally { I18n.Apply("es"); } + Report(bad, "sensitive-data messages cut"); + } + + // ---- Numbers + + static void Pump(Func done, int ms) + { + System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); + while (!done() && sw.ElapsedMilliseconds < ms) + { + System.Windows.Threading.DispatcherFrame fr = new System.Windows.Threading.DispatcherFrame(); + System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)delegate { fr.Continue = false; }); + System.Windows.Threading.Dispatcher.PushFrame(fr); + if (!done()) System.Threading.Thread.Sleep(5); + } + } + + static string StatusOf(MarkdownWindow w, string file) + { + typeof(MarkdownWindow).GetMethod("LoadFile", NP).Invoke(w, new object[] { file }); + Pump(delegate { return w.Doc != null && w.Doc.Path != null && Path.GetFileName(w.Doc.Path) == Path.GetFileName(file); }, 15000); + Pump(delegate { return false; }, 600); // the XML tree is built in the background + typeof(MarkdownWindow).GetMethod("Stats", NP).Invoke(w, null); + return ((TextBlock)typeof(MarkdownWindow).GetField("statusLabel", NP).GetValue(w)).Text; + } + + // Shown numbers follow the interface language, not the regional format of Windows: a Spanish Windows with the + // interface in English reads "30,002 nodes", an English Windows with the interface in Spanish "30.002 nodos". + public static void NumbersFollowTheInterfaceLanguage() + { + string dir = Path.Combine(Path.GetTempPath(), "stackshot-app-tests", "i18n-numbers"); + Directory.CreateDirectory(dir); + string md = Path.Combine(dir, "long.md"), xml = Path.Combine(dir, "many.xml"); + System.Text.StringBuilder words = new System.Text.StringBuilder(); + for (int i = 0; i < 30002; i++) words.Append("word "); + File.WriteAllText(md, words.ToString()); + System.Text.StringBuilder nodes = new System.Text.StringBuilder(""); + for (int i = 0; i < 30001; i++) nodes.Append(""); + File.WriteAllText(xml, nodes.Append("").ToString()); + CultureInfo regional = System.Threading.Thread.CurrentThread.CurrentCulture, ui = System.Threading.Thread.CurrentThread.CurrentUICulture; + List bad = new List(); + try + { + foreach (string lang in new[] { "en", "ko", "es", "de" }) + { + // The Windows regional format is the other one: Spanish when the interface is not, English when it is. + System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(lang == "es" || lang == "de" ? "en-US" : "es-ES"); + I18n.Apply(lang); + string shown = I18n.Culture.Name == "en-US" ? "30,002" : "30.002"; + MarkdownWindow w = (MarkdownWindow)typeof(MarkdownWindow).GetConstructors(NP)[0].Invoke(new object[] { null }); + typeof(MarkdownWindow).GetField("open", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, w); + try + { + w.Left = -6000; w.Top = 0; w.ShowActivated = false; w.ShowInTaskbar = false; + w.Show(); + string text = StatusOf(w, md); + if (!text.Contains(shown)) bad.Add(lang + " words: \"" + Ascii(text) + "\" should count " + shown); + if (lang == "en" || lang == "ko") { w.UpdateLayout(); Shot((FrameworkElement)w.Content, "document-status-" + lang + "-windows-es-ES"); } + text = StatusOf(w, xml); + if (!text.Contains(shown)) bad.Add(lang + " nodes: \"" + Ascii(text) + "\" should count " + shown); + } + finally + { + Func keep = DocAlert.Answer; + DocAlert.Answer = delegate { return 1; }; + try { w.Close(); } catch { } + DocAlert.Answer = keep; + } + string size = Recents.Size(5L * 1048576 + 500000); + string wantSize = (I18n.Culture.Name == "en-US" ? "5.5" : "5,5") + " MB"; + if (size != wantSize) bad.Add(lang + " size: \"" + size + "\" should be \"" + wantSize + "\""); + } + } + finally + { + System.Threading.Thread.CurrentThread.CurrentCulture = regional; + System.Threading.Thread.CurrentThread.CurrentUICulture = ui; + I18n.Apply("es"); + } + Report(bad, "numbers in the Windows format"); + } + + // The rest of the places that show a count or a size say them in a culture: a number turned into text with no + // culture takes the Windows regional format, and the interface language is the one that goes around it. + public static void NoNumberTakesTheWindowsFormat() + { + string src = Path.Combine(AppTestsI18nCoverage.RepoRoot(), "src"); + Regex bare = new Regex("\\.ToString\\(\"[NnFfPp][0-9]*\"\\)|\\.ToString\\(\"0\\.[0#]+\"\\)|\\.ToString\\([^()\"]*\\? \"0\\.[0#]+\"|\\{[0-9]+:[NnFfPp][0-9]*\\}(?=[^\\n]*(Format|Localize))"); + List bad = new List(); + foreach (string path in Directory.GetFiles(src, "*.cs", SearchOption.AllDirectories)) + { + string[] lines = File.ReadAllLines(path); + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (line.TrimStart().StartsWith("//") || line.Contains("I18n.Culture") || line.Contains("Guid") || line.Contains("InvariantCulture")) continue; + MatchCollection ms = bare.Matches(line); + foreach (Match m in ms) bad.Add(path.Substring(src.Length + 1) + ":" + (i + 1) + " " + m.Value); + } + } + Report(bad, "numbers turned into text with no culture"); + } + + // ---- Minutes + + // "25 min" is an English unit: the Korean pet menu says "25\uBD84", an hour and a quarter "1\uC2DC\uAC04 15\uBD84"; the other + // languages keep theirs (and a language that only previews English reads the English one). + public static void FocusMinutesAreLocalized() + { + List bad = new List(); + try + { + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + string[] want = lang == "ko" ? new[] { "25\uBD84", "1\uC2DC\uAC04", "1\uC2DC\uAC04 15\uBD84", "2\uC2DC\uAC04" } : new[] { "25 min", "1 h", "1 h 15 min", "2 h" }; + int[] minutes = { 25, 60, 75, 120 }; + for (int i = 0; i < minutes.Length; i++) + if (FocusClock.Minutes(minutes[i]) != want[i]) bad.Add(lang + ": " + minutes[i] + " min reads \"" + Ascii(FocusClock.Minutes(minutes[i])) + "\", expected \"" + Ascii(want[i]) + "\""); + if (lang == "ko") + { + // The choices of the quick reminder say their unit in Korean too. + QuickWindow w = Quick(false); + Lay(w, w.Width); + MacSegmented seg = null; + AppTestsI18n.Walk((DependencyObject)w.Content, new HashSet(), delegate(DependencyObject d) { if (d is MacSegmented) seg = (MacSegmented)d; }); + string[] options = (string[])typeof(MacSegmented).GetField("options", NP).GetValue(seg); + for (int i = 0; i < 4; i++) + if (options[i] != FocusClock.Minutes(new[] { 10, 30, 60, 120 }[i])) bad.Add("ko: quick reminder choice " + i + " reads \"" + Ascii(options[i]) + "\""); + Dispose(w); + } + } + } + finally { I18n.Apply("es"); } + Report(bad, "focus minutes not localized"); + } + } +}