Language and localization stuff moved here from MBS.Framework.UserInterface

This commit is contained in:
Michael Becker 2022-09-14 01:03:05 -04:00
parent 3fbcb738dd
commit f8a63cfdeb
No known key found for this signature in database
GPG Key ID: DA394832305DA332
3 changed files with 67 additions and 0 deletions

View File

@ -419,6 +419,18 @@ namespace MBS.Framework
System.Diagnostics.Debug.WriteLine(sb);
}
private Language mvarDefaultLanguage = null;
/// <summary>
/// The default <see cref="Language"/> used to display translatable text in this application.
/// </summary>
public Language DefaultLanguage { get { return mvarDefaultLanguage; } set { mvarDefaultLanguage = value; } }
private Language.LanguageCollection mvarLanguages = new Language.LanguageCollection();
/// <summary>
/// The languages defined for this application. Translations can be added through XML files in the ~/Languages folder.
/// </summary>
public Language.LanguageCollection Languages { get { return mvarLanguages; } }
/// <summary>
/// Gets a value indicating whether this <see cref="Application" /> is
/// currently in the process of shutting down.

54
MBS.Framework/Language.cs Normal file
View File

@ -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<Language>
{
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<string, string> mvarCommandTitles = new Dictionary<string, string>();
private Dictionary<string, string> mvarStringTableEntries = new Dictionary<string, string>();
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;
}
}
}

View File

@ -134,6 +134,7 @@
<Compile Include="ObjectExtensions.cs" />
<Compile Include="ConsoleExtensions.cs" />
<Compile Include="MessageSeverity.cs" />
<Compile Include="Language.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Logic\" />