diff --git a/BabySmash.csproj b/BabySmash.csproj index 9473dd2..ab248c2 100644 --- a/BabySmash.csproj +++ b/BabySmash.csproj @@ -70,6 +70,7 @@ + @@ -260,6 +261,9 @@ Settings.Designer.cs + + Always + Always diff --git a/Controller.cs b/Controller.cs index b506a1e..bfdebfc 100644 --- a/Controller.cs +++ b/Controller.cs @@ -25,7 +25,7 @@ namespace BabySmash using System.IO; using System.Speech.Synthesis; using System.Text; - + using BabySmash.Globalization; using Newtonsoft.Json; public class Controller @@ -399,7 +399,7 @@ public void PlaySound(FigureTemplate template) } else { - SpeakString(GetLocalizedString(Utils.ColorToString(template.Color)) + " " + template.Name); + SpeakString(GetLocalizedString(Utils.ColorToString(template.Color), template.Name) + " " + template.Name); } } } @@ -407,7 +407,7 @@ public void PlaySound(FigureTemplate template) /// /// Returns if value or culture is not found. /// - public static string GetLocalizedString(string key) + public static string GetLocalizedString(string key, string template = null) { CultureInfo keyboardLanguage = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture; string culture = keyboardLanguage.Name; @@ -428,6 +428,11 @@ public static string GetLocalizedString(string key) Dictionary config = JsonConvert.DeserializeObject>(jsonConfig); if (config.ContainsKey(key)) { + if (keyboardLanguage.IsLatvian()) + { + return LvCultureHelper.GenderizeTemplate(config[key].ToString(), template); + } + return config[key].ToString(); } } diff --git a/Globalization/LvCultureHelper.cs b/Globalization/LvCultureHelper.cs new file mode 100644 index 0000000..63ddff3 --- /dev/null +++ b/Globalization/LvCultureHelper.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace BabySmash.Globalization +{ + internal static class LvCultureHelper + { + private static readonly HashSet FeminineShapes = new HashSet(StringComparer.CurrentCultureIgnoreCase) + { + "Trapece", + "Zvaigzne", + "Sirds", + }; + + private static readonly HashSet AlwaysFeminineKeys = new HashSet(StringComparer.CurrentCultureIgnoreCase) + { + "Rozā", + }; + + + public static bool IsLatvian(this CultureInfo cultureInfo) + { + return cultureInfo?.TwoLetterISOLanguageName == "lv"; + } + + internal static string GenderizeTemplate(string key, string template) + { + if (String.IsNullOrEmpty(key)) + { + return string.Empty; + } + + if (AlwaysFeminineKeys.Contains(key)) + { + return key; + } + + if (String.IsNullOrEmpty(template)) + { + return key; + } + + if (FeminineShapes.Contains(template)) + { + return key.Substring(0, key.Length - 1) + "a"; + } + + return key; + } + } +} diff --git a/Resources/Strings/lv-LV.json b/Resources/Strings/lv-LV.json new file mode 100644 index 0000000..4f81a57 --- /dev/null +++ b/Resources/Strings/lv-LV.json @@ -0,0 +1,21 @@ +{ + "Circle": "Aplis", + "Oval": "Ovāls", + "Rectangle": "Taisnstūris", + "Hexagon": "Sešstūris", + "Trapezoid": "Trapece", + "Star": "Zvaigzne", + "Square": "Kvadrāts", + "Triangle": "Trijstūris", + "Heart": "Sirds", + + "Red": "Sarkans", + "Blue": "Zils", + "Yellow": "Dzeltens", + "Green": "Zaļš", + "Purple": "Violets", + "Pink": "Rozā", + "Orange": "Oranžs", + "Tan": "Dzeltenbrūns", + "Gray": "Pelēks" +} \ No newline at end of file