Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dracks opened this issue Jul 7, 2024 · 6 comments

Comments

@Dracks
Copy link

Dracks commented Jul 7, 2024

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
Copy link

RedMser commented Jul 7, 2024

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
Copy link
Author

Dracks commented Jul 7, 2024

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
Copy link

RedMser commented Jul 7, 2024

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
Copy link
Author

Dracks commented Jul 7, 2024

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
Copy link

RedMser commented Jul 7, 2024

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 #1316 )

@Dracks
Copy link
Author

Dracks commented Jul 7, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants