Use Fluent localization for key names.

This commit is contained in:
Pieter-Jan Briers
2021-05-02 21:44:21 +02:00
parent 2b15831349
commit 6005208285
4 changed files with 78 additions and 81 deletions

View File

@@ -0,0 +1,54 @@
input-key-Escape = Escape
input-key-Control = Control
input-key-Shift = Shift
input-key-Alt = Alt
input-key-Menu = Menu
input-key-F1 = F1
input-key-F2 = F2
input-key-F3 = F3
input-key-F4 = F4
input-key-F5 = F5
input-key-F6 = F6
input-key-F7 = F7
input-key-F8 = F8
input-key-F9 = F9
input-key-F10 = F10
input-key-F11 = F11
input-key-F12 = F12
input-key-F13 = F13
input-key-F14 = F14
input-key-F15 = F15
input-key-Pause = Pause
input-key-Left = Left
input-key-Up = Up
input-key-Down = Down
input-key-Right = Right
input-key-Space = Space
input-key-Return = Return
input-key-NumpadEnter = Num Enter
input-key-BackSpace = Backspace
input-key-Tab = Tab
input-key-PageUp = Page Up
input-key-PageDown = Page Down
input-key-End = End
input-key-Home = Home
input-key-Insert = Insert
input-key-Delete = Delete
input-key-MouseLeft = Mouse Left
input-key-MouseRight = Mouse Right
input-key-MouseMiddle = Mouse Middle
input-key-MouseButton4 = Mouse 4
input-key-MouseButton5 = Mouse 5
input-key-MouseButton6 = Mouse 6
input-key-MouseButton7 = Mouse 7
input-key-MouseButton8 = Mouse 8
input-key-MouseButton9 = Mouse 9
input-key-LSystem-win = Left Win
input-key-RSystem-win = Right Win
input-key-LSystem-mac = Left Cmd
input-key-RSystem-mac = Right Cmd
input-key-LSystem-linux = Left Meta
input-key-RSystem-linux = Right Meta
input-key-unknown = <unknown key>

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using OpenToolkit.GraphicsLibraryFramework;
using Robust.Client.Input;
using Robust.Shared.Localization;
@@ -47,17 +48,18 @@ namespace Robust.Client.Graphics.Clyde
public string KeyGetName(Keyboard.Key key)
{
var name = Keyboard.GetSpecialKeyName(key);
if (_printableKeyNameMap.TryGetValue(key, out var name))
{
var textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
return textInfo.ToTitleCase(name);
}
name = Keyboard.GetSpecialKeyName(key, _loc);
if (name != null)
{
return Loc.GetString(name);
}
if (_printableKeyNameMap.TryGetValue(key, out name))
{
return name;
}
return Loc.GetString("<unknown key>");
}

View File

@@ -4,6 +4,7 @@ using OpenToolkit.GraphicsLibraryFramework;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
namespace Robust.Client.Graphics.Clyde
@@ -14,6 +15,7 @@ namespace Robust.Client.Graphics.Clyde
{
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
private readonly Clyde _clyde;

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Robust.Shared.Localization;
using Robust.Shared.Map;
namespace Robust.Client.Input
{
@@ -172,86 +174,23 @@ namespace Robust.Client.Input
/// Gets a "nice" version of special unprintable keys such as <see cref="Key.Escape"/>.
/// </summary>
/// <returns><see langword="null"/> if there is no nice version of this special key.</returns>
internal static string? GetSpecialKeyName(Key key)
internal static string? GetSpecialKeyName(Key key, ILocalizationManager loc)
{
if (_keyNiceNameMap.TryGetValue(key, out var val))
var locId = $"input-key-{key}";
if (key == Key.LSystem || key == Key.RSystem)
{
return val;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
locId += "-win";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
locId += "-mac";
else
locId += "-linux";
}
return null;
}
if (loc.TryGetString(locId, out var name))
return name;
private static readonly Dictionary<Key, string> _keyNiceNameMap;
static Keyboard()
{
_keyNiceNameMap = new Dictionary<Key, string>
{
{Key.Escape, "Escape"},
{Key.Control, "Control"},
{Key.Shift, "Shift"},
{Key.Alt, "Alt"},
{Key.Menu, "Menu"},
{Key.F1, "F1"},
{Key.F2, "F2"},
{Key.F3, "F3"},
{Key.F4, "F4"},
{Key.F5, "F5"},
{Key.F6, "F6"},
{Key.F7, "F7"},
{Key.F8, "F8"},
{Key.F9, "F9"},
{Key.F10, "F10"},
{Key.F11, "F11"},
{Key.F12, "F12"},
{Key.F13, "F13"},
{Key.F14, "F14"},
{Key.F15, "F15"},
{Key.Pause, "Pause"},
{Key.Left, "Left"},
{Key.Up, "Up"},
{Key.Down, "Down"},
{Key.Right, "Right"},
{Key.Space, "Space"},
{Key.Return, "Return"},
{Key.NumpadEnter, "Num Enter"},
{Key.BackSpace, "Backspace"},
{Key.Tab, "Tab"},
{Key.PageUp, "Page Up"},
{Key.PageDown, "Page Down"},
{Key.End, "End"},
{Key.Home, "Home"},
{Key.Insert, "Insert"},
{Key.Delete, "Delete"},
{Key.MouseLeft, "Mouse Left"},
{Key.MouseRight, "Mouse Right"},
{Key.MouseMiddle, "Mouse Middle"},
{Key.MouseButton4, "Mouse 4"},
{Key.MouseButton5, "Mouse 5"},
{Key.MouseButton6, "Mouse 6"},
{Key.MouseButton7, "Mouse 7"},
{Key.MouseButton8, "Mouse 8"},
{Key.MouseButton9, "Mouse 9"},
};
// Have to adjust system key name depending on platform.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_keyNiceNameMap.Add(Key.LSystem, "Left Cmd");
_keyNiceNameMap.Add(Key.RSystem, "Right Cmd");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_keyNiceNameMap.Add(Key.LSystem, "Left Win");
_keyNiceNameMap.Add(Key.RSystem, "Right Win");
}
else
{
_keyNiceNameMap.Add(Key.LSystem, "Left Meta");
_keyNiceNameMap.Add(Key.RSystem, "Right Meta");
}
return loc.GetString("input-key-unknown");
}
}
}