2024-05-21 20:15:19 +01:00
|
|
|
|
using SPT.Launcher.Helpers;
|
|
|
|
|
using SPT.Launcher.Models.Launcher;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2024-09-02 07:53:58 +00:00
|
|
|
|
using SPT.Launcher.Utilities;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
namespace SPT.Launcher.Models
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
public class LocalizedLauncherAction : NotifyPropertyChangedBase
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
|
|
|
|
public LauncherAction Action { get; set; }
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _name;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _name;
|
|
|
|
|
set => SetProperty(ref _name, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateLocaleName()
|
|
|
|
|
{
|
|
|
|
|
string value = Action.ToString();
|
|
|
|
|
|
|
|
|
|
//this adds an underscore before capitalized letters, except if it is the first letter in the string. Then it is lower cased.
|
|
|
|
|
//The result should be the name of the localization providers property you want to use.
|
|
|
|
|
//Example: MinimizeAction -> minimize_action
|
|
|
|
|
string localePropertyName = Regex.Replace(value, "(?<!^)[A-Z]", "_$0").ToLower();
|
|
|
|
|
|
|
|
|
|
var locale = LocalizationProvider.Instance.GetType().GetProperty(localePropertyName).GetValue(LocalizationProvider.Instance, null) ?? value;
|
|
|
|
|
|
|
|
|
|
if (locale is string localizedName)
|
|
|
|
|
{
|
|
|
|
|
Name = localizedName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LocalizedLauncherAction(LauncherAction action)
|
|
|
|
|
{
|
|
|
|
|
string value = action.ToString();
|
|
|
|
|
|
|
|
|
|
Action = action;
|
|
|
|
|
Name = value;
|
|
|
|
|
|
|
|
|
|
UpdateLocaleName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|