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

Add translators comments extraction for Editor #41510

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

SkyLucilfer
Copy link
Contributor

@SkyLucilfer SkyLucilfer commented Aug 25, 2020

Added ability to extract translator comments in the C++ code.

When TRANSLATORS: tag is used in a comment, text following the tag will be extracted into the POT file as translator comment. The translator comment will be applied to the next translation function (TTR(), RTR() etc.) following it.

Example usage:

  • Single line

2

  • Multiline

  • Using block-comment style

Resulting POT file

The resulting POT file from the 3 comments above:
editor.pot.txt
(I have to add the extension .txt at the end to be able to attach it)

@Calinou Calinou added cherrypick:3.x Considered for cherry-picking into a future 3.x release enhancement topic:editor labels Aug 25, 2020
@Calinou Calinou added this to the 4.0 milestone Aug 25, 2020
@akien-mga
Copy link
Member

Tested locally, it seems to work well!

Some testing notes (which do not imply the need for changes to this PR):

  • Multiline comments seem to be extracted verbatim (with whitespace stripped), so that means that cosmetic line breaks in the C++ source will also lead to line breaks in the POT file and in the PO edition tool used by the translators. E.g.:
       // TRANSLATORS: This is a
       //  multiline
       //    comment
       //     and now with a very long line that should be wrapped by msgfmt so let's see how it goes and if PO editors like this mwahaha.
       print_line(TTR("Hello world") + " - " + TTR("Second part of string"));

Appears in Poedit as:
Screenshot_20200907_143546

That's not something to change IMO, but it's good to be aware of. I've tried and msgmerge (run by make merge) does not hard-wrap the long lines to 79 chars as done for the msgids and msgstrs (again, not a problem, I just figured that should be noted).

  • When two consecutive TTR calls are on the same line, only the first one has the translator comment. That also makes sense. It means that if we want to add translator comments for something that comes second on a line, the code should be refactored to split this string over multiple statements to be able to put the comment. For example this works fine:
	// TRANSLATORS: This is a
	//  multiline
	//    comment
	print_line(TTR("Hello world") + " - " +
			/* TRANSLATORS: Comments in split statements work! */
			TTR("Second part of string"));

Inline comments don't seem to work and could possibly be supported, but IMO it's a bit overkill so I wouldn't bother:

	// TRANSLATORS: This is a
	//  multiline
	//    comment
	//     and now with a very long line that should be wrapped by msgfmt so let's see how it goes and if PO editors like this mwahaha.
	print_line(TTR("Hello world") + " - " + /* TRANSLATORS: Inline comments don't work! */ TTR("Second part of string"));

@akien-mga akien-mga merged commit 5bf28c7 into godotengine:master Sep 7, 2020
@akien-mga
Copy link
Member

Thanks!

Could you make a backport PR for the 3.2 branch? The commit can't be cherry-picked as is as the 3.2 branch didn't get other changes like context and plurals support, but this specific feature should be safe to backport.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants