1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-12-28 09:05:30 +01:00

Translate key names in KeyPress::name() (#16779)

* Make KeyPress::name() return translated key names

* minor
This commit is contained in:
y5nw
2025-12-27 13:24:57 +01:00
committed by GitHub
parent 46436248de
commit 6fd46c05ae
3 changed files with 7 additions and 9 deletions

View File

@@ -3,6 +3,7 @@
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
#include "keycode.h"
#include "gettext.h"
#include "settings.h"
#include "log.h"
#include "renderingengine.h"
@@ -28,8 +29,6 @@ struct table_key {
#define DEFINEKEY5(ch) /* key without Irrlicht keycode */ \
{ ch, KEY_KEY_CODES_COUNT, static_cast<wchar_t>(*ch), ch },
#define N_(text) text
static std::vector<table_key> table = {
// Keys that can be reliably mapped between Char and Key
DEFINEKEY3(0)
@@ -224,9 +223,6 @@ static std::vector<table_key> table = {
static const table_key invalid_key = {"", KEY_UNKNOWN, L'\0', ""};
#undef N_
static const table_key &lookup_keychar(wchar_t Char)
{
if (Char == L'\0')
@@ -327,8 +323,10 @@ std::string KeyPress::name() const
{
const auto &name = lookup_scancode(scancode).LangName;
if (!name.empty())
return name;
return formatScancode();
return strgettext(name);
if (auto scancode = getScancode())
return fmtgettext("Scancode: %d", scancode);
return "";
}
EKEY_CODE KeyPress::getKeycode() const

View File

@@ -25,7 +25,7 @@ void GUIButtonKey::setKey(KeyPress kp)
{
key_value = kp;
keysym = utf8_to_wide(kp.sym());
super::setText(wstrgettext(kp.name()).c_str());
super::setText(utf8_to_wide(kp.name()).c_str());
}
void GUIButtonKey::sendKey()

View File

@@ -61,7 +61,7 @@ private:
{
capturing = false;
nostart |= inhibit_restart;
super::setText(wstrgettext(key_value.name()).c_str());
super::setText(utf8_to_wide(key_value.name()).c_str());
}
//! Sets the captured key and stop capturing