godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

have an export_translation that tells godot the exported string needs translation #10139

Open Dracks opened 1 week ago

Dracks commented 1 week ago

Describe the project you are working on

I'm working on a project that is a clone of advance wars, and I was trying to cleanup/improve our translation workflows

Describe the problem or limitation you are having in your project

Currently we have some custom scripts for scenes, that contains exported variables, that needs to be translated, and we need to manually do the call to the translation, like:

@export var title: String = "Menu":
    set(value):
        ($Label as Label).text = tr(value)
        title = tr(value)

Also, this means the automatic pot generation don't detect this texts.

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

I will like to have some export_translation that automatically can translate the string without custom code, Also will be nice that godot can pick the different texts used in this exported values to generate the base.pot file

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

use the new flag in the string, to rewrite my previous code:

@export_translation var title: String = "Menu":
    set(value):
        ($Label as Label).text = value
        title = value

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

more or less yes, for the automatic pot generation is more problematic

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

a library/plugin cannot control this as far as I know

RedMser commented 1 week ago

Your proposal code is missing use of the new annotation.

As for workarounds, you could always prefix those fields with a custom group or a name prefix like tr_title, loop through get_property_list in an external script and have that do the translation and detect language changes.

Dracks commented 1 week ago

Your proposal code is missing use of the new annotation. Sorry, Changed now!

As for workarounds, you could always prefix those fields with a custom group or a name prefix like tr_title, loop through get_property_list in an external script and have that do the translation and detect language changes.

I don't see the benefit of your workarround vs our current one, maybe I'm missing something?

RedMser commented 1 week ago

I don't see the benefit of your workarround vs our current one, maybe I'm missing something?

Automatic POT generator can be extended with a plugin to detect which fields are marked as translatable just by getting list of script properties.

Also your current solution doesn't handle the language change notification, so you'd need to restart the game or reload the entire scene to change language (or handle the notification as boilerplate in each script).

Dracks commented 1 week ago

Ah, I didn't know that the plugins can modify the POT generator.

Then your workarround will be to have some kind of autoload? that detects it? Also it can receive signals?

About the change of language, you mean when we are inside the game, and we change the language there right?

Thanks a lot for your input!

RedMser commented 1 week ago

I didn't know that the plugins can modify the POT generator.

See EditorTranslationParserPlugin and EditorPlugin.add_translation_parser_plugin

Then your workarround will be to have some kind of autoload? that detects it? Also it can receive signals?

About the change of language, you mean when we are inside the game, and we change the language there right?

Yes I haven't tried it myself like this, but it seems very possible to do it as an autoload that keeps track of the scene tree (e.g. using node_added signal). Change of language is indeed like you said, if you're in a settings menu and change the language dropdown. You need to handle NOTIFICATION_TRANSLATION_CHANGED as shown in the docs.


By the way I'm not saying this proposal would not be helpful. Just providing a workaround so everyone knows there is alternative ways to approach the problem, and maybe the core team decides this is e.g. something that a custom annotation should handle instead of a core builtin (see https://github.com/godotengine/godot-proposals/issues/1316 )

Dracks commented 1 week ago

I never said that you were discarting my "proposal", at the end is only a proposal.

I'm learning a lot in this ticket! (tecnically I already added a link to this issue in our code)

I already found the editorTranslationParserPlugin. But I don't expect to have more time to invest on this for the future weeks. Let's see... Still super thanks!

yeah, maybe a custom annotation will work also, I don't know about them yet. (They are also a proposal, right?)

Thanks!