From f8a63cfdeb875532b513f6bcf62bb37777335eb9 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 14 Sep 2022 01:03:05 -0400 Subject: [PATCH] Language and localization stuff moved here from MBS.Framework.UserInterface --- MBS.Framework/Application.cs | 12 +++++++ MBS.Framework/Language.cs | 54 ++++++++++++++++++++++++++++++ MBS.Framework/MBS.Framework.csproj | 1 + 3 files changed, 67 insertions(+) create mode 100644 MBS.Framework/Language.cs diff --git a/MBS.Framework/Application.cs b/MBS.Framework/Application.cs index fce83cb..f7ccad6 100644 --- a/MBS.Framework/Application.cs +++ b/MBS.Framework/Application.cs @@ -419,6 +419,18 @@ namespace MBS.Framework System.Diagnostics.Debug.WriteLine(sb); } + private Language mvarDefaultLanguage = null; + /// + /// The default used to display translatable text in this application. + /// + public Language DefaultLanguage { get { return mvarDefaultLanguage; } set { mvarDefaultLanguage = value; } } + + private Language.LanguageCollection mvarLanguages = new Language.LanguageCollection(); + /// + /// The languages defined for this application. Translations can be added through XML files in the ~/Languages folder. + /// + public Language.LanguageCollection Languages { get { return mvarLanguages; } } + /// /// Gets a value indicating whether this is /// currently in the process of shutting down. diff --git a/MBS.Framework/Language.cs b/MBS.Framework/Language.cs new file mode 100644 index 0000000..c245baa --- /dev/null +++ b/MBS.Framework/Language.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MBS.Framework +{ + public class Language + { + public class LanguageCollection + : System.Collections.ObjectModel.Collection + { + public Language this[string ID] + { + get + { + foreach (Language language in this) + { + if (language.ID == ID) return language; + } + return null; + } + } + } + + private string mvarID = String.Empty; + public string ID { get { return mvarID; } set { mvarID = value; } } + + private string mvarTitle = String.Empty; + public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + + private Dictionary mvarCommandTitles = new Dictionary(); + private Dictionary mvarStringTableEntries = new Dictionary(); + + public string GetCommandTitle(string id, string defaultValue = null) + { + if (mvarCommandTitles.ContainsKey(id)) return mvarCommandTitles[id]; + return defaultValue; + } + public void SetCommandTitle(string id, string value) + { + mvarCommandTitles[id] = value; + } + public string GetStringTableEntry(string id, string defaultValue = null) + { + if (mvarStringTableEntries.ContainsKey(id)) return mvarStringTableEntries[id]; + return defaultValue; + } + public void SetStringTableEntry(string id, string value) + { + mvarStringTableEntries[id] = value; + } + } +} diff --git a/MBS.Framework/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj index e05ea9c..3f47052 100644 --- a/MBS.Framework/MBS.Framework.csproj +++ b/MBS.Framework/MBS.Framework.csproj @@ -134,6 +134,7 @@ +