Start localising

This commit is contained in:
Isaac Marovitz 2023-05-18 18:53:51 -04:00 committed by Isaac Marovitz
parent 4a92d0b482
commit c567f40531
2 changed files with 86 additions and 4 deletions

View file

@ -266,6 +266,33 @@
"ControllerSettingsMotionGyroDeadzone": "Gyro Deadzone:",
"ControllerSettingsSave": "Save",
"ControllerSettingsClose": "Close",
"KeyUnknown": "Unknown",
"KeyShiftLeft": "Shift Left",
"KeyShiftRight": "Shift Right",
"KeyControlLeft": "Control Left",
"KeyControlRight": "Control Right",
"KeyAltLeft": "Alt Left",
"KeyAltRight": "Alt Right",
"KeyOptLeft": "⌥ Left",
"KeyOptRight": "⌥ Right",
"KeyWinLeft": "Windows Left",
"KeyWinRight": "Windows Right",
"KeyCmdLeft": "⌘ Left",
"KeyCmdRight": "⌘ Right",
"KeyMenu": "Menu",
"KeyUp": "Up",
"KeyDown": "Down",
"KeyLeft": "Left",
"KeyRight": "Right",
"KeyEnter": "Enter",
"KeyEscape": "Escape",
"KeySpace": "Space",
"KeyTab": "Tab",
"KeyBackSpace": "Backspace",
"KeyInsert": "Insert",
"KeyDelete": "Delete",
"KeyPageUp": "Page Up",
"KeyPageDown": "Page Down",
"UserProfilesSelectedUserProfile": "Selected User Profile:",
"UserProfilesSaveProfileName": "Save Profile Name",
"UserProfilesChangeProfileImage": "Change Profile Image",

View file

@ -1,7 +1,10 @@
using Avalonia.Data.Converters;
using DynamicData.Kernel;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Configuration.Hid.Controller;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace Ryujinx.Ava.UI.Helpers
@ -9,15 +12,59 @@ namespace Ryujinx.Ava.UI.Helpers
internal class KeyValueConverter : IValueConverter
{
public static KeyValueConverter Instance = new();
internal static readonly Dictionary<Key, LocaleKeys> KeysMap = new()
{
{ Key.Unknown, LocaleKeys.KeyUnknown },
{ Key.ShiftLeft, LocaleKeys.KeyShiftLeft },
{ Key.ShiftRight, LocaleKeys.KeyShiftRight },
{ Key.ControlLeft, LocaleKeys.KeyControlLeft },
{ Key.ControlRight, LocaleKeys.KeyControlRight },
{ Key.AltLeft, OperatingSystem.IsMacOS() ? LocaleKeys.KeyOptLeft : LocaleKeys.KeyAltLeft },
{ Key.AltRight, OperatingSystem.IsMacOS() ? LocaleKeys.KeyOptRight : LocaleKeys.KeyAltRight },
{ Key.WinLeft, OperatingSystem.IsMacOS() ? LocaleKeys.KeyCmdLeft : LocaleKeys.KeyWinLeft },
{ Key.WinRight, OperatingSystem.IsMacOS() ? LocaleKeys.KeyCmdRight : LocaleKeys.KeyWinRight },
{ Key.Up, LocaleKeys.KeyUp },
{ Key.Down, LocaleKeys.KeyDown },
{ Key.Left, LocaleKeys.KeyLeft },
{ Key.Right, LocaleKeys.KeyRight },
{ Key.Enter, LocaleKeys.KeyEnter },
{ Key.Escape, LocaleKeys.KeyEscape },
{ Key.Space, LocaleKeys.KeySpace },
{ Key.Tab, LocaleKeys.KeyTab },
{ Key.BackSpace, LocaleKeys.KeyBackSpace },
{ Key.Insert, LocaleKeys.KeyInsert },
{ Key.Delete, LocaleKeys.KeyDelete },
{ Key.PageUp, LocaleKeys.KeyPageUp },
{ Key.PageDown, LocaleKeys.KeyPageDown },
};
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
string keyString = "";
if (value != null)
{
return null;
if (value is Key key)
{
if (KeysMap.TryGetValue(key, out LocaleKeys localeKey))
{
keyString = LocaleManager.Instance[localeKey];
}
else
{
keyString = key.ToString();
}
}
else if (value is GamepadInputId gamepadInputId)
{
keyString = value.ToString();
}
else if (value is StickInputId stickInputId)
{ keyString = value.ToString();
}
}
return value.ToString();
return keyString;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
@ -27,9 +74,17 @@ namespace Ryujinx.Ava.UI.Helpers
if (value != null)
{
if (targetType == typeof(Key))
{
var optionalKey = KeysMap.FirstOrOptional(x => LocaleManager.Instance[x.Value] == value.ToString());
if (optionalKey.HasValue)
{
key = optionalKey.Value;
}
else
{
key = Enum.Parse<Key>(value.ToString());
}
}
else if (targetType == typeof(GamepadInputId))
{
key = Enum.Parse<GamepadInputId>(value.ToString());