godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 96 forks source link

Automatically Setting the Game Window Title Based on 'application/config/name_localized' Contents #7226

Open c3-hoge-fuga-piyo opened 1 year ago

c3-hoge-fuga-piyo commented 1 year ago

Describe the project you are working on

Various 2D games.

Describe the problem or limitation you are having in your project

While working on settings for localization, I noticed that the game window's title is always set to application/config/name, regardless of the contents of application/config/name_localized.

Upon examining the relevant implementation, I found that TranslationServer::translate is being executed for application/config/name. However, TranslationServer does not take into account the contents of application/config/name_localized, resulting in it not being properly translated.

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

Currently, it's redundant to have to add the same content in both application/config/name_localized and the regular localization settings.

Moreover, it would become possible to obtain the localized game title through the TranslationServer from application/config/name.

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

Based on the current implementation, it would become possible to obtain the locale-appropriate contents of application/config/name_localized by using TranslationServer.translate(ProjectSettings.get_settings("application/config/name")).

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

# At the initialization timing of the application.
var appnames := ProjectSettings.get_setting("application/config/name_localized", {}) as Dictionary
for locale in appnames:
    var appname := appnames[locale] as String
    var translation := Translation.new()
    translation.locale = locale
    TranslationServer.add_translation(translation)
    translation.add_message(key, appname)

# Setting the translated title to the game window.
var appname := ProjectSettings.get_setting("application/config/name") as String
var localized_appname := TranslationServer.translate(appname)
get_window().title = localized_appname

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

It seems that localization is considered in the implementation, so it might not be a feature omission but an unintended bug.

AThousandShips commented 11 months ago

Can someone confirm that the various platforms support all the different possible scripts for the name? Like Chinese characters? Otherwise there's a risk of the game running on a language that results in a window with garbled text of the title

Calinou commented 11 months ago

Can someone confirm that the various platforms support all the different possible scripts for the name? Like Chinese characters? Otherwise there's a risk of the game running on a language that results in a window with garbled text of the title

This should pretty much always work as the window title is drawn using the system font, which has a pretty extensive set of fallbacks available for various scripts. The only case where it may fail is with applications that don't have proper Unicode handling, but Godot sure does :slightly_smiling_face: