Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Latvian translation #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BabySmash.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions\ObjectExtensions.cs" />
<Compile Include="Globalization\LvCultureHelper.cs" />
<Compile Include="Shapes\BabySmashShape.cs" />
<Compile Include="WordFinder.cs" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down Expand Up @@ -260,6 +261,9 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<None Include="Resources\Strings\lv-LV.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\Strings\ru-RU.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
11 changes: 8 additions & 3 deletions Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -399,15 +399,15 @@ public void PlaySound(FigureTemplate template)
}
else
{
SpeakString(GetLocalizedString(Utils.ColorToString(template.Color)) + " " + template.Name);
SpeakString(GetLocalizedString(Utils.ColorToString(template.Color), template.Name) + " " + template.Name);
}
}
}

/// <summary>
/// Returns <param name="key"></param> if value or culture is not found.
/// </summary>
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;
Expand All @@ -428,6 +428,11 @@ public static string GetLocalizedString(string key)
Dictionary<string, object> config = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonConfig);
if (config.ContainsKey(key))
{
if (keyboardLanguage.IsLatvian())
{
return LvCultureHelper.GenderizeTemplate(config[key].ToString(), template);
}

return config[key].ToString();
}
}
Expand Down
52 changes: 52 additions & 0 deletions Globalization/LvCultureHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Globalization;

namespace BabySmash.Globalization
{
internal static class LvCultureHelper
{
private static readonly HashSet<string> FeminineShapes = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase)
{
"Trapece",
"Zvaigzne",
"Sirds",
};

private static readonly HashSet<string> AlwaysFeminineKeys = new HashSet<string>(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;
}
}
}
21 changes: 21 additions & 0 deletions Resources/Strings/lv-LV.json
Original file line number Diff line number Diff line change
@@ -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"
}