0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 09:30:45 -05:00
launcher/project/SPT.Launcher.Base/Models/Launcher/LocalizedLauncherAction.cs
loyvsc 441fb128fe Implement NotifyPropertyChangedBase, optimization (!66)
- NotifyPropertyChangedBase created and implemented in classes that inherit INotifyPropertyChangedBase
- Some optimization fixes in models (one of this - `Where(predicate).Count() == 0` to `All(invertedPredicate)`

Co-authored-by: Valery Varaksa <varaksav62@gmail.com>
Reviewed-on: SPT/Launcher#66
Co-authored-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
Co-committed-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
2024-09-02 07:53:58 +00:00

48 lines
1.4 KiB
C#

using SPT.Launcher.Helpers;
using SPT.Launcher.Models.Launcher;
using System.ComponentModel;
using System.Text.RegularExpressions;
using SPT.Launcher.Utilities;
namespace SPT.Launcher.Models
{
public class LocalizedLauncherAction : NotifyPropertyChangedBase
{
public LauncherAction Action { get; set; }
private string _name;
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
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();
}
}
}