From 7731065a7116e73637e0dcd018faade0e0c4389e 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 14:51:25 +0100 Subject: [PATCH 1/2] fix(i18n): Localize export names, settle Korean particles and fix the German and Korean texts of the final audit --- src/Capture/Recorder.cs | 2 +- src/Editor/Editor.cs | 4 +- src/Editor/PlayerKit.cs | 3 + src/Editor/PlayerWindow.PieceGif.cs | 4 +- src/Editor/PlayerWindow.cs | 6 +- src/ExportName.cs | 18 + src/Home/HomeViews.cs | 14 +- src/Home/MascotAnime.cs | 6 +- src/Home/MascotArcadePowers.cs | 18 +- src/Home/MascotTalk.cs | 14 +- src/Home/Wellness.cs | 10 +- src/I18n.German.App.cs | 16 +- src/I18n.German.Editor.cs | 2 +- src/I18n.German.MascotCast.cs | 4 +- src/I18n.Korean.Capture.cs | 4 +- src/I18n.Korean.Core.cs | 2 +- src/I18n.Korean.Editor.cs | 4 +- src/I18n.Korean.HomeDialogue.cs | 8 +- src/I18n.Korean.HomeSettings.cs | 4 +- src/I18n.Korean.Particle.cs | 62 ++++ src/I18n.cs | 13 +- src/ReportWindow.cs | 9 +- src/ShotStack.Wellness.cs | 10 +- tests/app/AppTestsI18n.cs | 1 + tests/app/AppTestsI18nFinal.cs | 507 ++++++++++++++++++++++++++++ 25 files changed, 684 insertions(+), 61 deletions(-) create mode 100644 src/ExportName.cs create mode 100644 src/I18n.Korean.Particle.cs create mode 100644 tests/app/AppTestsI18nFinal.cs diff --git a/src/Capture/Recorder.cs b/src/Capture/Recorder.cs index bf6d4d9..4b242e4 100644 --- a/src/Capture/Recorder.cs +++ b/src/Capture/Recorder.cs @@ -2268,7 +2268,7 @@ void MakeCine(double seconds) string dest = output; if (!v.Passed) { - dest = ShotStack.Unique(Path.ChangeExtension(output, null) + " (sin verificar)" + Cine.Extension); + dest = ShotStack.Unique(Path.ChangeExtension(output, null) + I18n.Own(" (sin verificar)", " (unverified)", " (ungepr\u00FCft)", " (\uBBF8\uAC80\uC99D)") + Cine.Extension); warning = watch.Cancelled ? I18n.Fmt("Has cancelado la comprobaci\u00F3n: el archivo se ha guardado sin verificar como \u00AB{0}\u00BB.", "You cancelled the check: the file was saved unverified as \u201C{0}\u201D.", Path.GetFileName(dest)) : I18n.Fmt("La comprobaci\u00F3n ha encontrado diferencias: el archivo se ha guardado como \u00AB{0}\u00BB.", diff --git a/src/Editor/Editor.cs b/src/Editor/Editor.cs index 75d3e9f..054ed08 100644 --- a/src/Editor/Editor.cs +++ b/src/Editor/Editor.cs @@ -1870,7 +1870,7 @@ void ExportVideo() // Next to a saved video (kept like it), else with the temporary captures. string dir = owner != null ? owner.ExportFolder(path) : Path.GetDirectoryName(path); string ext = toGif ? ".gif" : ".mp4"; - string suffix = IsMaster && !bg && !marks && !cropped && !trimmed && !cuts && !joined ? " (para compartir)" : " (editado)"; + string suffix = IsMaster && !bg && !marks && !cropped && !trimmed && !cuts && !joined ? ExportName.ForSharing : ExportName.Edited; exportOut = ShotStack.Reserve(Path.Combine(dir, Path.GetFileNameWithoutExtension(path) + suffix + ext)); ExportSpec spec = new ExportSpec(); @@ -2124,7 +2124,7 @@ void CheckDone(ExportAbort ab, ShareReport rep) string kept = exportOut; try { - kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(exportOut), Path.GetFileNameWithoutExtension(exportOut) + " (sin validar)" + Path.GetExtension(exportOut))); + kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(exportOut), Path.GetFileNameWithoutExtension(exportOut) + ExportName.Unverified + Path.GetExtension(exportOut))); File.Move(exportOut, kept); exportOut = kept; } diff --git a/src/Editor/PlayerKit.cs b/src/Editor/PlayerKit.cs index 397e49f..b037bbb 100644 --- a/src/Editor/PlayerKit.cs +++ b/src/Editor/PlayerKit.cs @@ -24,6 +24,9 @@ internal static class PlayerKit public static readonly string[] EditorFormats = ShotStack.VideoExtensions; public static string CineDir = Path.Combine(Settings.DataDir, "cine"); // tests point it elsewhere + // The button that picks the audio track: "Audio" in Spanish, English and German, "\uC624\uB514\uC624" in Korean. + public static string AudioLabel { get { return I18n.T("Audio", "Audio", "Audio"); } } + static string Dec(double v, string f) { return v.ToString(f, I18n.Culture); } // 1:07 or 1:02:03. diff --git a/src/Editor/PlayerWindow.PieceGif.cs b/src/Editor/PlayerWindow.PieceGif.cs index b834200..c6bb180 100644 --- a/src/Editor/PlayerWindow.PieceGif.cs +++ b/src/Editor/PlayerWindow.PieceGif.cs @@ -158,7 +158,7 @@ void ExportGif() try { Directory.CreateDirectory(dir); - output = ShotStack.Reserve(Path.Combine(dir, Path.GetFileNameWithoutExtension(path) + " (tramo).gif")); + output = ShotStack.Reserve(Path.Combine(dir, Path.GetFileNameWithoutExtension(path) + ExportName.Clip + ".gif")); } catch (Exception ex) { @@ -261,7 +261,7 @@ void GifDone(ExportAbort ab, string output, int code, string err, ShareReport re string kept = output; try { - kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + " (sin validar)" + Path.GetExtension(output))); + kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + ExportName.Unverified + Path.GetExtension(output))); File.Move(output, kept); } catch (Exception ex) { kept = output; ShotStack.Log("Reproductor: no se pudo renombrar: " + ex.Message); } diff --git a/src/Editor/PlayerWindow.cs b/src/Editor/PlayerWindow.cs index 382061b..ef202c3 100644 --- a/src/Editor/PlayerWindow.cs +++ b/src/Editor/PlayerWindow.cs @@ -637,7 +637,7 @@ void ExportMp4() try { Directory.CreateDirectory(dir); - output = ShotStack.Reserve(Path.Combine(dir, Path.GetFileNameWithoutExtension(path) + (HasRange ? " (tramo).mp4" : " (para compartir).mp4"))); + output = ShotStack.Reserve(Path.Combine(dir, Path.GetFileNameWithoutExtension(path) + (HasRange ? ExportName.Clip : ExportName.ForSharing) + ".mp4")); } catch (Exception ex) { @@ -756,7 +756,7 @@ void ExportDone(ExportAbort ab, string output, int code, string err, ShareReport string kept = output; try { - kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + " (sin validar)" + Path.GetExtension(output))); + kept = ShotStack.Unique(Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + ExportName.Unverified + Path.GetExtension(output))); File.Move(output, kept); } catch (Exception ex) { kept = output; ShotStack.Log("Reproductor: no se pudo renombrar: " + ex.Message); } @@ -1279,7 +1279,7 @@ void LayoutBar(Graphics g) Font pf = Face(true, 12); List right = new List(); right.Add(Make("full", fullscreen ? "restore" : "maximize", null, I18n.T("Pantalla completa (F)", "Full screen (F)"), P(34), false, false)); - if (info.Audio.Count > 1) right.Add(Make("tracks", null, "Audio", I18n.T("Pista de audio", "Audio track"), Math.Max(P(52), TextKit.Measure(g, "Audio", pf, Size.Empty, TextFormatFlags.NoPadding).Width + P(24)), false, true)); + if (info.Audio.Count > 1) right.Add(Make("tracks", null, PlayerKit.AudioLabel, I18n.T("Pista de audio", "Audio track"), Math.Max(P(52), TextKit.Measure(g, PlayerKit.AudioLabel, pf, Size.Empty, TextFormatFlags.NoPadding).Width + P(24)), false, true)); right.Add(Make("speed", null, PlayerKit.SpeedText(speed), I18n.T("Velocidad", "Speed"), Math.Max(P(48), TextKit.Measure(g, PlayerKit.SpeedText(speed), pf, Size.Empty, TextFormatFlags.NoPadding).Width + P(20)), speed != 1, true)); right.Add(Make("loop", "update", null, I18n.T("Repetir al terminar", "Loop playback"), P(34), loop, false)); right.Add(Make("menu", "gear", null, I18n.T("M\u00E1s opciones", "More options"), P(34), false, false)); diff --git a/src/ExportName.cs b/src/ExportName.cs new file mode 100644 index 0000000..2e9f97b --- /dev/null +++ b/src/ExportName.cs @@ -0,0 +1,18 @@ +// Stackshot - The words an exported file adds to the name of the video it comes from ("Cine A (editado).mp4"), in the +// interface language. Nothing reads them back (recordings are told by their "V\u00EDdeo", "GIF" and "Cine" prefixes), so they +// can follow the language; the other languages' previews use the English ones. +// MIT License - https://github.com/rubenitx/stackshot +namespace Stackshot +{ + internal static class ExportName + { + // A clip marked with E and S. + public static string Clip { get { return I18n.Own(" (tramo)", " (clip)", " (Ausschnitt)", " (\uAD6C\uAC04)"); } } + // Exported with a backdrop, annotations, a trim or cuts. + public static string Edited { get { return I18n.Own(" (editado)", " (edited)", " (bearbeitet)", " (\uD3B8\uC9D1\uB428)"); } } + // A lossless master compressed for sending as it is. + public static string ForSharing { get { return I18n.Own(" (para compartir)", " (for sharing)", " (zum Teilen)", " (\uACF5\uC720\uC6A9)"); } } + // The file the check could not vouch for, kept beside the one that was expected. + public static string Unverified { get { return I18n.Own(" (sin validar)", " (unverified)", " (ungepr\u00FCft)", " (\uBBF8\uAC80\uC99D)"); } } + } +} diff --git a/src/Home/HomeViews.cs b/src/Home/HomeViews.cs index 113972d..5d1761d 100644 --- a/src/Home/HomeViews.cs +++ b/src/Home/HomeViews.cs @@ -299,7 +299,7 @@ void BuildHomeMinimal() if (settings.MascotOn) { - MacButton chips = new MacButton(I18n.Fmt("Jugar con {0}", "Play with {0}", settings.MascotName), ButtonKind.Plain, "play", null, 26); + MacButton chips = new MacButton(MascotTalk.PlayWith(settings.MascotName), ButtonKind.Plain, "play", null, 26); chips.ToolTip = I18n.Fmt("P\u00EDdele algo a {0}", "Ask {0} something", settings.MascotName); chips.HorizontalAlignment = HorizontalAlignment.Center; chips.Margin = new Thickness(0, 12, 0, 0); @@ -734,7 +734,7 @@ FrameworkElement HomeNameTag(Typeface face, double size, Color color, bool centr TextBox box = new TextBox { - MaxLength = 16, MinWidth = 60, Visibility = Visibility.Collapsed, VerticalAlignment = VerticalAlignment.Center, + MinWidth = 60, Visibility = Visibility.Collapsed, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = centred ? HorizontalAlignment.Center : HorizontalAlignment.Left, FontFamily = face.FontFamily, FontWeight = face.Weight, FontSize = size, Padding = new Thickness(4, 0, 4, 1), Margin = new Thickness(0), @@ -743,6 +743,7 @@ FrameworkElement HomeNameTag(Typeface face, double size, Color color, bool centr Background = Ds.Brush(pal.Control), BorderBrush = Ds.Brush(Ds.WithAlpha(pal.Accent, 0.85)), BorderThickness = new Thickness(0, 0, 0, 1.5), Template = HomeFieldTemplate() }; + MascotName.Guard(box); slot.Children.Add(box); System.Windows.Automation.AutomationProperties.SetName(box, I18n.T("Nombre de la mascota", "Mascot name")); @@ -810,12 +811,7 @@ FrameworkElement HomeNameTag(Typeface face, double size, Color color, bool centr // Saves the new name (empty means Pixel) and lets the mascot say it. void HomeRename(string typed, TextBlock shown) { - System.Text.StringBuilder b = new System.Text.StringBuilder(); - foreach (char c in typed ?? "") if (!char.IsControl(c)) b.Append(c); - string v = b.ToString().Trim(); - if (v.Length > 16) v = v.Substring(0, 16); - if (v.Length > 0 && char.IsHighSurrogate(v[v.Length - 1])) v = v.Substring(0, v.Length - 1); // never half an emoji - v = v.Trim(); + string v = MascotName.Clean(typed); if (v.Length == 0) v = "Pixel"; if (shown != null) shown.Text = v; if (v == settings.MascotName) return; @@ -1417,7 +1413,7 @@ void BuildHomeScene() host.Margin = new Thickness(left, 0, 0, bottom); stage.Children.Add(host); UseMascot(host); - MacButton play = new MacButton(I18n.Fmt("Jugar con {0}", "Play with {0}", settings.MascotName), ButtonKind.Plain, "play", null, 26); + MacButton play = new MacButton(MascotTalk.PlayWith(settings.MascotName), ButtonKind.Plain, "play", null, 26); play.ToolTip = I18n.Fmt("P\u00EDdele algo a {0}", "Ask {0} something", settings.MascotName); play.Click += delegate { CommandMenu(play); }; play.HorizontalAlignment = HorizontalAlignment.Left; diff --git a/src/Home/MascotAnime.cs b/src/Home/MascotAnime.cs index 8278671..a816ca0 100644 --- a/src/Home/MascotAnime.cs +++ b/src/Home/MascotAnime.cs @@ -61,9 +61,9 @@ public static partial class MascotParts "Nezuko", "Spider-Man", "Batman", "Flash", "Superman", "Iron Man", "Ritter", "Astronaut", "Weiser Magier", "Superheld", "Kero", "Kamina", "Ohnezahn", "Lichtfurie", "Sturmschwinge", "Hakenzahn", "Fleischkloß", - "Stitch", "Kirby", "Grogu", "Eevee", "Charmander", - "Bulbasaur", "Squirtle", "Jigglypuff", "Snorlax", "Gengar", "Mew", - "Psyduck", "Togepi", "Meowth", "Piplup", "Mimikyu", "Lucario", "Dragonite", "Ditto", "Mewtwo", + "Stitch", "Kirby", "Grogu", "Evoli", "Glumanda", + "Bisasam", "Schiggy", "Pummeluff", "Relaxo", "Gengar", "Mew", + "Enton", "Togepi", "Mauzi", "Plinfa", "Mimigma", "Lucario", "Dragoran", "Ditto", "Mewtu", "No-Face", "Calcifer", "Kodama", "Yoshi", "Pac-Man", "Creeper", "Crewmate", "Blinky", "Slime", "Snoopy", "Hello Kitty", "Baby Groot", "Rilakkuma", "Pusheen", "Pochacco", "Pinky", "Inky", "Clyde", "Space Invader", "Goomba", "Boo", "Toad", "Superpilz", "Bob-omb", "Kettenhund", diff --git a/src/Home/MascotArcadePowers.cs b/src/Home/MascotArcadePowers.cs index 4db4534..f6e2c27 100644 --- a/src/Home/MascotArcadePowers.cs +++ b/src/Home/MascotArcadePowers.cs @@ -185,23 +185,23 @@ static string[] OwnLinesDe(int kind) case KindStitch: return new string[] { "Ohana!", "Ohana hei\u00DFt Familie.", "Meega nala kweesta!" }; case KindKirby: return new string[] { "Poyo!", "Hai!", "Ich habe Hunger\u2026 poyo!" }; case KindGrogu: return new string[] { "Mmm\u2026", "Ein blaues Pl\u00E4tzchen?" }; - case KindEevee: return new string[] { "Vee!", "Eevee!" }; - case KindCharmander: return new string[] { "Char!", "Charmander!" }; + case KindEevee: return new string[] { "Voli!", "Evoli!" }; + case KindCharmander: return new string[] { "Glum!", "Glumanda!" }; case KindPikachu: return new string[] { "Pika pika!", "Pikachu!", "Pika!" }; case KindBmo: return new string[] { "Wer will Videospiele spielen?", "Piep bop, ich bin BMO.", "BMO sagt: Schnappschuss!" }; case KindDoraemon: return new string[] { "Daf\u00FCr habe ich ein Gadget!", "Hat jemand Dorayaki?" }; case KindTotoro: return new string[] { "Grooaar!", "Warten wir auf den Bus?" }; - case KindBulbasaur: return new string[] { "Bulba!", "Bulbasaur!" }; - case KindSquirtle: return new string[] { "Squirtle!", "Alle mal chillen!" }; - case KindJigglypuff: return new string[] { "Jiggly\u2026 puuuff \u266A", "Eingeschlafen? Dann mal ich dir ins Gesicht!" }; + case KindBulbasaur: return new string[] { "Bisa!", "Bisasam!" }; + case KindSquirtle: return new string[] { "Schiggy!", "Alle mal chillen!" }; + case KindJigglypuff: return new string[] { "Pummel\u2026 puuuff \u266A", "Eingeschlafen? Dann mal ich dir ins Gesicht!" }; case KindSnorlax: return new string[] { "Zzz\u2026", "Ist es schon Zeit zum Essen?", "Nur noch f\u00FCnf Minuten\u2026" }; case KindGengar: return new string[] { "Gen\u2026 gar\u2026 hihihi", "Ich bin in deinem Schatten." }; case KindMew: return new string[] { "Mew!", "Mew mew \u266A" }; - case KindPsyduck: return new string[] { "Psy\u2026?", "Mein Kopf tut so weh\u2026", "Psyduck?" }; + case KindPsyduck: return new string[] { "Ent\u2026?", "Mein Kopf tut so weh\u2026", "Enton?" }; case KindTogepi: return new string[] { "Toge toge priii!", "Togepi!" }; - case KindMeowth: return new string[] { "Meowth, genau so ist es!", "Gl\u00E4nzt das? Dann geh\u00F6rt es mir!" }; - case KindPiplup: return new string[] { "Piplup!", "Pip pip!" }; - case KindMimikyu: return new string[] { "Ich will doch nur einen Freund\u2026", "Mimiky\u2026" }; + case KindMeowth: return new string[] { "Mauzi, genau so ist es!", "Gl\u00E4nzt das? Dann geh\u00F6rt es mir!" }; + case KindPiplup: return new string[] { "Plinfa!", "Plin plin!" }; + case KindMimikyu: return new string[] { "Ich will doch nur einen Freund\u2026", "Mimigma\u2026" }; case KindLucario: return new string[] { "Ich sp\u00FCre deine Aura.", "Aurasph\u00E4re!" }; case KindDragonite: return new string[] { "Drago!", "Soll ich dich irgendwohin fliegen?" }; case KindDitto: return new string[] { "Ditto!", "Ich kann alles sein, was du willst." }; diff --git a/src/Home/MascotTalk.cs b/src/Home/MascotTalk.cs index f182a8c..9af4410 100644 --- a/src/Home/MascotTalk.cs +++ b/src/Home/MascotTalk.cs @@ -11,6 +11,14 @@ public static class MascotTalk static readonly Random rnd = new Random(); static readonly List recent = new List(); + // The label that opens the mascot's menu: "Jugar con Pixel". Korean puts \uACFC or \uC640 after the name by how the + // name ends; a name that doesn't say (Latin script) gets a wording without any particle. + public static string PlayWith(string name) + { + if (I18n.IsKorean && I18n.JosaOrNull(name, "\uACFC", "\uC640") == null) return name + " \uB180\uC544 \uC8FC\uAE30"; + return I18n.Fmt("Jugar con {0}", "Play with {0}", name); + } + static string Pick(string[] lines) { string line = null; @@ -452,9 +460,9 @@ public static string WellToday(Settings s, int kind) if (I18n.IsKorean) { string whatEn = I18n.Localize(kind == WellKind.Water ? "water reminders" : kind == WellKind.Eyes ? "eye rest reminders" : kind == WellKind.Move ? "movement breaks" : "breathing breaks"); - if (!s.MascotTalks) return string.Format(I18n.Localize("No more {0} today."), whatEn); - return By(s.MascotPersonality, new string[] { string.Format(I18n.Localize("Got it! No more {0} today."), whatEn) }, new string[] { string.Format(I18n.Localize("Alright, no more {0} for today."), whatEn) }, - new string[] { string.Format(I18n.Localize("Fine, you're off the hook for {0} today."), whatEn) }); + if (!s.MascotTalks) return I18n.KoreanParticles(string.Format(I18n.Localize("No more {0} today."), whatEn)); + return By(s.MascotPersonality, new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Got it! No more {0} today."), whatEn)) }, new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Alright, no more {0} for today."), whatEn)) }, + new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Fine, you're off the hook for {0} today."), whatEn)) }); } string what = kind == WellKind.Water ? I18n.T("lo del agua", "water reminders", "Wasser-Erinnerungen") : kind == WellKind.Eyes ? I18n.T("lo de la vista", "eye rest reminders", "Augenpausen") diff --git a/src/Home/Wellness.cs b/src/Home/Wellness.cs index d2dade6..e96f56e 100644 --- a/src/Home/Wellness.cs +++ b/src/Home/Wellness.cs @@ -15,7 +15,15 @@ public static class WellKind public static readonly string[] Glyphs = { "drop", "eye", "walk", "wind" }; // Choices for each interval, in minutes (0: off). public static readonly int[] Minutes = { 0, 20, 30, 45, 60, 90, 120 }; - public static string[] MinuteNames { get { return new string[] { I18n.T("No", "Off"), "20 min", "30 min", "45 min", "1 h", "1 h 30", "2 h" }; } } + public static string[] MinuteNames + { + get + { + // Korean says its own units ("20\uBD84", "1\uC2DC\uAC04 30\uBD84"), as everywhere else a duration is shown. + if (I18n.IsKorean) return new string[] { I18n.T("No", "Off"), FocusClock.Minutes(20), FocusClock.Minutes(30), FocusClock.Minutes(45), FocusClock.Minutes(60), FocusClock.Minutes(90), FocusClock.Minutes(120) }; + return new string[] { I18n.T("No", "Off"), "20 min", "30 min", "45 min", "1 h", "1 h 30", "2 h" }; + } + } public static int IndexOf(int minutes) { diff --git a/src/I18n.German.App.cs b/src/I18n.German.App.cs index f893d8b..ceee680 100644 --- a/src/I18n.German.App.cs +++ b/src/I18n.German.App.cs @@ -283,7 +283,7 @@ static void RegisterGermanApp(Action reg) reg("You can retry or open on GitHub.", "Puedes reintentarlo o abrirlo en GitHub.", "Du kannst es erneut versuchen oder auf GitHub \u00F6ffnen."); reg("Tell us what happened", "Cu\u00E9ntanos qu\u00E9 pasa", "Erz\u00E4hl uns, was passiert ist"); reg("Type a title and {0}.", "Escribe un t\u00EDtulo y {0}.", "Schreib einen Titel und {0}."); - reg("Title needs {0} more.", "El t\u00EDtulo necesita {0} m\u00E1s.", "Dem Titel fehlen noch {0}."); + reg("Title needs {0} more.", "El t\u00EDtulo necesita {0} m\u00E1s.", "Der Titel braucht noch {0}."); reg("{0} needs {1} more.", "{0} necesita {1} m\u00E1s.", "{0} braucht noch {1}."); reg("minimum {0} characters", "m\u00EDnimo {0} letras", "mindestens {0} Zeichen"); reg("1 letter", "1 letra", "1 Buchstabe"); @@ -313,13 +313,13 @@ static void RegisterGermanApp(Action reg) reg("Mark as pending", "Marcar como pendiente", "Als offen markieren"); reg("Not available", "No disponible", "Nicht verf\u00FCgbar"); reg("Could not capture", "No se pudo capturar", "Es konnte nicht aufgenommen werden"); - reg("Could not {0} ({1}).", "No se pudo {0} ({1}).", "{0} fehlgeschlagen ({1})."); - reg("Could not {0}. ", "No se pudo {0}. ", "{0} schlug fehl. "); - reg("Could not {0}. Will try again later.", "No se pudo {0}. Se volver\u00E1 a intentar m\u00E1s tarde.", "{0} war nicht m\u00F6glich. Es wird sp\u00E4ter erneut versucht."); - reg("Could not {0} (error {1}).", "No se pudo {0} (error {1}).", "{0} fehlgeschlagen (Fehler {1})."); - reg("The network proxy does not let Stackshot {0}.", "El proxy de la red no deja {0}.", "Der Netzwerk-Proxy l\u00E4sst Stackshot {0} nicht zu."); - reg("download the update", "descargar la actualizaci\u00F3n", "das Herunterladen des Updates"); - reg("check GitHub", "consultar GitHub", "das \u00DCberpr\u00FCfen von GitHub"); + reg("Could not {0} ({1}).", "No se pudo {0} ({1}).", "Beim {0} ist ein Fehler aufgetreten ({1})."); + reg("Could not {0}. ", "No se pudo {0}. ", "Beim {0} ist ein Fehler aufgetreten. "); + reg("Could not {0}. Will try again later.", "No se pudo {0}. Se volver\u00E1 a intentar m\u00E1s tarde.", "Beim {0} ist ein Fehler aufgetreten. Es wird sp\u00E4ter erneut versucht."); + reg("Could not {0} (error {1}).", "No se pudo {0} (error {1}).", "Beim {0} ist ein Fehler aufgetreten (Fehler {1})."); + reg("The network proxy does not let Stackshot {0}.", "El proxy de la red no deja {0}.", "Der Netzwerk-Proxy blockiert Stackshot beim {0}."); + reg("download the update", "descargar la actualizaci\u00F3n", "Herunterladen des Updates"); + reg("check GitHub", "consultar GitHub", "Abfragen von GitHub"); reg("Failed to open the file. Try again; if it recurs, the Stackshot log has the details.", "Ha fallado al abrir el archivo. Vuelve a intentarlo; si se repite, el registro de Stackshot tiene los detalles.", "Die Datei lie\u00DF sich nicht \u00F6ffnen. Versuch es erneut; wenn es wieder passiert, stehen die Details im Stackshot-Protokoll."); diff --git a/src/I18n.German.Editor.cs b/src/I18n.German.Editor.cs index fe2f9fb..b5e7fa7 100644 --- a/src/I18n.German.Editor.cs +++ b/src/I18n.German.Editor.cs @@ -76,7 +76,7 @@ static void RegisterGermanEditor(Action reg) reg("Move left", null, "Nach links verschieben"); reg("Move right", null, "Nach rechts verschieben"); reg("Remove this video", null, "Dieses Video entfernen"); - reg("Split", null, "Teilen"); + reg("Split", null, "Aufteilen"); reg("Remove piece", null, "Abschnitt entfernen"); reg("+ Video", null, "+ Video"); reg("Playback error: ", null, "Wiedergabefehler: "); diff --git a/src/I18n.German.MascotCast.cs b/src/I18n.German.MascotCast.cs index 7e57167..077a676 100644 --- a/src/I18n.German.MascotCast.cs +++ b/src/I18n.German.MascotCast.cs @@ -69,9 +69,9 @@ static void RegisterGermanMascotCast(Action reg) reg("A little burst of flame, and the tail burns brighter", "Una peque\u00F1a llamarada, y la cola arde m\u00E1s", "Ein kleiner Feuersto\u00DF, und der Schwanz brennt heller"); reg("Ohana!", "\u00A1Ohana!", "Ohana!"); reg("Poyo!", "\u00A1Poyo!", "Poyo!"); - reg("Eevee!", "\u00A1Eevee!", "Eevee!"); + reg("Eevee!", "\u00A1Eevee!", "Evoli!"); reg("Pika pika!", "\u00A1Pika pika!", "Pika pika!"); - reg("Char!", "\u00A1Char!", "Char!"); + reg("Char!", "\u00A1Char!", "Glum!"); // Rhythm: what the mascot says at the coffee, before bed and on Friday afternoon. reg("A little coffee to get going.", "Un cafecito para empezar.", "Erst mal ein kleiner Kaffee."); diff --git a/src/I18n.Korean.Capture.cs b/src/I18n.Korean.Capture.cs index ffb7c48..7e304e0 100644 --- a/src/I18n.Korean.Capture.cs +++ b/src/I18n.Korean.Capture.cs @@ -23,7 +23,7 @@ static void RegisterKoreanCapture(Dictionary map) map["This version of FFmpeg does not include the lossless encoder (libx264rgb), required for Cinema quality.\n\nUpdate it from Stackshot settings or choose another quality."] = "\uC774 FFmpeg \uBC84\uC804\uC5D0\uB294 \uC2DC\uB124\uB9C8 \uD654\uC9C8\uC5D0 \uD544\uC694\uD55C \uBB34\uC190\uC2E4 \uC778\uCF54\uB354(libx264rgb)\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.\n\nStackshot \uC124\uC815\uC5D0\uC11C FFmpeg\uB97C \uC5C5\uB370\uC774\uD2B8\uD558\uAC70\uB098 \uB2E4\uB978 \uD654\uC9C8\uC744 \uC120\uD0DD\uD558\uC138\uC694."; map["Not enough disk space for lossless recording: {0} GB left, need at least {1} GB (a minute takes from several MBs up to multiple GBs depending on motion)."] = "\uBB34\uC190\uC2E4 \uB179\uD654\uB97C \uC704\uD55C \uB514\uC2A4\uD06C \uACF5\uAC04\uC774 \uBD80\uC871\uD569\uB2C8\uB2E4. \uB0A8\uC740 \uACF5\uAC04\uC740 {0}GB\uC774\uBA70 \uCD5C\uC18C {1}GB\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uC6C0\uC9C1\uC784\uC5D0 \uB530\uB77C 1\uBD84 \uB179\uD654\uC5D0 \uC218 MB\uC5D0\uC11C \uC218 GB\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4."; map["The area of {0} \u00D7 {1} is too large to encode losslessly at 60 fps on most computers.\n\nYes: record at 30 fps, lossless.\nNo: try at 60 fps (if the PC cannot keep up, recording stops and saved portion is kept).\nCancel: do not record."] = "\uB300\uBD80\uBD84\uC758 PC\uC5D0\uC11C {0} \u00D7 {1} \uC601\uC5ED\uC744 60 fps\uB85C \uBB34\uC190\uC2E4 \uB179\uD654\uD558\uAE30\uB294 \uC5B4\uB835\uC2B5\uB2C8\uB2E4.\n\n\uC608: 30 fps\uB85C \uBB34\uC190\uC2E4 \uB179\uD654\uD569\uB2C8\uB2E4.\n\uC544\uB2C8\uC694: 60 fps\uB85C \uC2DC\uB3C4\uD569\uB2C8\uB2E4. PC\uAC00 \uC18D\uB3C4\uB97C \uB530\uB77C\uAC00\uC9C0 \uBABB\uD558\uBA74 \uB179\uD654\uB97C \uBA48\uCD94\uACE0 \uADF8\uB54C\uAE4C\uC9C0\uC758 \uC601\uC0C1\uC744 \uC800\uC7A5\uD569\uB2C8\uB2E4.\n\uCDE8\uC18C: \uB179\uD654\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."; - map["FFmpeg exited with code {0}."] = "FFmpeg\uAC00 \uC885\uB8CC \uCF54\uB4DC {0}\uC744 \uBC18\uD658\uD588\uC2B5\uB2C8\uB2E4."; + map["FFmpeg exited with code {0}."] = "FFmpeg\uAC00 \uC885\uB8CC \uCF54\uB4DC {0}\uC744(\uB97C) \uBC18\uD658\uD588\uC2B5\uB2C8\uB2E4."; map["FFmpeg did not create the file."] = "FFmpeg\uAC00 \uD30C\uC77C\uC744 \uB9CC\uB4E4\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4."; map["Check"] = "\uAC80\uC99D"; map["Cancelled before finishing."] = "\uC644\uB8CC \uC804\uC5D0 \uCDE8\uC18C\uD588\uC2B5\uB2C8\uB2E4."; @@ -72,7 +72,7 @@ static void RegisterKoreanCapture(Dictionary map) // FfmpegSetup map["Record video and GIF"] = "\uB3D9\uC601\uC0C1 \uBC0F GIF \uB179\uD654"; - map["To record and play video, Stackshot uses FFmpeg {0}, a free open-source program under its own license (GPL). It is downloaded once (about 110 MB) "] = "Stackshot\uC740 \uB3D9\uC601\uC0C1\uC744 \uB179\uD654\uD558\uACE0 \uC7AC\uC0DD\uD560 \uB54C GPL\uB85C \uBC30\uD3EC\uB418\uB294 \uBB34\uB8CC \uC624\uD508 \uC18C\uC2A4 \uD504\uB85C\uADF8\uB7A8 FFmpeg {0}\uC744 \uC0AC\uC6A9\uD569\uB2C8\uB2E4. \uCD5C\uCD08 \uD55C \uBC88 GitHub\uC5D0\uC11C \uC57D 110MB\uB97C \uB0B4\uB824\uBC1B\uC544 "; + map["To record and play video, Stackshot uses FFmpeg {0}, a free open-source program under its own license (GPL). It is downloaded once (about 110 MB) "] = "Stackshot\uC740 \uB3D9\uC601\uC0C1\uC744 \uB179\uD654\uD558\uACE0 \uC7AC\uC0DD\uD560 \uB54C GPL\uB85C \uBC30\uD3EC\uB418\uB294 \uBB34\uB8CC \uC624\uD508 \uC18C\uC2A4 \uD504\uB85C\uADF8\uB7A8 FFmpeg {0}\uC744(\uB97C) \uC0AC\uC6A9\uD569\uB2C8\uB2E4. \uCD5C\uCD08 \uD55C \uBC88 GitHub\uC5D0\uC11C \uC57D 110MB\uB97C \uB0B4\uB824\uBC1B\uC544 "; map["from GitHub, verified to be the original, and saved only for your user account."] = "\uC6D0\uBCF8\uC778\uC9C0 \uAC80\uC99D\uD55C \uB4A4 \uD604\uC7AC \uC0AC\uC6A9\uC790 \uACC4\uC815\uC5D0\uB9CC \uC800\uC7A5\uD569\uB2C8\uB2E4."; map["Download"] = "\uB2E4\uC6B4\uB85C\uB4DC"; map["I already have it\u2026"] = "\uAE30\uC874 \uD30C\uC77C \uC120\uD0DD\u2026"; diff --git a/src/I18n.Korean.Core.cs b/src/I18n.Korean.Core.cs index c7f0f85..caa931d 100644 --- a/src/I18n.Korean.Core.cs +++ b/src/I18n.Korean.Core.cs @@ -57,7 +57,7 @@ static void RegisterKoreanCore(Dictionary map) // Program.cs map["Could not open {0}.\n\n{1}"] = "{0}\uC744(\uB97C) \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\n{1}"; - map["This machine has Stackshot {0} installed via MSI package.\n\nTo update to {1}, install Stackshot.msi for that version (or ask IT)."] = "\uC774 PC\uC5D0\uB294 MSI\uB85C \uC124\uCE58\uD55C Stackshot {0}\uC774 \uC788\uC2B5\uB2C8\uB2E4.\n\n{1} \uBC84\uC804\uC758 Stackshot.msi\uB97C \uC124\uCE58\uD558\uAC70\uB098 IT \uB2F4\uB2F9\uC790\uC5D0\uAC8C \uBB38\uC758\uD558\uC138\uC694."; + map["This machine has Stackshot {0} installed via MSI package.\n\nTo update to {1}, install Stackshot.msi for that version (or ask IT)."] = "\uC774 PC\uC5D0\uB294 MSI\uB85C \uC124\uCE58\uD55C Stackshot {0}\uC774(\uAC00) \uC788\uC2B5\uB2C8\uB2E4.\n\n{1} \uBC84\uC804\uC758 Stackshot.msi\uB97C \uC124\uCE58\uD558\uAC70\uB098 IT \uB2F4\uB2F9\uC790\uC5D0\uAC8C \uBB38\uC758\uD558\uC138\uC694."; map["Update Stackshot from version {0} to {1}?"] = "Stackshot\uC744 {0}\uC5D0\uC11C {1}(\uC73C)\uB85C \uC5C5\uB370\uC774\uD2B8\uD560\uAE4C\uC694?"; map["Does not seem to be a valid image, or is corrupted."] = "\uC62C\uBC14\uB978 \uC774\uBBF8\uC9C0\uAC00 \uC544\uB2C8\uAC70\uB098 \uD30C\uC77C\uC774 \uC190\uC0C1\uB418\uC5C8\uC2B5\uB2C8\uB2E4."; map["The file cannot be opened in the editor."] = "\uD3B8\uC9D1\uAE30\uC5D0\uC11C \uD30C\uC77C\uC744 \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."; diff --git a/src/I18n.Korean.Editor.cs b/src/I18n.Korean.Editor.cs index 0c5aaa9..e8527f8 100644 --- a/src/I18n.Korean.Editor.cs +++ b/src/I18n.Korean.Editor.cs @@ -217,8 +217,8 @@ static void RegisterKoreanEditor(Dictionary map) map["Could not play the video."] = "\uB3D9\uC601\uC0C1\uC744 \uC7AC\uC0DD\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4."; // PlayerKit - map["100 % (actual size: 1 video pixel = 1 screen pixel)"] = "100%(\uC2E4\uC81C \uD06C\uAE30: \uC601\uC0C1 1\uD53D\uC140 = \uD654\uBA74 1\uD53D\uC140)"; - map[" % (scaled to fill window)"] = "%(\uCC3D \uD06C\uAE30\uC5D0 \uB9DE\uCDA4)"; + map["100 % (actual size: 1 video pixel = 1 screen pixel)"] = "100% (\uC2E4\uC81C \uD06C\uAE30: \uC601\uC0C1 1\uD53D\uC140 = \uD654\uBA74 1\uD53D\uC140)"; + map[" % (scaled to fill window)"] = "% (\uCC3D \uD06C\uAE30\uC5D0 \uB9DE\uCDA4)"; map["window is smaller than video: maximize or press F"] = "\uCC3D\uC774 \uC601\uC0C1\uBCF4\uB2E4 \uC791\uC2B5\uB2C8\uB2E4. \uCD5C\uB300\uD654\uD558\uAC70\uB098 F\uB97C \uB204\uB974\uC138\uC694"; map["video is larger than screen"] = "\uC601\uC0C1\uC774 \uD654\uBA74\uBCF4\uB2E4 \uD07D\uB2C8\uB2E4"; map["File"] = "\uD30C\uC77C"; diff --git a/src/I18n.Korean.HomeDialogue.cs b/src/I18n.Korean.HomeDialogue.cs index 8ce98d3..2d17ed8 100644 --- a/src/I18n.Korean.HomeDialogue.cs +++ b/src/I18n.Korean.HomeDialogue.cs @@ -768,10 +768,10 @@ static void RegisterKoreanHomeDialogue(Dictionary map) map["{0} eye rests today."] = "\uC624\uB298 \uB208\uC744 {0}\uBC88 \uC26C\uC5C8\uC5B4."; map["{0} movement breaks today."] = "\uC624\uB298 {0}\uBC88 \uBAB8\uC744 \uC6C0\uC9C1\uC600\uC5B4."; map["{0} breathing sessions today."] = "\uC624\uB298 \uD638\uD761 \uC6B4\uB3D9\uC744 {0}\uBC88 \uD588\uC5B4."; - map["No more {0} today."] = "\uC624\uB298\uC740 {0}\uC744 \uADF8\uB9CC\uD560\uAC8C."; - map["Got it! No more {0} today."] = "\uC54C\uACA0\uC5B4! \uC624\uB298\uC740 {0}\uC744 \uADF8\uB9CC\uD560\uAC8C."; - map["Alright, no more {0} for today."] = "\uC88B\uC544, \uC624\uB298\uC740 {0}\uC744 \uAEBC \uB458\uAC8C."; - map["Fine, you're off the hook for {0} today."] = "\uC88B\uC544. \uC624\uB298\uC740 {0}\uC744 \uB354 \uC548 \uD574\uB3C4 \uB3FC."; + map["No more {0} today."] = "\uC624\uB298\uC740 {0}\uC744(\uB97C) \uADF8\uB9CC\uD560\uAC8C."; + map["Got it! No more {0} today."] = "\uC54C\uACA0\uC5B4! \uC624\uB298\uC740 {0}\uC744(\uB97C) \uADF8\uB9CC\uD560\uAC8C."; + map["Alright, no more {0} for today."] = "\uC88B\uC544, \uC624\uB298\uC740 {0}\uC744(\uB97C) \uAEBC \uB458\uAC8C."; + map["Fine, you're off the hook for {0} today."] = "\uC88B\uC544. \uC624\uB298\uC740 {0}\uC744(\uB97C) \uB354 \uC548 \uD574\uB3C4 \uB3FC."; map["We are now {0}!"] = "\uC774\uC81C \uC6B0\uB9AC\uB294 \u2018{0}\u2019\uC57C!"; map["Press {0} to capture."] = "{0} \uD0A4\uB97C \uB20C\uB7EC \uCEA1\uCC98\uD558\uC138\uC694."; map["Today: {0} glasses of water, {1} eye rests, {2} movement breaks"] = "\uC624\uB298 \uBB3C {0}\uC794, \uB208 \uC26C\uAE30 {1}\uD68C, \uBAB8 \uC6C0\uC9C1\uC774\uAE30 {2}\uD68C"; diff --git a/src/I18n.Korean.HomeSettings.cs b/src/I18n.Korean.HomeSettings.cs index 52dcbc0..06cbbee 100644 --- a/src/I18n.Korean.HomeSettings.cs +++ b/src/I18n.Korean.HomeSettings.cs @@ -105,7 +105,7 @@ static void RegisterKoreanHomeSettings(Dictionary map) map["Could not check"] = "\uD655\uC778\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4"; map[" Last checked: {0}."] = " \uB9C8\uC9C0\uB9C9 \uD655\uC778: {0}."; map["You're up to date"] = "\uCD5C\uC2E0 \uBC84\uC804\uC785\uB2C8\uB2E4"; - map["Stackshot {0} is the latest version. Checked {1}."] = "Stackshot {0}\uC774 \uCD5C\uC2E0 \uBC84\uC804\uC785\uB2C8\uB2E4. \uD655\uC778 \uC2DC\uAC01: {1}"; + map["Stackshot {0} is the latest version. Checked {1}."] = "Stackshot {0}\uC774(\uAC00) \uCD5C\uC2E0 \uBC84\uC804\uC785\uB2C8\uB2E4. \uD655\uC778 \uC2DC\uAC01: {1}"; map["Check now"] = "\uC9C0\uAE08 \uD655\uC778"; map["You have version {0}. Not checked for updates yet."] = "\uD604\uC7AC \uBC84\uC804\uC740 {0}\uC785\uB2C8\uB2E4. \uC544\uC9C1 \uC5C5\uB370\uC774\uD2B8\uB97C \uD655\uC778\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4."; map["View all release notes"] = "\uBAA8\uB4E0 \uB9B4\uB9AC\uC2A4 \uB178\uD2B8 \uBCF4\uAE30"; @@ -574,7 +574,7 @@ static void RegisterKoreanHomeSettings(Dictionary map) map[" for an area"] = " \uC601\uC5ED \uC120\uD0DD"; map[" to stop"] = " \uC911\uC9C0"; map[" to record"] = " \uB179\uD654"; - map["Play with {0}"] = "{0}\uC640 \uB180\uAE30"; + map["Play with {0}"] = "{0}\uC640(\uACFC) \uB180\uAE30"; map["Ask {0} something"] = "{0}\uC5D0\uAC8C \uBB3C\uC5B4\uBCF4\uAE30"; map["Recent captures"] = "\uCD5C\uADFC \uCEA1\uCC98"; map["View all"] = "\uC804\uCCB4 \uBCF4\uAE30"; diff --git a/src/I18n.Korean.Particle.cs b/src/I18n.Korean.Particle.cs new file mode 100644 index 0000000..b3f1095 --- /dev/null +++ b/src/I18n.Korean.Particle.cs @@ -0,0 +1,62 @@ +// Stackshot - Korean particles: which of the pair follows a name or a number ("\uD558\uB298\uACFC", "\uB098\uBE44\uC640"). +// MIT License - https://github.com/rubenitx/stackshot +using System; +using System.Text.RegularExpressions; + +namespace Stackshot +{ + public static partial class I18n + { + // Whether the last word of the text ends in a consonant when read aloud: true (a Hangul syllable with a final + // consonant, or a number read the Sino-Korean way: 0 1 3 6 7 8), false (no final consonant) or null when it can't + // be told: a Latin or other script name ("Pixel" is read \uD53D\uC140, "Rex" \uB809\uC2A4: spelling doesn't say) and a digit + // glued to a letter ("MP3" reads \uC4F0\uB9AC or \uC0BC). Punctuation after the word doesn't count. + internal static bool? KoreanFinal(string text) + { + if (string.IsNullOrEmpty(text)) return null; + int i = text.Length - 1; + while (i >= 0 && !char.IsLetterOrDigit(text[i])) i--; + if (i < 0) return null; + char c = text[i]; + if (c >= '\uAC00' && c <= '\uD7A3') return (c - '\uAC00') % 28 != 0; + if (c < '0' || c > '9') return null; + int j = i; + while (j >= 0 && (char.IsDigit(text[j]) || text[j] == '.' || text[j] == ',')) j--; + if (j >= 0 && ((text[j] >= 'A' && text[j] <= 'Z') || (text[j] >= 'a' && text[j] <= 'z'))) return null; + return "013678".IndexOf(c) >= 0; + } + + // The particle after the word: whenFinal after a final consonant ("\uACFC", "\uC740", "\uC774", "\uC744"), whenOpen after a vowel + // ("\uC640", "\uB294", "\uAC00", "\uB97C"), and both, "\uACFC(\uC640)", when the word's script doesn't say. + internal static string Josa(string word, string whenFinal, string whenOpen) + { + bool? f = KoreanFinal(word); + return f == null ? whenFinal + "(" + whenOpen + ")" : f.Value ? whenFinal : whenOpen; + } + + // The same particle but only when the word says it; null for a word the pair can't be picked for, so the caller + // can word the sentence without a particle. + internal static string JosaOrNull(string word, string whenFinal, string whenOpen) + { + bool? f = KoreanFinal(word); + return f == null ? null : f.Value ? whenFinal : whenOpen; + } + + static readonly Regex JosaPair = new Regex("(\uC740\\(\uB294\\)|\uB294\\(\uC740\\)|\uC774\\(\uAC00\\)|\uAC00\\(\uC774\\)|\uC744\\(\uB97C\\)|\uB97C\\(\uC744\\)|\uACFC\\(\uC640\\)|\uC640\\(\uACFC\\))", RegexOptions.CultureInvariant); + + // A catalog text writes a particle after a variable as the pair ("{0}\uC744(\uB97C)"): once the variable is filled in, + // the pair becomes the one that fits the word before it, or stays as the pair when that word doesn't say. + internal static string KoreanParticles(string text) + { + if (string.IsNullOrEmpty(text) || text.IndexOf('(') < 0) return text; + return JosaPair.Replace(text, delegate(Match m) + { + bool? f = KoreanFinal(text.Substring(0, m.Index)); + if (f == null) return m.Value; + string v = m.Value; + bool finalFirst = v[0] == '\uC740' || v[0] == '\uC774' || v[0] == '\uC744' || v[0] == '\uACFC'; + return (f.Value == finalFirst ? v[0] : v[2]).ToString(); + }); + } + } +} diff --git a/src/I18n.cs b/src/I18n.cs index 34f0e75..9b3ac3f 100644 --- a/src/I18n.cs +++ b/src/I18n.cs @@ -101,10 +101,19 @@ public static string T(string es, string en, string de) return PreviewText(en) ?? en; } - // Formats a localized string, with the numbers in the interface language's culture. + // A wording of its own for each language that has one, and English for every other, the previews too: a short word + // such as "Open" (a status, not the verb) has no entry a machine translation could pick the right sense from. + internal static string Own(string es, string en, string de, string ko) + { + return IsSpanish ? es : IsGerman ? de : IsKorean ? ko : en; + } + + // Formats a localized string, with the numbers in the interface language's culture. In Korean the particles that + // follow a filled-in name or number ("{0}\uC744(\uB97C)") are settled by how that last word ends. public static string Fmt(string esFmt, string enFmt, params object[] args) { - return string.Format(Culture, T(esFmt, enFmt), args); + string text = string.Format(Culture, T(esFmt, enFmt), args); + return IsKorean ? KoreanParticles(text) : text; } // Shown text back to the English key it translates (the key T starts from): the catalog maps every English key diff --git a/src/ReportWindow.cs b/src/ReportWindow.cs index 358e2b1..75a84ec 100644 --- a/src/ReportWindow.cs +++ b/src/ReportWindow.cs @@ -379,7 +379,7 @@ FrameworkElement ReportRow(ReportHistory.Entry e, Palette pal) string label; Color ink; if (s == null) { label = states == null ? I18n.T("Enviado", "Sent") : I18n.T("No disponible", "Not available"); ink = pal.Label2; } - else if (s.Open) { label = I18n.T("Abierto", "Open"); ink = pal.High ? pal.Label : pal.Accent; } + else if (s.Open) { label = OpenStatus; ink = pal.High ? pal.Label : pal.Accent; } else if (s.Reason == "completed") { label = e.Idea ? I18n.T("Hecho", "Done") : I18n.T("Arreglado", "Fixed"); ink = pal.High ? pal.Label : pal.Green; } else if (s.Reason == "duplicate") { label = I18n.T("Repetido", "Duplicate"); ink = pal.Label2; } else if (s.Reason == "not_planned") { label = I18n.T("Descartado", "Discarded"); ink = pal.Label2; } @@ -596,10 +596,13 @@ string Machine() return machine; } - static string WindowsVersion() + // A report that is still waiting. Not the verb "Abrir" / "Open" / "\u00D6ffnen" / "\uC5F4\uAE30" the catalog gives for the word. + internal static string OpenStatus { get { return I18n.Own("Abierto", "Open", "Offen", "\uC9C4\uD589 \uC911"); } } + + internal static string WindowsVersion() { Version v = Environment.OSVersion.Version; - return v.Major + "." + v.Minor + "." + v.Build + (Environment.Is64BitOperatingSystem ? " (64 bits)" : ""); + return v.Major + "." + v.Minor + "." + v.Build + (Environment.Is64BitOperatingSystem ? I18n.Own(" (64 bits)", " (64-bit)", " (64 Bit)", " (64\uBE44\uD2B8)") : ""); } static string Screens() diff --git a/src/ShotStack.Wellness.cs b/src/ShotStack.Wellness.cs index dc6e39f..db7bc38 100644 --- a/src/ShotStack.Wellness.cs +++ b/src/ShotStack.Wellness.cs @@ -61,7 +61,7 @@ void WellTick() else { int k = kind; - Notify(settings.MascotName + ": " + WellKind.Names[kind].ToLowerInvariant(), text, NoticeKind.Info, I18n.T("Hecho", "Done"), delegate + Notify(WellTitle(settings.MascotName, kind), text, NoticeKind.Info, I18n.T("Hecho", "Done"), delegate { string up; int today = WellDone(k, out up); @@ -70,6 +70,14 @@ void WellTick() } } + // "Pixel: beber agua": the name of the break after the mascot's. Spanish and English write it in lower case after + // the colon; German keeps the capital its nouns have ("Pixel: Wasser trinken"). + internal static string WellTitle(string name, int kind) + { + string what = WellKind.Names[kind]; + return name + ": " + (I18n.IsGerman ? what : what.ToLowerInvariant()); + } + // Not now: Windows asks for quiet (full screen, presenting, quiet time, locked), an area is being picked, a // recording is on, or the microphone or camera is in use (a call). bool WellQuiet() diff --git a/tests/app/AppTestsI18n.cs b/tests/app/AppTestsI18n.cs index 14eaf8f..e063873 100644 --- a/tests/app/AppTestsI18n.cs +++ b/tests/app/AppTestsI18n.cs @@ -85,6 +85,7 @@ public static void Suite() 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); + AppTestsI18nFinal.Suite(T); } finally { diff --git a/tests/app/AppTestsI18nFinal.cs b/tests/app/AppTestsI18nFinal.cs new file mode 100644 index 0000000..1aa9952 --- /dev/null +++ b/tests/app/AppTestsI18nFinal.cs @@ -0,0 +1,507 @@ +// Suite "i18n", the last audit's findings: file names, Korean particles, German grammar and Pokemon names, the report +// status word, wellness texts, the mascot's name in any script, and the news a release carries in German and Korean. +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +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 AppTestsI18nFinal + { + // The tests of this file, under the names the suite lists them by. + public static void Suite(Action T) + { + T("export-suffixes-follow-the-language", ExportSuffixesFollowTheLanguage); + T("korean-particles-follow-the-word", KoreanParticlesFollowTheWord); + T("report-status-open-is-not-the-verb", ReportStatusOpenIsNotTheVerb); + T("wellness-title-keeps-german-nouns", WellnessTitleKeepsGermanNouns); + T("german-title-hint-is-a-sentence", GermanTitleHintIsASentence); + T("german-pokemon-have-german-names", GermanPokemonHaveGermanNames); + T("korean-wellness-intervals", KoreanWellnessIntervals); + T("german-update-errors-are-sentences", GermanUpdateErrorsAreSentences); + T("korean-zoom-text-is-spaced", KoreanZoomTextIsSpaced); + T("player-audio-button-is-localized", PlayerAudioButtonIsLocalized); + T("report-machine-line-bits", ReportMachineLineBits); + T("german-split-is-not-share", GermanSplitIsNotShare); + T("mascot-name-is-clean-wherever-it-comes-from", MascotNameIsCleanWhereverItComesFrom); + T("settings-rows-exempt-their-paths", SettingsRowsExemptTheirPaths); + T("release-notices-read-their-language", ReleaseNoticesReadTheirLanguage); + T("last-audit-screens-as-pictures", Pictures); + } + + static string[] AllLanguages { get { return AppTestsI18nLayout.AllLanguages; } } + + static void Check(bool ok, string what) { if (!ok) throw new InvalidOperationException(what); } + + static void Same(string expected, string actual, string what) + { + if (expected != actual) throw new InvalidOperationException(what + ": expected <" + Show(expected) + ">, got <" + Show(actual) + ">"); + } + + static string Show(string s) { return s == null ? "null" : Regex.Replace(s, "[^\\x20-\\x7e]", m => "\\u" + ((int)m.Value[0]).ToString("X4")); } + + static string Src(string rel) { return File.ReadAllText(Path.Combine(AppTestsI18nCoverage.RepoRoot(), "src", rel), Encoding.UTF8); } + + static void InLanguage(string lang, Action body) + { + I18n.Apply(lang); + try { body(); } + finally { I18n.Apply("es"); } + } + + // Where each export adds a word to the video's name: Spanish keeps its words, German, Korean and English have their + // own, and the preview languages use the English ones. Nothing in the program reads the words back. + public static void ExportSuffixesFollowTheLanguage() + { + Dictionary want = new Dictionary(); + want["es"] = new[] { " (tramo)", " (editado)", " (para compartir)", " (sin validar)" }; + want["en"] = new[] { " (clip)", " (edited)", " (for sharing)", " (unverified)" }; + want["de"] = new[] { " (Ausschnitt)", " (bearbeitet)", " (zum Teilen)", " (ungepr\u00FCft)" }; + want["ko"] = new[] { " (\uAD6C\uAC04)", " (\uD3B8\uC9D1\uB428)", " (\uACF5\uC720\uC6A9)", " (\uBBF8\uAC80\uC99D)" }; + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + string[] w = want.ContainsKey(lang) ? want[lang] : want["en"]; + string[] got = { ExportName.Clip, ExportName.Edited, ExportName.ForSharing, ExportName.Unverified }; + for (int i = 0; i < 4; i++) Same(w[i], got[i], lang + " export word " + i); + if (lang != "es") + foreach (string s in got) + Check(!Regex.IsMatch(s, "tramo|editado|compartir|validar"), lang + " export word is Spanish: " + s); + } + I18n.Apply("es"); + // No call site spells the Spanish words itself. + List bad = new List(); + foreach (string f in Directory.GetFiles(Path.Combine(AppTestsI18nCoverage.RepoRoot(), "src"), "*.cs", SearchOption.AllDirectories)) + { + if (Path.GetFileName(f) == "ExportName.cs") continue; + string[] lines = File.ReadAllLines(f, Encoding.UTF8); + for (int i = 0; i < lines.Length; i++) + if (!lines[i].TrimStart().StartsWith("//", StringComparison.Ordinal) && Regex.IsMatch(lines[i], "\\((tramo|editado|para compartir|sin validar)\\)")) + bad.Add(Path.GetFileName(f) + ":" + (i + 1)); + } + Check(bad.Count == 0, "Spanish export words spelled in code: " + string.Join(", ", bad)); + } + + // A particle after a name or a number follows how that ends. Latin-script names say nothing about the sound. + public static void KoreanParticlesFollowTheWord() + { + InLanguage("ko", delegate + { + string sky = "\uD558\uB298", butterfly = "\uB098\uBE44"; + Same(sky + "\uACFC \uB180\uAE30", I18n.Fmt("", "Play with {0}", sky), "play with a name ending in a consonant"); + Same(butterfly + "\uC640 \uB180\uAE30", I18n.Fmt("", "Play with {0}", butterfly), "play with a name ending in a vowel"); + Same(sky + "\uACFC \uB180\uAE30", MascotTalk.PlayWith(sky), "the menu label, consonant"); + Same(butterfly + "\uC640 \uB180\uAE30", MascotTalk.PlayWith(butterfly), "the menu label, vowel"); + string latin = MascotTalk.PlayWith("Pixel"); + Same("Pixel \uB180\uC544 \uC8FC\uAE30", latin, "a Latin name gets a wording without a particle"); + Check(latin.IndexOf('\uC640') < 0 && latin.IndexOf('\uACFC') < 0, "a particle after Pixel: " + latin); + Same("Pixel\uC744(\uB97C) \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\nx", I18n.Fmt("", "Could not open {0}.\n\n{1}", "Pixel", "x"), "an unknown ending keeps the pair"); + Same(sky + "\uC744 \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\nx", I18n.Fmt("", "Could not open {0}.\n\n{1}", sky, "x"), "pair settled by the name"); + + string latest = "Stackshot {0} is the latest version. Checked {1}."; + Check(I18n.Fmt("", latest, "2.2.3", "x").StartsWith("Stackshot 2.2.3\uC774 \uCD5C\uC2E0", StringComparison.Ordinal), "2.2.3 reads sam: " + I18n.Fmt("", latest, "2.2.3", "x")); + Check(I18n.Fmt("", latest, "2.2.2", "x").StartsWith("Stackshot 2.2.2\uAC00 \uCD5C\uC2E0", StringComparison.Ordinal), "2.2.2 reads i: " + I18n.Fmt("", latest, "2.2.2", "x")); + Check(I18n.Fmt("", "This machine has Stackshot {0} installed via MSI package.\n\nTo update to {1}, install Stackshot.msi for that version (or ask IT).", "2.2.2", "2.3.0").Contains("Stackshot 2.2.2\uAC00 "), "MSI notice with 2.2.2"); + Check(I18n.Fmt("", "FFmpeg exited with code {0}.", 1).Contains("\uCF54\uB4DC 1\uC744 "), "exit code 1"); + Check(I18n.Fmt("", "FFmpeg exited with code {0}.", 2).Contains("\uCF54\uB4DC 2\uB97C "), "exit code 2"); + + Same("\uACFC", I18n.Josa(sky, "\uACFC", "\uC640"), "Josa after a final consonant"); + Same("\uC640", I18n.Josa(butterfly, "\uACFC", "\uC640"), "Josa after a vowel"); + Same("\uACFC(\uC640)", I18n.Josa("Pixel", "\uACFC", "\uC640"), "Josa after a Latin name"); + Same("\uB294", I18n.Josa(butterfly, "\uC740", "\uB294"), "topic particle after a vowel"); + Same("\uC774", I18n.Josa(sky, "\uC774", "\uAC00"), "subject particle after a consonant"); + Same("\uB97C", I18n.Josa("2", "\uC744", "\uB97C"), "a number read \uC774 ends in a vowel"); + Same("\uC744", I18n.Josa("3", "\uC744", "\uB97C"), "a number read \uC0BC ends in a consonant"); + Check(I18n.KoreanFinal("MP3") == null, "a digit glued to letters is not settled"); + Check(I18n.KoreanFinal("2.2.3") == true && I18n.KoreanFinal("2.2.2") == false, "version numbers by their last digit"); + + // No catalog text pins a particle after a variable: the pair is written and settled when it is filled in. + FieldInfo f = typeof(I18n).GetField("KoreanCatalog", BindingFlags.NonPublic | BindingFlags.Static); + object lazy = f.GetValue(null); + Dictionary catalog = (Dictionary)lazy.GetType().GetProperty("Value").GetValue(lazy, null); + List pinned = new List(); + Regex bare = new Regex("\\{\\d\\}[\uC640\uACFC\uC740\uB294\uC774\uAC00\uC744\uB97C](?![\uAC00-\uD7A3(])"); + foreach (KeyValuePair p in catalog) + if (bare.IsMatch(p.Value)) pinned.Add(p.Key + " => " + Show(p.Value)); + foreach (string s in pinned) Console.WriteLine(" pinned particle: " + s); + Check(pinned.Count == 0, pinned.Count + " Korean texts pin a particle after a variable"); + }); + } + + // "Open" as the state of a report is not the verb the menus use. + public static void ReportStatusOpenIsNotTheVerb() + { + Dictionary want = new Dictionary { { "es", "Abierto" }, { "en", "Open" }, { "de", "Offen" }, { "ko", "\uC9C4\uD589 \uC911" } }; + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + Same(want.ContainsKey(lang) ? want[lang] : "Open", ReportWindow.OpenStatus, lang + " report status"); + if (lang == "de" || lang == "ko") Check(ReportWindow.OpenStatus != I18n.Open, lang + ": the status is the verb " + I18n.Open); + } + I18n.Apply("es"); + Check(!Src("ReportWindow.cs").Contains("I18n.T(\"Abierto\", \"Open\")"), "ReportRow still takes the verb's translation"); + } + + // A German title keeps the capitals its nouns have; Spanish and English still write the break in lower case. + public static void WellnessTitleKeepsGermanNouns() + { + InLanguage("de", delegate + { + Same("Pixel: Wasser trinken", ShotStack.WellTitle("Pixel", WellKind.Water), "German water title"); + for (int k = 0; k < WellKind.Count; k++) + { + string t = ShotStack.WellTitle("Pixel", k); + string what = t.Substring("Pixel: ".Length); + Check(what.Length > 0 && char.IsUpper(what[0]), "German title after the name starts lower case: " + t); + } + }); + InLanguage("es", delegate { Same("Pixel: beber agua", ShotStack.WellTitle("Pixel", WellKind.Water), "Spanish title"); }); + InLanguage("en", delegate { Same("Pixel: drink water", ShotStack.WellTitle("Pixel", WellKind.Water), "English title"); }); + InLanguage("ko", delegate { Same("Pixel: " + WellKind.Names[WellKind.Water], ShotStack.WellTitle("Pixel", WellKind.Water), "Korean title"); }); + } + + // The report form's hint on the title: "Der Titel braucht noch 1 Buchstabe." / "... 3 Buchstaben.". + public static void GermanTitleHintIsASentence() + { + MethodInfo letters = typeof(ReportWindow).GetMethod("Letters", BindingFlags.NonPublic | BindingFlags.Static); + InLanguage("de", delegate + { + foreach (int n in new[] { 1, 3 }) + { + string hint = I18n.Fmt("El t\u00EDtulo necesita {0} m\u00E1s.", "Title needs {0} more.", (string)letters.Invoke(null, new object[] { n })); + Same(n == 1 ? "Der Titel braucht noch 1 Buchstabe." : "Der Titel braucht noch 3 Buchstaben.", hint, "German title hint for " + n); + } + }); + InLanguage("es", delegate { Same("El t\u00EDtulo necesita 3 letras m\u00E1s.", I18n.Fmt("El t\u00EDtulo necesita {0} m\u00E1s.", "Title needs {0} more.", (string)letters.Invoke(null, new object[] { 3 })), "Spanish hint unchanged"); }); + } + + static readonly string[] EnglishPokemon = { "Eevee", "Charmander", "Bulbasaur", "Squirtle", "Jigglypuff", "Snorlax", "Psyduck", "Meowth", "Piplup", "Mimikyu", "Dragonite", "Mewtwo" }; + // What their cries are cut from in English: the part of the name a Pokemon says. + static readonly string[] EnglishCries = { "Vee!", "Char!", "Bulba!", "Jiggly", "Psy\u2026", "Pip pip", "Mimiky" }; + + // In German the Pokemon have their German names (Bisasam, Glumanda, Schiggy, ...): neither the costume list nor + // what they say may carry the English ones. + public static void GermanPokemonHaveGermanNames() + { + InLanguage("de", delegate + { + List bad = new List(); + foreach (string n in MascotParts.AnimeNames) + if (EnglishPokemon.Contains(n)) bad.Add("costume " + n); + foreach (string n in new[] { "Evoli", "Glumanda", "Bisasam", "Schiggy", "Pummeluff", "Relaxo", "Enton", "Mauzi", "Plinfa", "Mimigma", "Dragoran" }) + if (!MascotParts.AnimeNames.Contains(n)) bad.Add("no costume " + n); + int[] kinds = { MascotParts.KindEevee, MascotParts.KindCharmander, MascotParts.KindBulbasaur, MascotParts.KindSquirtle, MascotParts.KindJigglypuff, MascotParts.KindSnorlax, + MascotParts.KindPsyduck, MascotParts.KindMeowth, MascotParts.KindPiplup, MascotParts.KindMimikyu, MascotParts.KindDragonite, MascotParts.KindMewtwo, + MascotParts.KindPikachu, MascotParts.KindGengar, MascotParts.KindMew, MascotParts.KindTogepi, MascotParts.KindLucario, MascotParts.KindDitto }; + foreach (int kind in kinds) + { + string[] lines = MascotParts.OwnLines(kind); + if (lines == null) continue; + foreach (string line in lines) + foreach (string name in EnglishPokemon.Concat(EnglishCries)) + if (line.IndexOf(name, StringComparison.Ordinal) >= 0) bad.Add(line + " (" + name + ")"); + } + // The catalog's German cries, which the same lines reach through the English key. + Same("Evoli!", I18n.T("\u00A1Eevee!", "Eevee!"), "German Eevee cry"); + Same("Glum!", I18n.T("\u00A1Char!", "Char!"), "German Charmander cry"); + foreach (string s in bad) Console.WriteLine(" english Pokemon in German: " + s); + Check(bad.Count == 0, bad.Count + " English Pokemon names in German"); + }); + InLanguage("es", delegate { Check(MascotParts.AnimeNames.Contains("Bulbasaur") && MascotParts.AnimeNames.Contains("Eevee"), "Spanish keeps the names it has"); }); + } + + // Wellness reminders in Korean say their units like every other duration. + public static void KoreanWellnessIntervals() + { + InLanguage("ko", delegate + { + string[] names = WellKind.MinuteNames; + string[] want = { null, "20\uBD84", "30\uBD84", "45\uBD84", "1\uC2DC\uAC04", "1\uC2DC\uAC04 30\uBD84", "2\uC2DC\uAC04" }; + Check(names.Length == want.Length, "seven choices"); + for (int i = 1; i < want.Length; i++) Same(want[i], names[i], "Korean interval " + i); + }); + foreach (string lang in new[] { "es", "en", "de", "fr" }) + InLanguage(lang, delegate + { + string[] names = WellKind.MinuteNames; + for (int i = 1; i < 7; i++) Same(new[] { null, "20 min", "30 min", "45 min", "1 h", "1 h 30", "2 h" }[i], names[i], lang + " interval " + i); + }); + } + + // German update failures are sentences with a verb and a capital, in the notice and in Acerca de. + public static void GermanUpdateErrorsAreSentences() + { + MethodInfo why = typeof(Updater).GetMethod("Why", BindingFlags.NonPublic | BindingFlags.Static); + Func run = (ex, download) => (string)why.Invoke(null, new object[] { ex, download }); + InLanguage("de", delegate + { + string download = I18n.T("descargar la actualizaci\u00F3n", "download the update"); + Same("Herunterladen des Updates", download, "German name of the download"); + string[] messages = + { + run(new Exception("x"), true), run(new Exception("x"), false), run(new InvalidDataException("kaputt."), true), run(new InvalidOperationException("x"), false), + I18n.Fmt("El proxy de la red no deja {0}.", "The network proxy does not let Stackshot {0}.", download), + I18n.Fmt("No se pudo {0} (error {1}).", "Could not {0} (error {1}).", download, 404) + }; + Same("Beim Herunterladen des Updates ist ein Fehler aufgetreten. Es wird sp\u00E4ter erneut versucht.", messages[0], "unknown failure"); + Same("Beim Abfragen von GitHub ist ein Fehler aufgetreten. Es wird sp\u00E4ter erneut versucht.", messages[1], "check failure"); + Same("Beim Herunterladen des Updates ist ein Fehler aufgetreten (kaputt).", messages[2], "invalid data"); + Same("Der Netzwerk-Proxy blockiert Stackshot beim Herunterladen des Updates.", messages[4], "proxy"); + Same("Beim Herunterladen des Updates ist ein Fehler aufgetreten (Fehler 404).", messages[5], "http error"); + foreach (string m in messages) Check(char.IsUpper(m[0]), "a German sentence starts in lower case: " + m); + }); + InLanguage("es", delegate { Same("No se pudo descargar la actualizaci\u00F3n. Se volver\u00E1 a intentar m\u00E1s tarde.", run(new Exception("x"), true), "Spanish unchanged"); }); + } + + // "100% (" with a space, as the other languages write it. + public static void KoreanZoomTextIsSpaced() + { + InLanguage("ko", delegate + { + Check(I18n.T("", "100 % (actual size: 1 video pixel = 1 screen pixel)").StartsWith("100% (", StringComparison.Ordinal), "100% ("); + Check(I18n.T("", " % (scaled to fill window)").StartsWith("% (", StringComparison.Ordinal), "% ("); + }); + } + + // The player's audio track button follows the language; "Audio" is the word in Spanish, English and German. + public static void PlayerAudioButtonIsLocalized() + { + foreach (string lang in new[] { "es", "en", "de" }) InLanguage(lang, delegate { Same("Audio", PlayerKit.AudioLabel, lang + " audio button"); }); + InLanguage("ko", delegate { Same("\uC624\uB514\uC624", PlayerKit.AudioLabel, "Korean audio button"); }); + Check(!Regex.IsMatch(Src("Editor\\PlayerWindow.cs"), "Make\\(\"tracks\", null, \"Audio\""), "the player still hard-codes the Audio label"); + } + + // "(64 bits)" in the report's machine line follows the language. + public static void ReportMachineLineBits() + { + if (!Environment.Is64BitOperatingSystem) return; + Dictionary want = new Dictionary { { "es", " (64 bits)" }, { "en", " (64-bit)" }, { "de", " (64 Bit)" }, { "ko", " (64\uBE44\uD2B8)" } }; + foreach (string lang in AllLanguages) + { + I18n.Apply(lang); + string v = ReportWindow.WindowsVersion(); + string w = want.ContainsKey(lang) ? want[lang] : want["en"]; + Check(v.EndsWith(w, StringComparison.Ordinal), lang + " machine line: " + Show(v)); + } + I18n.Apply("es"); + } + + // Split is a verb on a button; "Teilen" also means share. + public static void GermanSplitIsNotShare() + { + InLanguage("de", delegate { Same("Aufteilen", I18n.T("Dividir", "Split"), "German Split"); }); + } + + // A name from the settings file loses control and bidi characters like a typed one, and the 16 units are cut by + // letters: an emoji, a flag or a conjunct is never left in half. + public static void MascotNameIsCleanWhereverItComesFrom() + { + string dir = Path.Combine(Path.GetTempPath(), "stackshot-app-tests", "name-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(dir); + try + { + Func load = delegate(string raw) + { + string ini = Path.Combine(dir, "n.ini"); + File.WriteAllText(ini, "FirstRunDone = 1\nMascotName = " + raw + "\n", new UTF8Encoding(false)); + return Settings.Load(ini).MascotName; + }; + Same("evilx", load("\u202Eevil\u0007\u2066x\u2069"), "settings.ini: bidi and control characters"); + Same("Pixel", load("\u202E\u2069"), "settings.ini: nothing left keeps the default"); + Same("1234567890123456", load("12345678901234567890"), "settings.ini: 16 units"); + MethodInfo typed = typeof(HomeWindow).GetMethod("CleanName", BindingFlags.NonPublic | BindingFlags.Static); + Func type = s => (string)typed.Invoke(null, new object[] { s }); + Same("evilx", type("\u202Aev\u202Eil\u0007\u2066x\u2069"), "typed: bidi characters"); + Same("Pixel", type("\u202E"), "typed: nothing left is Pixel"); + + string family = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66"; + string flags = "\uD83C\uDDEA\uD83C\uDDF8\uD83C\uDDE9\uD83C\uDDEA\uD83C\uDDF0\uD83C\uDDF7\uD83C\uDDEB\uD83C\uDDF7\uD83C\uDDEE\uD83C\uDDF9"; + string thumbs = "\uD83D\uDC4D\uD83C\uDFFD"; + string deva = "\u0928\u092E\u0938\u094D\u0924\u0947 \u0915\u094D\u0937\u0924\u094D\u0930\u093F\u092F \u0926\u0941\u0928\u093F\u092F\u093E"; + string beng = "\u09AC\u09BE\u0982\u09B2\u09BE\u09A6\u09C7\u09B6 \u0995\u09CD\u09B7\u09C1\u09A6\u09CD\u09B0 \u0995\u09A8\u09CD\u09AF\u09BE"; + string hangul = "\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558"; + Same(family, MascotName.Clean(family + family), "two family emoji keep one whole"); + Same(flags.Substring(0, 16), MascotName.Clean(flags), "flags keep four whole"); + Same(thumbs + thumbs + thumbs + thumbs, MascotName.Clean(thumbs + thumbs + thumbs + thumbs + thumbs + thumbs), "skin tones stay with their hand"); + Same(hangul.Substring(0, 16), MascotName.Clean(hangul), "Hangul syllables are one unit each"); + // Whatever the cut, it never ends or continues inside a letter. + foreach (string name in new[] { deva, beng, family + "ab" + family, "a" + family + "bc" + family, "ab" + flags + flags, "x" + thumbs + deva + beng }) + for (int skip = 0; skip < 6; skip++) + { + string input = new string('a', skip) + name; + string cut = MascotName.Clean(input); + string tail = input.Substring(cut.Length).TrimStart(); + Check(cut.Length <= 16, "over 16 units: " + Show(cut)); + Check(input.StartsWith(cut, StringComparison.Ordinal), "not a start of the text: " + Show(input)); + char last = cut.Length > 0 ? cut[cut.Length - 1] : 'a'; + Check(last != '\u200D' && last != '\u094D' && last != '\u09CD' && !char.IsHighSurrogate(last), "ends inside a letter: " + Show(cut)); + if (cut.Length < input.TrimEnd().Length) + { + char next = input[cut.Length]; + UnicodeCategory cat = char.GetUnicodeCategory(next); + Check(next != '\u200D' && !char.IsLowSurrogate(next) && cat != UnicodeCategory.NonSpacingMark && cat != UnicodeCategory.SpacingCombiningMark && cat != UnicodeCategory.EnclosingMark, + "the cut leaves a piece of a letter: " + Show(cut) + " | " + Show(tail)); + } + } + + // The field itself drops what is forbidden as it is typed or pasted. + TextBox box = new TextBox(); + MascotName.Guard(box); + box.Text = "ab\u202Ec\u2067d"; + Same("abcd", box.Text, "typed text loses bidi characters"); + box.Text = family + family; + Same(family, box.Text, "pasted text is cut by letters"); + box.Text = "Mr Pixel "; + Same("Mr Pixel ", box.Text, "a space typed at the end stays while typing"); + } + finally { try { Directory.Delete(dir, true); } catch { } } + } + + // The rows test leaves out texts that are the user's own: a folder in any form Stackshot shows it. + public static void SettingsRowsExemptTheirPaths() + { + foreach (string theirs in new[] { "C:\\Users\\me\\Pictures", "~\\Pictures\\Stackshot", "~\\Videos", "Windows default: Speakers (Model)" }) + Check(AppTestsI18nAudit.IsTheirs(theirs), "not exempt: " + theirs); + foreach (string ours in new[] { "Retention of temporary captures", "Auto-Ausgleich", "Temporary files ~ a day" }) + Check(!AppTestsI18nAudit.IsTheirs(ours), "exempt though it is ours: " + ours); + } + + // Each language reads its own block of the release's news, falling back to the English one and then to the + // changelog lines, and never to the Spanish block. + public static void ReleaseNoticesReadTheirLanguage() + { + Func block = (marker, text) => "
x\n\n\n- **" + text + ".** Body.\n\n\n
\n"; + string lines = "- **Changelog line.** Plain.\n\n"; + string all = lines + block("novedades", "Spanisch") + block("novedades-en", "English") + block("novedades-de", "Deutsch") + block("novedades-ko", "Korean"); + string noGerman = lines + block("novedades", "Spanisch") + block("novedades-en", "English"); + string onlyDe = lines + block("novedades", "Spanisch") + block("novedades-de", "Deutsch"); + string onlyEs = lines + block("novedades", "Spanisch"); + Dictionary want = new Dictionary(); + // es en de ko fr ar + want[all] = new[] { "Spanisch", "English", "Deutsch", "Korean", "English", "English" }; + want[noGerman] = new[] { "Spanisch", "English", "English", "English", "English", "English" }; + want[onlyDe] = new[] { "Spanisch", "Changelog line", "Deutsch", "Changelog line", "Changelog line", "Changelog line" }; + want[onlyEs] = new[] { "Spanisch", "Changelog line", "Changelog line", "Changelog line", "Changelog line", "Changelog line" }; + string[] langs = { "es", "en", "de", "ko", "fr", "ar" }; + foreach (KeyValuePair c in want) + { + Updater.Release r = AppTestsI18nAudit.ParseRelease(c.Key); + for (int i = 0; i < langs.Length; i++) + { + I18n.Apply(langs[i]); + List items = r.Items(); + Check(items.Count == 1 && items[0].Title.Contains(c.Value[i]), langs[i] + ": expected " + c.Value[i] + ", got " + (items.Count == 0 ? "nothing" : items[0].Title)); + } + } + I18n.Apply("es"); + Updater.Release full = AppTestsI18nAudit.ParseRelease(all); + Check(full.News.Count == 1 && full.NewsEn.Count == 1 && full.NewsDe.Count == 1 && full.NewsKo.Count == 1, "the four blocks are read apart"); + // The block markers do not get mixed up: "novedades" is not a prefix of the others in the way the app looks for it. + Check(News.FromRelease(lines + block("novedades-de", "Deutsch")).Count == 0, "a German block read as the Spanish one"); + } + + // ---- Pictures: with STACKSHOT_UI_SHOTS set to a folder, the screens this audit touched are saved there as PNG. + + static void SavePng(BitmapSource b, string name) + { + PngBitmapEncoder e = new PngBitmapEncoder(); + e.Frames.Add(BitmapFrame.Create(b)); + using (FileStream fs = File.Create(Path.Combine(Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"), name))) e.Save(fs); + } + + static void SaveElement(FrameworkElement root, double width, double height, string name) + { + root.Measure(new Size(width, height > 0 ? height : double.PositiveInfinity)); + root.Arrange(new Rect(0, 0, width, height > 0 ? height : root.DesiredSize.Height)); + root.UpdateLayout(); + int w = (int)Math.Ceiling(root.ActualWidth), h = (int)Math.Ceiling(root.ActualHeight); + 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); + SavePng(rtb, name); + } + + public static void Pictures() + { + string dir = Environment.GetEnvironmentVariable("STACKSHOT_UI_SHOTS"); + if (string.IsNullOrEmpty(dir)) return; + Directory.CreateDirectory(dir); + BindingFlags np = BindingFlags.NonPublic | BindingFlags.Instance; + try + { + // The mascot's menu button on the Home page, in Korean, for names that end in a consonant, a vowel and Latin script. + foreach (string[] n in new[] { new[] { "\uD558\uB298", "hanul" }, new[] { "\uB098\uBE44", "nabi" }, new[] { "Pixel", "pixel" } }) + { + I18n.Apply("ko"); + Ds.Apply(1); + Settings st = new Settings(); + st.SaveFolder = Path.Combine(Path.GetTempPath(), "stackshot-app-tests", "t18-shots"); + st.ShowRecent = false; st.ShowIntro = false; st.Profile = 2; st.Appearance = 1; st.MascotOn = true; st.MascotName = n[0]; + HomeWindow hw = new HomeWindow((ShotStack)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(ShotStack)), st); + try { AppTestsI18n.SetPage(hw, "home"); AppTestsI18n.Layout(hw); SaveElement((FrameworkElement)hw.Content, 980, 660, "t18-ko-play-" + n[1] + ".png"); } + finally { hw.Shutdown(); } + } + + // The German wellness notice: the mascot's name, a colon and the break with its capital. + I18n.Apply("de"); + Ds.Apply(1); + Settings ws = new Settings(); + ws.MascotName = "Pixel"; + Notice notice = new Notice(ShotStack.WellTitle("Pixel", WellKind.Water), MascotTalk.Remind(ws, WellKind.Water, 20), NoticeKind.Info); + ToastLook look = ToastLook.For(notice, 1f); + int pad = 30, tw = look.Size.Width + 2 * pad, th = look.Size.Height + 2 * pad; + BitmapSource shadow = ToastLook.Shadow(tw, th, pad, look); + SavePng(Ink.Render(tw, th, delegate(DrawingContext dc) + { + dc.DrawRectangle(new SolidColorBrush(Color.FromRgb(214, 224, 238)), null, new Rect(0, 0, tw, th)); + dc.DrawImage(shadow, new Rect(0, 0, tw, th)); + dc.PushTransform(new TranslateTransform(pad, pad)); + look.Paint(dc, ToastLook.None); + dc.Pop(); + }, null), "t18-de-wellness-notice.png"); + + // The report form with the title hint, and the list of reports with a report that is still open. + foreach (string lang in new[] { "de", "ko" }) + { + I18n.Apply(lang); + Ds.Apply(1); + ReportWindow w = (ReportWindow)typeof(ReportWindow).GetConstructor(np, null, Type.EmptyTypes, null).Invoke(null); + try + { + typeof(ReportWindow).GetField("title", np).SetValue(w, "Ab"); + typeof(ReportWindow).GetMethod("Build", np).Invoke(w, null); + SaveElement((FrameworkElement)w.Content, 540, 0, "t18-" + lang + "-report-form.png"); + + ReportHistory.Add(41, false, "Aufnahme bricht ab"); + ReportHistory.Add(42, true, "Dark mode for the editor"); + ReportHistory.Add(43, false, "Wrong crop on a second screen"); + Dictionary states = new Dictionary(); + states[41] = new ReportHistory.State { Open = true }; + states[42] = new ReportHistory.State { Open = false, Reason = "completed" }; + states[43] = new ReportHistory.State { Open = false, Reason = "duplicate" }; + typeof(ReportWindow).GetField("states", np).SetValue(w, states); + typeof(ReportWindow).GetField("mine", np).SetValue(w, true); + typeof(ReportWindow).GetMethod("Build", np).Invoke(w, null); + SaveElement((FrameworkElement)w.Content, 540, 0, "t18-" + lang + "-my-reports.png"); + } + finally { try { w.Close(); } catch (Exception) { } } + } + } + finally { I18n.Apply("es"); } + } + } +} From 22926c37f34371359a1b2a9ef0272f052f15f054 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 16:15:37 +0100 Subject: [PATCH 2/2] fix(i18n): Settle Korean particles in the template, guard the mascot name on input and fix the last German texts --- src/Home/MascotTalk.cs | 11 +- src/I18n.German.App.cs | 2 +- src/I18n.Korean.HomeSettings.cs | 2 +- src/I18n.Korean.Particle.cs | 61 ++++++---- src/I18n.cs | 7 +- src/MascotName.cs | 85 +++++++++---- src/ReportWindow.cs | 2 +- src/ShotStack.cs | 2 +- tests/app/AppTestsI18nFinal.cs | 206 ++++++++++++++++++++++++++++---- 9 files changed, 300 insertions(+), 78 deletions(-) diff --git a/src/Home/MascotTalk.cs b/src/Home/MascotTalk.cs index 9af4410..3264e35 100644 --- a/src/Home/MascotTalk.cs +++ b/src/Home/MascotTalk.cs @@ -11,11 +11,10 @@ public static class MascotTalk static readonly Random rnd = new Random(); static readonly List recent = new List(); - // The label that opens the mascot's menu: "Jugar con Pixel". Korean puts \uACFC or \uC640 after the name by how the - // name ends; a name that doesn't say (Latin script) gets a wording without any particle. + // The label that opens the mascot's menu: "Jugar con Pixel". Korean says it with \uD558\uACE0, which needs no particle + // chosen by how the name ends, so every name reads the same way, in any script. public static string PlayWith(string name) { - if (I18n.IsKorean && I18n.JosaOrNull(name, "\uACFC", "\uC640") == null) return name + " \uB180\uC544 \uC8FC\uAE30"; return I18n.Fmt("Jugar con {0}", "Play with {0}", name); } @@ -460,9 +459,9 @@ public static string WellToday(Settings s, int kind) if (I18n.IsKorean) { string whatEn = I18n.Localize(kind == WellKind.Water ? "water reminders" : kind == WellKind.Eyes ? "eye rest reminders" : kind == WellKind.Move ? "movement breaks" : "breathing breaks"); - if (!s.MascotTalks) return I18n.KoreanParticles(string.Format(I18n.Localize("No more {0} today."), whatEn)); - return By(s.MascotPersonality, new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Got it! No more {0} today."), whatEn)) }, new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Alright, no more {0} for today."), whatEn)) }, - new string[] { I18n.KoreanParticles(string.Format(I18n.Localize("Fine, you're off the hook for {0} today."), whatEn)) }); + if (!s.MascotTalks) return I18n.KoreanFormat(I18n.Localize("No more {0} today."), whatEn); + return By(s.MascotPersonality, new string[] { I18n.KoreanFormat(I18n.Localize("Got it! No more {0} today."), whatEn) }, new string[] { I18n.KoreanFormat(I18n.Localize("Alright, no more {0} for today."), whatEn) }, + new string[] { I18n.KoreanFormat(I18n.Localize("Fine, you're off the hook for {0} today."), whatEn) }); } string what = kind == WellKind.Water ? I18n.T("lo del agua", "water reminders", "Wasser-Erinnerungen") : kind == WellKind.Eyes ? I18n.T("lo de la vista", "eye rest reminders", "Augenpausen") diff --git a/src/I18n.German.App.cs b/src/I18n.German.App.cs index ceee680..16c26d2 100644 --- a/src/I18n.German.App.cs +++ b/src/I18n.German.App.cs @@ -286,7 +286,7 @@ static void RegisterGermanApp(Action reg) reg("Title needs {0} more.", "El t\u00EDtulo necesita {0} m\u00E1s.", "Der Titel braucht noch {0}."); reg("{0} needs {1} more.", "{0} necesita {1} m\u00E1s.", "{0} braucht noch {1}."); reg("minimum {0} characters", "m\u00EDnimo {0} letras", "mindestens {0} Zeichen"); - reg("1 letter", "1 letra", "1 Buchstabe"); + reg("1 letter", "1 letra", "1 Buchstaben"); reg("{0} letters", "{0} letras", "{0} Buchstaben"); reg("Discard report?", "\u00BFDescartar el reporte?", "Meldung verwerfen?"); reg("Your report is number {0}. Under \u201CMy reports\u201D you will see its progress and replies, right here with no account.", diff --git a/src/I18n.Korean.HomeSettings.cs b/src/I18n.Korean.HomeSettings.cs index 06cbbee..5070bdf 100644 --- a/src/I18n.Korean.HomeSettings.cs +++ b/src/I18n.Korean.HomeSettings.cs @@ -574,7 +574,7 @@ static void RegisterKoreanHomeSettings(Dictionary map) map[" for an area"] = " \uC601\uC5ED \uC120\uD0DD"; map[" to stop"] = " \uC911\uC9C0"; map[" to record"] = " \uB179\uD654"; - map["Play with {0}"] = "{0}\uC640(\uACFC) \uB180\uAE30"; + map["Play with {0}"] = "{0}\uD558\uACE0 \uB180\uAE30"; map["Ask {0} something"] = "{0}\uC5D0\uAC8C \uBB3C\uC5B4\uBCF4\uAE30"; map["Recent captures"] = "\uCD5C\uADFC \uCEA1\uCC98"; map["View all"] = "\uC804\uCCB4 \uBCF4\uAE30"; diff --git a/src/I18n.Korean.Particle.cs b/src/I18n.Korean.Particle.cs index b3f1095..da34660 100644 --- a/src/I18n.Korean.Particle.cs +++ b/src/I18n.Korean.Particle.cs @@ -7,21 +7,25 @@ namespace Stackshot { public static partial class I18n { + // What may follow the word without changing how it is read: spaces, sentence punctuation and closing quotes or + // brackets ("\uD558\uB298!", "\u201C\uB098\uBE44\u201D"). A percent sign, an emoji or any other symbol is not read, so it settles nothing. + const string KoreanIgnorable = ".,!?\u2026:;)]}>\"'~\u201C\u201D\u2018\u2019\u00BB\u203A\u300D\u300F\u3011\uFF09\u3002\u3001"; + // Whether the last word of the text ends in a consonant when read aloud: true (a Hangul syllable with a final // consonant, or a number read the Sino-Korean way: 0 1 3 6 7 8), false (no final consonant) or null when it can't - // be told: a Latin or other script name ("Pixel" is read \uD53D\uC140, "Rex" \uB809\uC2A4: spelling doesn't say) and a digit - // glued to a letter ("MP3" reads \uC4F0\uB9AC or \uC0BC). Punctuation after the word doesn't count. + // be told: a Latin or other script name ("Pixel" is read \uD53D\uC140, "Rex" \uB809\uC2A4: spelling doesn't say), an emoji or a + // symbol (50%), nothing at all, and a digit glued to a letter ("MP3" reads \uC4F0\uB9AC or \uC0BC). internal static bool? KoreanFinal(string text) { if (string.IsNullOrEmpty(text)) return null; int i = text.Length - 1; - while (i >= 0 && !char.IsLetterOrDigit(text[i])) i--; + while (i >= 0 && (char.IsWhiteSpace(text[i]) || KoreanIgnorable.IndexOf(text[i]) >= 0)) i--; if (i < 0) return null; char c = text[i]; if (c >= '\uAC00' && c <= '\uD7A3') return (c - '\uAC00') % 28 != 0; if (c < '0' || c > '9') return null; int j = i; - while (j >= 0 && (char.IsDigit(text[j]) || text[j] == '.' || text[j] == ',')) j--; + while (j >= 0 && ((text[j] >= '0' && text[j] <= '9') || text[j] == '.' || text[j] == ',')) j--; if (j >= 0 && ((text[j] >= 'A' && text[j] <= 'Z') || (text[j] >= 'a' && text[j] <= 'z'))) return null; return "013678".IndexOf(c) >= 0; } @@ -34,29 +38,44 @@ internal static string Josa(string word, string whenFinal, string whenOpen) return f == null ? whenFinal + "(" + whenOpen + ")" : f.Value ? whenFinal : whenOpen; } - // The same particle but only when the word says it; null for a word the pair can't be picked for, so the caller - // can word the sentence without a particle. - internal static string JosaOrNull(string word, string whenFinal, string whenOpen) - { - bool? f = KoreanFinal(word); - return f == null ? null : f.Value ? whenFinal : whenOpen; - } - - static readonly Regex JosaPair = new Regex("(\uC740\\(\uB294\\)|\uB294\\(\uC740\\)|\uC774\\(\uAC00\\)|\uAC00\\(\uC774\\)|\uC744\\(\uB97C\\)|\uB97C\\(\uC744\\)|\uACFC\\(\uC640\\)|\uC640\\(\uACFC\\))", RegexOptions.CultureInvariant); + // A variable of the text with the pair that follows it: the variable (with its format), the closing quotes or + // brackets between them, and the pair. Without a variable before it (a word of the text itself), only the pair. + static readonly Regex JosaSlot = new Regex( + "(?(?[0-9]+)(?:,[-+]?[0-9]+)?(?::[^{}]*)?\\})?(?[\"'\u201D\u2019\u300D\u300F\\)\\]\u3011\uFF09>]*)" + + "(?\uC740\\(\uB294\\)|\uB294\\(\uC740\\)|\uC774\\(\uAC00\\)|\uAC00\\(\uC774\\)|\uC744\\(\uB97C\\)|\uB97C\\(\uC744\\)|\uACFC\\(\uC640\\)|\uC640\\(\uACFC\\))", + RegexOptions.CultureInvariant); - // A catalog text writes a particle after a variable as the pair ("{0}\uC744(\uB97C)"): once the variable is filled in, - // the pair becomes the one that fits the word before it, or stays as the pair when that word doesn't say. - internal static string KoreanParticles(string text) + // A catalog text writes a particle after a variable as the pair ("{0}\uC744(\uB97C)"). Settled here, in the text and + // before it is formatted, from the value the variable is going to hold; the pair stays as it is when that value + // doesn't say how it ends. The values are never read back out of the formatted text, so none of them is edited. + internal static string KoreanTemplate(string template, object[] args) { - if (string.IsNullOrEmpty(text) || text.IndexOf('(') < 0) return text; - return JosaPair.Replace(text, delegate(Match m) + if (string.IsNullOrEmpty(template) || template.IndexOf('(') < 0) return template; + return JosaSlot.Replace(template, delegate(Match m) { - bool? f = KoreanFinal(text.Substring(0, m.Index)); + Group pair = m.Groups["pair"]; + bool? f = null; + if (m.Groups["ph"].Success) + { + int n; + if (args != null && int.TryParse(m.Groups["n"].Value, out n) && n < args.Length && args[n] != null) + { + try { f = KoreanFinal(string.Format(Culture, m.Groups["ph"].Value, args)); } + catch (FormatException) { f = null; } + } + } + else f = KoreanFinal(template.Substring(0, pair.Index)); if (f == null) return m.Value; - string v = m.Value; + string v = pair.Value; bool finalFirst = v[0] == '\uC740' || v[0] == '\uC774' || v[0] == '\uC744' || v[0] == '\uACFC'; - return (f.Value == finalFirst ? v[0] : v[2]).ToString(); + return m.Value.Substring(0, pair.Index - m.Index) + (f.Value == finalFirst ? v[0] : v[2]); }); } + + // Formats a Korean text that is not a catalog key of Fmt's (already localized by the caller) the same way. + internal static string KoreanFormat(string template, params object[] args) + { + return string.Format(Culture, KoreanTemplate(template, args), args); + } } } diff --git a/src/I18n.cs b/src/I18n.cs index 9b3ac3f..c340ea7 100644 --- a/src/I18n.cs +++ b/src/I18n.cs @@ -109,11 +109,12 @@ internal static string Own(string es, string en, string de, string ko) } // Formats a localized string, with the numbers in the interface language's culture. In Korean the particles that - // follow a filled-in name or number ("{0}\uC744(\uB97C)") are settled by how that last word ends. + // follow a variable ("{0}\uC744(\uB97C)") are settled in the text, from the value that fills it, before it is formatted: + // the values themselves go in as they are. public static string Fmt(string esFmt, string enFmt, params object[] args) { - string text = string.Format(Culture, T(esFmt, enFmt), args); - return IsKorean ? KoreanParticles(text) : text; + string text = T(esFmt, enFmt); + return string.Format(Culture, IsKorean ? KoreanTemplate(text, args) : text, args); } // Shown text back to the English key it translates (the key T starts from): the catalog maps every English key diff --git a/src/MascotName.cs b/src/MascotName.cs index 8ef54a9..252b528 100644 --- a/src/MascotName.cs +++ b/src/MascotName.cs @@ -1,10 +1,14 @@ -// Stackshot - The mascot's name, whatever the keyboard, the settings file or a paste brings: no control or bidirectional -// override characters, at most 16 UTF-16 units, and never cut through a letter that is several pieces (an emoji with its -// joiners, a flag, a Devanagari or Bengali conjunct with its vowel signs). +// Stackshot - The mascot's name, whatever the keyboard, the settings file or a paste brings: no control, invisible or +// bidirectional characters, at most 16 UTF-16 units, composed (NFC), and never cut through a letter that is several pieces +// (an emoji with its joiners, a flag, a Devanagari or Bengali conjunct with its vowel signs). // MIT License - https://github.com/rubenitx/stackshot +using System; using System.Collections.Generic; using System.Globalization; using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; namespace Stackshot { @@ -12,49 +16,82 @@ public static class MascotName { public const int MaxUnits = 16; - // What the name may not contain: control characters and the characters that turn the text around (U+202A-U+202E - // embeddings and overrides, U+2066-U+2069 isolates), which would make a name read as if it were another one. + // What the name may not contain: control characters, the characters that turn the text around (U+202A-U+202E + // embeddings and overrides, U+2066-U+2069 isolates, the marks U+200E U+200F U+061C) and the ones that show nothing + // (U+200B zero-width space, U+FEFF), which would make a name read as if it were another one. The joiners that emoji + // and scripts need (U+200D, U+200C) stay. static bool Forbidden(char c) { - return char.IsControl(c) || (c >= '\u202A' && c <= '\u202E') || (c >= '\u2066' && c <= '\u2069'); + return char.IsControl(c) || (c >= '\u202A' && c <= '\u202E') || (c >= '\u2066' && c <= '\u2069') + || c == '\u200B' || c == '\u200E' || c == '\u200F' || c == '\u061C' || c == '\uFEFF'; } - // The typed text without what is forbidden and cut to the limit: still as typed otherwise, spaces included. - public static string Limit(string text) + // The text without what is forbidden, put together (NFC: Hangul typed as separate jamo is one syllable each, and + // counts like it). + static string Strip(string text) { StringBuilder b = new StringBuilder(); foreach (char c in text ?? "") if (!Forbidden(c)) b.Append(c); string v = b.ToString(); - if (v.Length <= MaxUnits) return v; + try { return v.Normalize(NormalizationForm.FormC); } + catch (ArgumentException) { return v; } // a lone surrogate has no normal form: it stays as it is + } + + // The text without what is forbidden and cut to the limit: still as typed otherwise, spaces included. + public static string Limit(string text) + { + return Cut(Strip(text), MaxUnits); + } + + // The start of the text of at most max units, ending between two letters. + static string Cut(string v, int max) + { + if (v.Length <= max) return v; StringBuilder o = new StringBuilder(); foreach (string piece in Pieces(v)) { - if (o.Length + piece.Length > MaxUnits) break; + if (o.Length + piece.Length > max) break; o.Append(piece); } return o.ToString(); } - // A field the name is typed or pasted in: what is forbidden never stays, and the text stops at the limit without - // cutting a letter in half (the box's own MaxLength counts units and would). - public static void Guard(System.Windows.Controls.TextBox box) + // A field the name is typed or pasted in. What is typed is checked as it arrives (PreviewTextInput comes after an + // IME has committed its composition): a letter that does not fit is refused, so the name in the box is never altered + // behind the user's back, wherever the caret is. A paste is cleaned and cut by letters to the room left; a drop is + // refused. The box's own MaxLength would count units and cut a letter in half. + public static void Guard(TextBox box) { - box.TextChanged += delegate + box.PreviewTextInput += delegate(object o, TextCompositionEventArgs e) { - string v = Limit(box.Text); - if (v == box.Text) return; - int caret = box.CaretIndex; - box.Text = v; - box.CaretIndex = System.Math.Min(caret, v.Length); + string typed = Strip(e.Text); + if (typed.Length == 0 || box.Text.Length - box.SelectionLength + typed.Length > MaxUnits) + { + e.Handled = true; + return; + } + if (typed == e.Text) return; + e.Handled = true; + box.SelectedText = typed; + box.CaretIndex = box.SelectionStart + box.SelectionLength; }; + DataObject.AddPastingHandler(box, delegate(object o, DataObjectPastingEventArgs e) + { + e.CancelCommand(); + if (e.IsDragDrop) return; + string text = e.DataObject.GetDataPresent(DataFormats.UnicodeText) ? e.DataObject.GetData(DataFormats.UnicodeText) as string : null; + if (string.IsNullOrEmpty(text)) return; + string fits = Cut(Strip(text), Math.Max(0, MaxUnits - (box.Text.Length - box.SelectionLength))); + if (fits.Length == 0) return; + box.SelectedText = fits; + box.CaretIndex = box.SelectionStart + box.SelectionLength; + }); } // The name to keep: Limit, with no spaces around it ("" when nothing is left; the caller picks the default). public static string Clean(string text) { - StringBuilder b = new StringBuilder(); - foreach (char c in text ?? "") if (!Forbidden(c)) b.Append(c); - return Limit(b.ToString().Trim()).Trim(); + return Limit(Strip(text).Trim()).Trim(); } // The text split in what is read as one letter each. @@ -72,12 +109,14 @@ static List Pieces(string v) } // The framework's rules for what belongs together predate emoji sequences and conjuncts: a piece that follows a - // joiner or a virama, starts with a joiner or is a skin tone, or the second half of a flag, stays with the one before. + // joiner or a virama, starts with a joiner or is a skin tone, a tag character (the letters and the cancel tag that spell a + // subdivision flag after the black flag) or the second half of a flag, stays with the one before. static bool Joins(string before, string next) { char last = before[before.Length - 1]; if (last == '\u200D' || next[0] == '\u200D' || IsVirama(last)) return true; if (next.Length == 2 && next[0] == '\uD83C' && next[1] >= '\uDFFB' && next[1] <= '\uDFFF') return true; + if (next.Length == 2 && next[0] == '\uDB40' && next[1] >= '\uDC20' && next[1] <= '\uDC7F') return true; return before.Length == 2 && IsRegional(before) && next.Length == 2 && IsRegional(next); } diff --git a/src/ReportWindow.cs b/src/ReportWindow.cs index 75a84ec..76f6674 100644 --- a/src/ReportWindow.cs +++ b/src/ReportWindow.cs @@ -602,7 +602,7 @@ string Machine() internal static string WindowsVersion() { Version v = Environment.OSVersion.Version; - return v.Major + "." + v.Minor + "." + v.Build + (Environment.Is64BitOperatingSystem ? I18n.Own(" (64 bits)", " (64-bit)", " (64 Bit)", " (64\uBE44\uD2B8)") : ""); + return v.Major + "." + v.Minor + "." + v.Build + (Environment.Is64BitOperatingSystem ? I18n.Own(" (64 bits)", " (64-bit)", " (64-Bit)", " (64\uBE44\uD2B8)") : ""); } static string Screens() diff --git a/src/ShotStack.cs b/src/ShotStack.cs index a69845d..39698b0 100644 --- a/src/ShotStack.cs +++ b/src/ShotStack.cs @@ -316,7 +316,7 @@ void OpenRequested(string first) if (docs.Count == 0) return; OpenViewerFile(docs[0]); if (docs.Count > 1) - Notify("Stackshot", string.Format(I18n.T("Se abre {0}. {1} {2} (el visor muestra uno cada vez).", "Opening {0}. {1} {2} (the viewer shows one at a time)."), Path.GetFileName(docs[0]), docs.Count - 1, docs.Count == 2 ? I18n.T("archivo m\u00E1s", "more file") : I18n.T("archivos m\u00E1s", "more files"))); + Notify("Stackshot", I18n.Fmt("Se abre {0}. {1} {2} (el visor muestra uno cada vez).", "Opening {0}. {1} {2} (the viewer shows one at a time).", Path.GetFileName(docs[0]), docs.Count - 1, docs.Count == 2 ? I18n.T("archivo m\u00E1s", "more file") : I18n.T("archivos m\u00E1s", "more files"))); } void OpenViewerFile(string path) diff --git a/tests/app/AppTestsI18nFinal.cs b/tests/app/AppTestsI18nFinal.cs index 1aa9952..108705c 100644 --- a/tests/app/AppTestsI18nFinal.cs +++ b/tests/app/AppTestsI18nFinal.cs @@ -10,6 +10,7 @@ using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -32,7 +33,11 @@ public static void Suite(Action T) T("player-audio-button-is-localized", PlayerAudioButtonIsLocalized); T("report-machine-line-bits", ReportMachineLineBits); T("german-split-is-not-share", GermanSplitIsNotShare); + T("korean-particles-never-edit-values", KoreanParticlesNeverEditValues); + T("opening-several-files-notice-uses-fmt", OpeningSeveralFilesNoticeUsesFmt); T("mascot-name-is-clean-wherever-it-comes-from", MascotNameIsCleanWhereverItComesFrom); + T("mascot-name-field-never-alters-typing", MascotNameFieldNeverAltersTyping); + T("mascot-name-cut-edge-cases", MascotNameCutEdgeCases); T("settings-rows-exempt-their-paths", SettingsRowsExemptTheirPaths); T("release-notices-read-their-language", ReleaseNoticesReadTheirLanguage); T("last-audit-screens-as-pictures", Pictures); @@ -97,13 +102,12 @@ public static void KoreanParticlesFollowTheWord() InLanguage("ko", delegate { string sky = "\uD558\uB298", butterfly = "\uB098\uBE44"; - Same(sky + "\uACFC \uB180\uAE30", I18n.Fmt("", "Play with {0}", sky), "play with a name ending in a consonant"); - Same(butterfly + "\uC640 \uB180\uAE30", I18n.Fmt("", "Play with {0}", butterfly), "play with a name ending in a vowel"); - Same(sky + "\uACFC \uB180\uAE30", MascotTalk.PlayWith(sky), "the menu label, consonant"); - Same(butterfly + "\uC640 \uB180\uAE30", MascotTalk.PlayWith(butterfly), "the menu label, vowel"); - string latin = MascotTalk.PlayWith("Pixel"); - Same("Pixel \uB180\uC544 \uC8FC\uAE30", latin, "a Latin name gets a wording without a particle"); - Check(latin.IndexOf('\uC640') < 0 && latin.IndexOf('\uACFC') < 0, "a particle after Pixel: " + latin); + // The mascot's menu label has no particle at all: the same wording for every name, Latin script or not. + foreach (string name in new[] { sky, butterfly, "Pixel", "\uD83D\uDE00", "50%" }) + { + Same(name + "\uD558\uACE0 \uB180\uAE30", I18n.Fmt("", "Play with {0}", name), "play with " + name); + Same(name + "\uD558\uACE0 \uB180\uAE30", MascotTalk.PlayWith(name), "the menu label for " + name); + } Same("Pixel\uC744(\uB97C) \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\nx", I18n.Fmt("", "Could not open {0}.\n\n{1}", "Pixel", "x"), "an unknown ending keeps the pair"); Same(sky + "\uC744 \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\nx", I18n.Fmt("", "Could not open {0}.\n\n{1}", sky, "x"), "pair settled by the name"); @@ -121,7 +125,10 @@ public static void KoreanParticlesFollowTheWord() Same("\uC774", I18n.Josa(sky, "\uC774", "\uAC00"), "subject particle after a consonant"); Same("\uB97C", I18n.Josa("2", "\uC744", "\uB97C"), "a number read \uC774 ends in a vowel"); Same("\uC744", I18n.Josa("3", "\uC744", "\uB97C"), "a number read \uC0BC ends in a consonant"); + Same("\uAC00", I18n.Josa("2", "\uC774", "\uAC00"), "2 is read \uC774, no final consonant"); Check(I18n.KoreanFinal("MP3") == null, "a digit glued to letters is not settled"); + Check(I18n.KoreanFinal("50%") == null && I18n.KoreanFinal("\uD558\uB298\uD83D\uDE00") == null && I18n.KoreanFinal("") == null && I18n.KoreanFinal(null) == null, "%, an emoji and nothing are not settled"); + Check(I18n.KoreanFinal("\uD558\uB298!") == true && I18n.KoreanFinal("\u201C\uB098\uBE44\u201D") == false, "closing punctuation does not count"); Check(I18n.KoreanFinal("2.2.3") == true && I18n.KoreanFinal("2.2.2") == false, "version numbers by their last digit"); // No catalog text pins a particle after a variable: the pair is written and settled when it is filled in. @@ -169,7 +176,7 @@ public static void WellnessTitleKeepsGermanNouns() InLanguage("ko", delegate { Same("Pixel: " + WellKind.Names[WellKind.Water], ShotStack.WellTitle("Pixel", WellKind.Water), "Korean title"); }); } - // The report form's hint on the title: "Der Titel braucht noch 1 Buchstabe." / "... 3 Buchstaben.". + // The report form's hint on the title and on the other field: "braucht noch 1 Buchstaben" (accusative), "... 3 Buchstaben". public static void GermanTitleHintIsASentence() { MethodInfo letters = typeof(ReportWindow).GetMethod("Letters", BindingFlags.NonPublic | BindingFlags.Static); @@ -178,7 +185,9 @@ public static void GermanTitleHintIsASentence() foreach (int n in new[] { 1, 3 }) { string hint = I18n.Fmt("El t\u00EDtulo necesita {0} m\u00E1s.", "Title needs {0} more.", (string)letters.Invoke(null, new object[] { n })); - Same(n == 1 ? "Der Titel braucht noch 1 Buchstabe." : "Der Titel braucht noch 3 Buchstaben.", hint, "German title hint for " + n); + Same(n == 1 ? "Der Titel braucht noch 1 Buchstaben." : "Der Titel braucht noch 3 Buchstaben.", hint, "German title hint for " + n); + string field = I18n.Fmt("{0} necesita {1} m\u00E1s.", "{0} needs {1} more.", "Thema", (string)letters.Invoke(null, new object[] { n })); + Same(n == 1 ? "Thema braucht noch 1 Buchstaben." : "Thema braucht noch 3 Buchstaben.", field, "German field hint for " + n); } }); InLanguage("es", delegate { Same("El t\u00EDtulo necesita 3 letras m\u00E1s.", I18n.Fmt("El t\u00EDtulo necesita {0} m\u00E1s.", "Title needs {0} more.", (string)letters.Invoke(null, new object[] { 3 })), "Spanish hint unchanged"); }); @@ -284,7 +293,7 @@ public static void PlayerAudioButtonIsLocalized() public static void ReportMachineLineBits() { if (!Environment.Is64BitOperatingSystem) return; - Dictionary want = new Dictionary { { "es", " (64 bits)" }, { "en", " (64-bit)" }, { "de", " (64 Bit)" }, { "ko", " (64\uBE44\uD2B8)" } }; + Dictionary want = new Dictionary { { "es", " (64 bits)" }, { "en", " (64-bit)" }, { "de", " (64-Bit)" }, { "ko", " (64\uBE44\uD2B8)" } }; foreach (string lang in AllLanguages) { I18n.Apply(lang); @@ -301,6 +310,55 @@ public static void GermanSplitIsNotShare() InLanguage("de", delegate { Same("Aufteilen", I18n.T("Dividir", "Split"), "German Split"); }); } + // The pair is settled in the catalog text, from the value that is going to fill the variable, before the text is + // formatted: what the user wrote (a file name, a mascot name) goes in untouched. + public static void KoreanParticlesNeverEditValues() + { + InLanguage("ko", delegate + { + string open = "Could not open {0}.\n\n{1}"; + string tail = " \uC5F4 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.\n\n"; + Same("\uAC51\uC740(\uB294).md\uC744(\uB97C)" + tail + "x", I18n.Fmt("", open, "\uAC51\uC740(\uB294).md", "x"), "a file name that holds a pair stays intact"); + Same("\uAC51\uC740(\uB294)\uC744" + tail + "x", I18n.Fmt("", open, "\uAC51\uC740(\uB294)", "x"), "a value ending in a pair stays intact (\uB294 has a final consonant)"); + Same("\uD83D\uDE00\uC744(\uB97C)" + tail + "x", I18n.Fmt("", open, "\uD83D\uDE00", "x"), "an emoji keeps the pair"); + Same("\uD558\uB298\uD83D\uDE00\uC744(\uB97C)" + tail + "x", I18n.Fmt("", open, "\uD558\uB298\uD83D\uDE00", "x"), "the word before an emoji is not read"); + Same("50%\uC744(\uB97C)" + tail + "x", I18n.Fmt("", open, "50%", "x"), "a percentage keeps the pair"); + Same("\uC744(\uB97C)" + tail + "x", I18n.Fmt("", open, "", "x"), "an empty value keeps the pair"); + Same("\uD558\uB298\uC744" + tail + "\uC740(\uB294) \uC774(\uAC00) \uC744(\uB97C) \uACFC(\uC640)", I18n.Fmt("", open, "\uD558\uB298", "\uC740(\uB294) \uC774(\uAC00) \uC744(\uB97C) \uACFC(\uC640)"), "the other values are never touched"); + Same("Stackshot 2.2.2\uAC00 \uCD5C\uC2E0 \uBC84\uC804\uC785\uB2C8\uB2E4. \uD655\uC778 \uC2DC\uAC01: \uC774(\uAC00)", I18n.Fmt("", "Stackshot {0} is the latest version. Checked {1}.", "2.2.2", "\uC774(\uAC00)"), "a later value that is a pair"); + Same("2.2.3\uC774", I18n.Fmt("", "Stackshot {0} is the latest version. Checked {1}.", "2.2.3", "x").Substring("Stackshot ".Length, "2.2.3\uC774".Length), "2.2.3"); + Check(I18n.Fmt("", "FFmpeg exited with code {0}.", 1).Contains("\uCF54\uB4DC 1\uC744 "), "1 read as a number"); + + // The template: a closing quote or bracket between the variable and the pair does not hide the variable. + string attach = "Open attachment \u201C{0}\u201D?"; + Same("\uCCA8\uBD80 \uD30C\uC77C \u2018\uD558\uB298\u2019\uC744 \uC5F4\uAE4C\uC694?", I18n.Fmt("", attach, "\uD558\uB298"), "quotes around the name, consonant"); + Same("\uCCA8\uBD80 \uD30C\uC77C \u2018\uB098\uBE44\u2019\uB97C \uC5F4\uAE4C\uC694?", I18n.Fmt("", attach, "\uB098\uBE44"), "quotes around the name, vowel"); + Same("\uCCA8\uBD80 \uD30C\uC77C \u2018\uD83D\uDE00\u2019\uC744(\uB97C) \uC5F4\uAE4C\uC694?", I18n.Fmt("", attach, "\uD83D\uDE00"), "quotes around an emoji"); + Same("({0})\uC744 \uC5F4\uAE30 {0:N0}\uAC1C", I18n.KoreanTemplate("({0})\uC744(\uB97C) \uC5F4\uAE30 {0:N0}\uAC1C", new object[] { "\uD558\uB298" }), "a bracket between"); + Same("{0:N0}\uC744 \uC5F4\uAE30", I18n.KoreanTemplate("{0:N0}\uC744(\uB97C) \uC5F4\uAE30", new object[] { 1000 }), "a format is read as the text it makes (1,000: a zero)"); + Same("{0}\uC744(\uB97C) \uC5F4\uAE30", I18n.KoreanTemplate("{0}\uC744(\uB97C) \uC5F4\uAE30", new object[] { null }), "a missing value keeps the pair"); + }); + // Spanish, English and German do not go through any of this. + foreach (string lang in new[] { "es", "en", "de" }) + InLanguage(lang, delegate + { + string s = I18n.Fmt("No se pudo abrir {0}.\n\n{1}", "Could not open {0}.\n\n{1}", "\uAC51\uC740(\uB294).md", "\uC744(\uB97C)"); + Check(s.Contains("\uAC51\uC740(\uB294).md") && s.EndsWith("\uC744(\uB97C)", StringComparison.Ordinal), lang + ": a value changed: " + Show(s)); + }); + } + + // The notice that says how many other files were left out of the viewer is a catalog text: formatted by Fmt, so the + // Korean pair after the file name is settled and never shown as it is written. + public static void OpeningSeveralFilesNoticeUsesFmt() + { + Check(!Regex.IsMatch(Src("ShotStack.cs"), "string\\.Format\\(I18n\\.T\\(\"Se abre"), "ShotStack still formats the notice by hand"); + InLanguage("ko", delegate + { + string text = I18n.Fmt("Se abre {0}. {1} {2} (el visor muestra uno cada vez).", "Opening {0}. {1} {2} (the viewer shows one at a time).", "\uD558\uB298", 2, I18n.T("archivos m\u00E1s", "more files")); + Check(text.StartsWith("\uD558\uB298\uC744 \uC5FD\uB2C8\uB2E4.", StringComparison.Ordinal) && text.IndexOf("(\uB97C)", StringComparison.Ordinal) < 0, "Korean notice: " + Show(text)); + }); + } + // A name from the settings file loses control and bidi characters like a typed one, and the 16 units are cut by // letters: an emoji, a flag or a conjunct is never left in half. public static void MascotNameIsCleanWhereverItComesFrom() @@ -352,20 +410,126 @@ public static void MascotNameIsCleanWhereverItComesFrom() "the cut leaves a piece of a letter: " + Show(cut) + " | " + Show(tail)); } } - - // The field itself drops what is forbidden as it is typed or pasted. - TextBox box = new TextBox(); - MascotName.Guard(box); - box.Text = "ab\u202Ec\u2067d"; - Same("abcd", box.Text, "typed text loses bidi characters"); - box.Text = family + family; - Same(family, box.Text, "pasted text is cut by letters"); - box.Text = "Mr Pixel "; - Same("Mr Pixel ", box.Text, "a space typed at the end stays while typing"); } finally { try { Directory.Delete(dir, true); } catch { } } } + static bool TypeInto(TextBox box, string text) + { + TextCompositionEventArgs pre = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(InputManager.Current, box, text)); + pre.RoutedEvent = UIElement.PreviewTextInputEvent; + box.RaiseEvent(pre); + if (pre.Handled) return false; + TextCompositionEventArgs input = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(InputManager.Current, box, text)); + input.RoutedEvent = UIElement.TextInputEvent; + box.RaiseEvent(input); + return true; + } + + // What the clipboard command does: the pasting handlers may change or cancel it, and what is left goes in. + static void PasteInto(TextBox box, string text, bool dragDrop) + { + DataObject data = new DataObject(DataFormats.UnicodeText, text); + DataObjectPastingEventArgs e = new DataObjectPastingEventArgs(data, dragDrop, DataFormats.UnicodeText); + e.RoutedEvent = DataObject.PastingEvent; + box.RaiseEvent(e); + if (!e.CommandCancelled) box.SelectedText = (string)e.DataObject.GetData(DataFormats.UnicodeText); + } + + // The name's field never rewrites what is in it: a full name refuses one more letter instead of dropping another + // one, wherever the caret is; a paste is cleaned and cut by letters, and what was there stays. + public static void MascotNameFieldNeverAltersTyping() + { + string full = "1234567890123456"; + string family = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67"; + TextBox box = new TextBox(); + MascotName.Guard(box); + + box.Text = full; + box.CaretIndex = 3; + Check(!TypeInto(box, "X"), "a full name accepted a letter in the middle"); + Same(full, box.Text, "typing into a full name leaves it as it is"); + Same("3", box.CaretIndex.ToString(), "and the caret stays"); + box.CaretIndex = 16; + Check(!TypeInto(box, "X"), "a full name accepted a letter at the end"); + Same(full, box.Text, "typing at the end of a full name"); + Check(!TypeInto(box, "\uD83D\uDE00"), "a full name accepted an emoji"); + Same(full, box.Text, "an emoji into a full name"); + Check(!TypeInto(box, "\u202E"), "a bidi override was accepted"); + Same(full, box.Text, "a bidi override into a full name"); + + box.Text = "Mr Pixel "; + box.CaretIndex = 9; + Check(TypeInto(box, "X"), "a name with room refused a letter"); + Same("Mr Pixel X", box.Text, "typing with room keeps the spaces"); + box.Text = "ab"; + box.CaretIndex = 1; + Check(TypeInto(box, "X"), "typing in the middle was refused"); + Same("aXb", box.Text, "typing in the middle"); + box.Text = full; + box.SelectAll(); + Check(TypeInto(box, "X"), "typing over the selection was refused"); + Same("X", box.Text, "typing over a selection frees the room"); + box.Text = "ab"; + box.CaretIndex = 2; + Check(!TypeInto(box, "\u202E"), "a bidi override typed into a name was kept"); + Check(!TypeInto(box, "\u200B"), "a zero-width space typed into a name was kept"); + Same("ab", box.Text, "forbidden characters are not typed"); + + // Pasting: cleaned, then cut by letters to what room is left. + box.Text = "abc"; + box.CaretIndex = 3; + PasteInto(box, "\u202E" + "de\u0007\r\nf\u2066", false); + Same("abcdef", box.Text, "a paste loses bidi and control characters"); + box.Text = "abc"; + box.CaretIndex = 3; + PasteInto(box, family + family, false); + Same("abc" + family, box.Text, "a paste is cut by letters, not in the middle of a family"); + box.Text = "abcd"; + box.CaretIndex = 1; + PasteInto(box, "1234567890123456789", false); + Same("a" + "123456789012" + "bcd", box.Text, "a paste in the middle keeps both sides and is cut"); + Check(box.Text.Length == 16, "16 units after the paste"); + box.Text = full; + box.CaretIndex = 4; + PasteInto(box, "zz", false); + Same(full, box.Text, "a paste into a full name changes nothing"); + box.Text = "abc"; + PasteInto(box, "dropped", true); + Same("abc", box.Text, "a drop is refused"); + } + + // The cut at 16 units: decomposed Hangul is put together first, a flag made of tag characters stays whole, and the + // invisible spaces and direction marks that would make two names look alike are removed. + public static void MascotNameCutEdgeCases() + { + // NFD Hangul (three jamo per syllable) counts as the syllables it reads as. + string syllables = "\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44\uD558\uB298\uB098\uBE44"; + string jamo = syllables.Normalize(NormalizationForm.FormD); + Check(jamo.Length > 40, "the test text is decomposed"); + Same(syllables.Substring(0, 16), MascotName.Clean(jamo), "decomposed Hangul is cut by syllables, composed"); + Same("\uD55C\uAE00", MascotName.Clean("\u1112\u1161\u11AB\u1100\u1173\u11AF"), "two decomposed syllables read as two"); + // A flag drawn with tag characters (England) is one letter of 14 units: whole or not at all. + string england = "\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67\uDB40\uDC7F"; + Same(england.Length.ToString(), "14", "the flag is 14 units"); + Same("ab" + england, MascotName.Clean("ab" + england), "a flag that fits stays whole"); + Same("abc", MascotName.Clean("abc" + england), "a flag that does not fit is left out, not cut"); + Same("abc", MascotName.Clean("abc" + england + england), "two flags"); + Same(england, MascotName.Clean(england + england), "one flag of two"); + Same("a" + england + "b", MascotName.Clean("a" + england + "bcd"), "the letters after a whole flag still count"); + // Invisible characters and direction marks are not part of a name. + Same("abcdef", MascotName.Clean("a\u200Bb\uFEFFc\u200Ed\u200Fe\u061Cf"), "zero-width space, BOM, LRM, RLM and ALM"); + Same("Pixel", HomeWindowCleanName("\u200B\uFEFF\u200E\u200F\u061C"), "nothing left is Pixel"); + Same("a\u200Db", MascotName.Clean("a\u200Db"), "the joiner of emoji and scripts stays"); + Same("\u0645\u06CC\u200C\u062E\u0648\u0627\u0647\u0645", MascotName.Clean("\u0645\u06CC\u200C\u062E\u0648\u0627\u0647\u0645"), "the Persian half-space stays"); + } + + static string HomeWindowCleanName(string s) + { + MethodInfo typed = typeof(HomeWindow).GetMethod("CleanName", BindingFlags.NonPublic | BindingFlags.Static); + return (string)typed.Invoke(null, new object[] { s }); + } + // The rows test leaves out texts that are the user's own: a folder in any form Stackshot shows it. public static void SettingsRowsExemptTheirPaths() { @@ -482,7 +646,7 @@ public static void Pictures() ReportWindow w = (ReportWindow)typeof(ReportWindow).GetConstructor(np, null, Type.EmptyTypes, null).Invoke(null); try { - typeof(ReportWindow).GetField("title", np).SetValue(w, "Ab"); + typeof(ReportWindow).GetField("title", np).SetValue(w, "Abc"); typeof(ReportWindow).GetMethod("Build", np).Invoke(w, null); SaveElement((FrameworkElement)w.Content, 540, 0, "t18-" + lang + "-report-form.png");