IW4M-Admin/SharedLibraryCore/Localization/Layout.cs

50 lines
1.1 KiB
C#
Raw Normal View History

2022-01-26 11:32:16 -05:00
using System.Collections.Generic;
using System.Globalization;
2022-01-26 11:32:16 -05:00
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Localization
{
public class Layout
{
private string localizationName;
2022-01-26 11:32:16 -05:00
public Layout(Dictionary<string, string> set)
{
LocalizationIndex = new TranslationLookup
{
Set = set
};
}
public string LocalizationName
{
get => localizationName;
set
{
localizationName = value;
Culture = new CultureInfo(value);
}
}
2022-01-26 11:32:16 -05:00
public TranslationLookup LocalizationIndex { get; set; }
public CultureInfo Culture { get; private set; }
}
public class TranslationLookup : ITranslationLookup
{
public Dictionary<string, string> Set { get; set; }
public string this[string key]
{
get
{
2022-01-26 11:32:16 -05:00
if (!Set.TryGetValue(key, out var value))
{
return key;
}
2022-01-26 11:32:16 -05:00
return value;
}
}
}
2022-01-26 11:32:16 -05:00
}