X Tutup
Skip to content

Add source lines to file locations on POT generation#111419

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:numbers_numbers_numbers
Oct 14, 2025
Merged

Add source lines to file locations on POT generation#111419
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:numbers_numbers_numbers

Conversation

@YeldhamDev
Copy link
Member

gettext allows not just adding the file path where a string comes from, but also the specific line number. This PR makes so that strings extracted from GDScripts also state the source line, as well as allowing plugins to do the same.

@YeldhamDev YeldhamDev added this to the 4.x milestone Oct 8, 2025
@YeldhamDev YeldhamDev requested review from a team as code owners October 8, 2025 16:38
Copy link
Member

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a good reason this wasn't done before... Does it genuinely work properly out-of-the-box?

[gdscript]
# This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", and comment "test 1 comment".
ret.append(PackedStringArray(["Test 1", "context", "test 1 plurals", "test 1 comment"]))
# This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", comment "test 1 comment", and source line "7".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this comment grew in length, it's not going to be an easy read, not that it was before. This will not look pretty in the built-in and online class reference.
I would suggest removing it, but at the same time, that would be inconsistent with the other comments below, which are... of questionable utility, too.

@YeldhamDev
Copy link
Member Author

YeldhamDev commented Oct 8, 2025

I wonder if there's a good reason this wasn't done before... Does it genuinely work properly out-of-the-box?

PO editors such as Poedit and Weblate make use of this feature by opening the source file and pointing the tagged line. It's a nice thing to have when checking for extra context. Here's a example of it in action:

image

@YeldhamDev YeldhamDev force-pushed the numbers_numbers_numbers branch from e663d90 to 3b79d97 Compare October 8, 2025 17:39
@YeldhamDev
Copy link
Member Author

@dalexeev Changes made.

@Mickeon
Copy link
Member

Mickeon commented Oct 8, 2025

PO editors such as Poedit and Weblate make use of this feature by opening the source file and pointing the tagged line

Yeah, I was aware of that myself. I was just wondering why no one thought of adding the extra parameter sooner.
This is entirely unrelated to the ability of actually implementing proper source lines for the editor itself, I gather?

@YeldhamDev YeldhamDev force-pushed the numbers_numbers_numbers branch from 3b79d97 to ab80976 Compare October 8, 2025 17:55
@akien-mga
Copy link
Member

akien-mga commented Oct 8, 2025

This is entirely unrelated to the ability of actually implementing proper source lines for the editor itself, I gather?

Editor translations can also have source lines, and did in the past. I now remove them because they make the diffs humongous on syncs, so we'd quickly end up with GBs of POT files diffs in the history.

I don't know if that would be a problem for text heavy games or Godot apps that would want this to be opt-out. We can wait for users to ask, or they can post-process the generated POT file to strip lines before committing to VCS.

Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me.

@YeldhamDev YeldhamDev force-pushed the numbers_numbers_numbers branch from ab80976 to 0de3f8b Compare October 8, 2025 19:43
@dalexeev
Copy link
Member

dalexeev commented Oct 8, 2025

We can wait for users to ask, or they can post-process the generated POT file to strip lines before committing to VCS.

See my recent PR #111074 for the ability to intercept standard parsers (I plan to polish the PR a bit more). With this, users could quite easily implement a parser that would remove line numbers from extracted strings.

@Repiteo Repiteo modified the milestones: 4.x, 4.6 Oct 13, 2025
@Repiteo Repiteo merged commit 4ae535b into godotengine:master Oct 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 14, 2025

Thanks!

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.

5 participants

X Tutup