Skip to content

Commit

Permalink
Introduced a workaround for options that depend on the current locale (
Browse files Browse the repository at this point in the history
…fix #541)
  • Loading branch information
Serg-Norseman committed Mar 2, 2024
1 parent 425ff0c commit 8bf7670
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
15 changes: 13 additions & 2 deletions projects/GKCore/GKCore/GKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static StringList GetLocationLinks(GDMTree tree, GDMLocationRecord locRec
GDMCustomEvent evt = evsRec.Events[j];

if (evt.HasPlace && evt.Place.Location.XRef == locRec.XRef) {
linksList.AddObject(GetRecordName(tree, evsRec, true) + ", " + GetEventName(evt).ToLower(), evsRec);
linksList.AddObject(GetRecordName(tree, evsRec, true) + ", " + GetEventNameLd(evt), evsRec);
}
}
}
Expand Down Expand Up @@ -675,6 +675,17 @@ public static int GetFamilyEventIndex(string sign)
return res;
}

/// <summary>
/// Localized event name.
/// </summary>
/// <param name="evt"></param>
/// <returns></returns>
public static string GetEventNameLd(GDMCustomEvent evt)
{
string evtName = GetEventName(evt);
return LocaleOptions.Instance.AlwaysCapitalizeNouns() ? evtName : evtName.ToLower();
}

public static string GetEventName(GDMCustomEvent evt)
{
if (evt == null)
Expand Down Expand Up @@ -2060,7 +2071,7 @@ private static void ShowLink(GDMTree tree, GDMRecord aSubject, StringList aToLis

string suffix;
if (aTag is GDMCustomEvent) {
suffix = ", " + GetEventName((GDMCustomEvent) aTag).ToLower();
suffix = ", " + GetEventNameLd((GDMCustomEvent) aTag);
} else {
suffix = "";
}
Expand Down
2 changes: 2 additions & 0 deletions projects/GKCore/GKCore/Options/GlobalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ public void LoadLanguage(int langCode)
}

InterfaceLang = (ushort)langCode;

LocaleOptions.Instance.SetLocale((ushort)langCode);
}

public LangRecord GetLangByCode(int code)
Expand Down
51 changes: 51 additions & 0 deletions projects/GKCore/GKCore/Options/LocaleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GKCore.Options
{
/// <summary>
/// Temporary class for options that depend on the current locale.
/// </summary>
public sealed class LocaleOptions
{
private static LocaleOptions fInstance = null;

private ushort fLocale;

public static LocaleOptions Instance
{
get {
if (fInstance == null) fInstance = new LocaleOptions();
return fInstance;
}
}

public void SetLocale(ushort locale)
{
fLocale = locale;
}

public bool AlwaysCapitalizeNouns()
{
// 1031,Deutsch(de),German(en)
return (fLocale == 1031);
}
}
}
6 changes: 6 additions & 0 deletions projects/GKTests/GKCore/GKUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ public void Test_GetEventName()
Assert.Throws(typeof(ArgumentNullException), () => { GKUtils.GetEventName(null); });
}

[Test]
public void Test_GetEventNameLd()
{
Assert.Throws(typeof(ArgumentNullException), () => { GKUtils.GetEventNameLd(null); });
}

[Test]
public void Test_GetEventCause()
{
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/GKStdReports/RecordCardReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ private void ShowLink(GDMRecord aSubject, GDMRecord aRec, GDMTag aTag, GDMPointe

string suffix;
if (aTag is GDMCustomEvent) {
suffix = ", " + GKUtils.GetEventName((GDMCustomEvent)aTag).ToLower();
suffix = ", " + GKUtils.GetEventNameLd((GDMCustomEvent)aTag);
} else {
suffix = "";
}
Expand Down

0 comments on commit 8bf7670

Please sign in to comment.