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

i18n: Expose editor's translation via EditorInterface. #82158

Closed

Conversation

zaevi
Copy link
Contributor

@zaevi zaevi commented Sep 22, 2023

Closes godotengine/godot-proposals#6885
Closes godotengine/godot-proposals#1262

Expose editor's translation via EditorInterface.get_editor_translation(). This will allow developers to add translations for their plugin.

Example (Updated):

var translation : Translation
var tool_translation := EditorInterface.get_editor_translation()

func load_translation():
    if not tool_translation:
        return
    var tr_path = "res://addons/tr_test/locales/" + tool_translation.locale + ".po"
    if ResourceLoader.exists(tr_path):
        translation = load(tr_path) 
        for msg in translation.get_message_list():
            if tool_translation.get_message(msg) != "":
                push_warning("Translation conflict for '%s'! Please report to the author!" % msg)
                translation.erase_message(msg) # avoid removal on unloading
            else:
                tool_translation.add_message(msg, translation.get_message(msg))

func unload_translation():
    if translation:
        for msg in translation.get_message_list():
            tool_translation.erase_message(msg)
        translation = null

tr_test.zip

@KoBeWi
Copy link
Member

KoBeWi commented Sep 22, 2023

Related: #77104

@timothyqiu
Copy link
Member

One thing I think #77104 does better is that it keeps track of what messages are actually added. This makes it easy to perform inverse operations.

Exposing Translation directly would require the caller to consider possible collisions. In order to safely add plugin translation, they will need to exclude & record existing messages themselves when the plugin is enabled. When disabling the plugin, they will need to remove the ones that don't exist in the original translation based on the previous record. It's tedious and I don't think most people would comply.

@zaevi
Copy link
Contributor Author

zaevi commented Sep 23, 2023

I think plugin developers should handle conflicts and removals themselves. They will find and resolve translation conflicts when debugging their plugins.

For removal, it's also easy. Continuing with the example above:

func unload_translation():
	if translation:
		for msg in translation.get_message_list():
			tool_translation.erase_message(msg)
		translation = null

@timothyqiu
Copy link
Member

I think plugin developers should handle conflicts and removals themselves.

Editor translation changes. Entries from other plugins would also collide with your plugin.

@zaevi
Copy link
Contributor Author

zaevi commented Sep 23, 2023

Editor translation changes. Entries from other plugins would also collide with your plugin.

This can also be handled manually:

        # ...
        for msg in translation.get_message_list():
            if tool_translation.get_message(msg) != "":
                push_warning("Translation conflict for '%s'! Please report to the author!" % msg)
                translation.erase_message(msg) # avoid removal on unloading
            else:
                tool_translation.add_message(msg, translation.get_message(msg))

I think we can document it to guide developers on how to support i18n for their plugins.

@akien-mga
Copy link
Member

Superseded by #95787.

@akien-mga akien-mga closed this Sep 20, 2024
@akien-mga akien-mga removed this from the 4.x milestone Sep 20, 2024
@zaevi zaevi deleted the i18n-expose-editor-translation branch September 20, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants