From 8bf767073e133cff2153e2a2f36756b20b634173 Mon Sep 17 00:00:00 2001 From: "Sergey V. Zhdanovskih" Date: Sat, 2 Mar 2024 20:54:14 +0300 Subject: [PATCH] Introduced a workaround for options that depend on the current locale (fix #541) --- projects/GKCore/GKCore/GKUtils.cs | 15 +++++- .../GKCore/GKCore/Options/GlobalOptions.cs | 2 + .../GKCore/GKCore/Options/LocaleOptions.cs | 51 +++++++++++++++++++ projects/GKTests/GKCore/GKUtilsTests.cs | 6 +++ .../plugins/GKStdReports/RecordCardReport.cs | 2 +- 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 projects/GKCore/GKCore/Options/LocaleOptions.cs diff --git a/projects/GKCore/GKCore/GKUtils.cs b/projects/GKCore/GKCore/GKUtils.cs index e8b815883..4daa7db8e 100644 --- a/projects/GKCore/GKCore/GKUtils.cs +++ b/projects/GKCore/GKCore/GKUtils.cs @@ -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); } } } @@ -675,6 +675,17 @@ public static int GetFamilyEventIndex(string sign) return res; } + /// + /// Localized event name. + /// + /// + /// + 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) @@ -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 = ""; } diff --git a/projects/GKCore/GKCore/Options/GlobalOptions.cs b/projects/GKCore/GKCore/Options/GlobalOptions.cs index 475024cef..5367a47a7 100644 --- a/projects/GKCore/GKCore/Options/GlobalOptions.cs +++ b/projects/GKCore/GKCore/Options/GlobalOptions.cs @@ -494,6 +494,8 @@ public void LoadLanguage(int langCode) } InterfaceLang = (ushort)langCode; + + LocaleOptions.Instance.SetLocale((ushort)langCode); } public LangRecord GetLangByCode(int code) diff --git a/projects/GKCore/GKCore/Options/LocaleOptions.cs b/projects/GKCore/GKCore/Options/LocaleOptions.cs new file mode 100644 index 000000000..7bfe4f4fc --- /dev/null +++ b/projects/GKCore/GKCore/Options/LocaleOptions.cs @@ -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 . + */ + +namespace GKCore.Options +{ + /// + /// Temporary class for options that depend on the current locale. + /// + 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); + } + } +} diff --git a/projects/GKTests/GKCore/GKUtilsTests.cs b/projects/GKTests/GKCore/GKUtilsTests.cs index ee732c564..cfdb88dc4 100644 --- a/projects/GKTests/GKCore/GKUtilsTests.cs +++ b/projects/GKTests/GKCore/GKUtilsTests.cs @@ -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() { diff --git a/projects/plugins/GKStdReports/RecordCardReport.cs b/projects/plugins/GKStdReports/RecordCardReport.cs index 952c3e57e..c3c5ed720 100644 --- a/projects/plugins/GKStdReports/RecordCardReport.cs +++ b/projects/plugins/GKStdReports/RecordCardReport.cs @@ -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 = ""; }