Skip to content

Localize key labels based on keyboard language #10350

@AdriaandeJongh

Description

@AdriaandeJongh

Describe the project you are working on

Rift Riff, a tower defense game localized to 12 languages.

Describe the problem or limitation you are having in your project

In order to fully localize my game and support full input remapping on keyboards, I need localized key labels.

OS.get_keycode_string(DisplayServer.keyboard_get_label_from_physical(physical_key)) returns only the English name for a key, even if the keyboard's language is not English. This means getting the keycode string for the physical Key.KEY_UP will, for instance, always return "Up" and not "Oben" when using a German keyboard, while the keycode string for the physical Key.KEY_BRACKETLEFT will correctly return Ü for a German Keyboard. This is in my opinion inconsistent.

As a sidenote, it is very confusing that DisplayServer.keyboard_get_label_from_physical(physical_key) returns a Key as opposed to a String. I don't understand how it returns an enum (Key) and yet the method's description says it can return any unicode character? I must be misunderstanding something here because somehow it works in combination with OS.get_keycode_string() for characters like the Ü on German keyboards even though there is no Key enum value for that character specifically.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A way to return the localized key label would enable me to localize my game and support full input remapping on keyboards.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I don't know enough about the engine's inner workings to get specific here, but considering DisplayServer.keyboard_get_layout_language() exists, this means that the keyboard's language is available to Godot. Either OS.get_keycode_string() should return the key label translated to the keyboard's language, or a method (something along the lines of get_localized_key_label()) could be added to OS or DisplayServer or TranslationServer to get the localized label for the key based on the language of the keyboard.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Right now, a workaround is to add the majority of English names for keys (from this list) to my game's localization and add checks to see what keys to translate manually using tr() before I display the label to players.

Is there a reason why this should be core and not an add-on in the asset library?

Both localization and input remapping are necessary features in a fully fledged game, and both features increasingly expected by players. I believe this is an issue for any localized Godot game supporting input remapping and relevant to every game developer serious about marketing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions