0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 09:50:43 -05:00
launcher/project/SPT.Launcher.Base/Models/Launcher/LocalizedLauncherAction.cs

48 lines
1.4 KiB
C#
Raw Permalink Normal View History

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;
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
{
public class LocalizedLauncherAction : NotifyPropertyChangedBase
2023-03-03 19:25:33 +00:00
{
public LauncherAction Action { get; set; }
private string _name;
2023-03-03 19:25:33 +00:00
public string Name
{
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();
}
}
}