Skip to content

Commit 4ae535b

Browse files
committed
Merge pull request #111419 from YeldhamDev/numbers_numbers_numbers
Add source lines to file locations on POT generation
2 parents c0c7556 + 0de3f8b commit 4ae535b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

doc/classes/EditorTranslationParserPlugin.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</brief_description>
66
<description>
77
[EditorTranslationParserPlugin] is invoked when a file is being parsed to extract strings that require translation. To define the parsing and string extraction logic, override the [method _parse_file] method in script.
8-
The return value should be an [Array] of [PackedStringArray]s, one for each extracted translatable string. Each entry should contain [code][msgid, msgctxt, msgid_plural, comment][/code], where all except [code]msgid[/code] are optional. Empty strings will be ignored.
8+
The return value should be an [Array] of [PackedStringArray]s, one for each extracted translatable string. Each entry should contain [code][msgid, msgctxt, msgid_plural, comment, source_line][/code], where all except [code]msgid[/code] are optional. Empty strings will be ignored.
99
The extracted strings will be written into a POT file selected by user under "POT Generation" in "Localization" tab in "Project Settings" menu.
1010
Below shows an example of a custom parser that extracts strings from a CSV file to write into a POT.
1111
[codeblocks]
@@ -54,19 +54,19 @@
5454
}
5555
[/csharp]
5656
[/codeblocks]
57-
To add a translatable string associated with a context, plural, or comment:
57+
To add a translatable string associated with a context, plural, comment, or source line:
5858
[codeblocks]
5959
[gdscript]
60-
# This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", and comment "test 1 comment".
61-
ret.append(PackedStringArray(["Test 1", "context", "test 1 plurals", "test 1 comment"]))
60+
# This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", comment "test 1 comment", and source line "7".
61+
ret.append(PackedStringArray(["Test 1", "context", "test 1 plurals", "test 1 comment", "7"]))
6262
# This will add a message with msgid "A test without context" and msgid_plural "plurals".
6363
ret.append(PackedStringArray(["A test without context", "", "plurals"]))
6464
# This will add a message with msgid "Only with context" and msgctxt "a friendly context".
6565
ret.append(PackedStringArray(["Only with context", "a friendly context"]))
6666
[/gdscript]
6767
[csharp]
68-
// This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", and comment "test 1 comment".
69-
ret.Add(["Test 1", "context", "test 1 plurals", "test 1 comment"]);
68+
// This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", comment "test 1 comment", and source line "7".
69+
ret.Add(["Test 1", "context", "test 1 plurals", "test 1 comment", "7"]);
7070
// This will add a message with msgid "A test without context" and msgid_plural "plurals".
7171
ret.Add(["A test without context", "", "plurals"]);
7272
// This will add a message with msgid "Only with context" and msgctxt "a friendly context".

editor/translations/pot_generator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ void POTGenerator::generate_pot(const String &p_file) {
8484
const String &msgctxt = (translation.size() > 1) ? translation[1] : String();
8585
const String &msgid_plural = (translation.size() > 2) ? translation[2] : String();
8686
const String &comment = (translation.size() > 3) ? translation[3] : String();
87-
_add_new_msgid(translation[0], msgctxt, msgid_plural, file_path, comment);
87+
const int source_line = (translation.size() > 4) ? translation[4].to_int() : 0;
88+
String location = file_path;
89+
if (source_line > 0) {
90+
location += vformat(":%d", source_line);
91+
}
92+
_add_new_msgid(translation[0], msgctxt, msgid_plural, location, comment);
8893
}
8994
}
9095

modules/gdscript/editor/gdscript_translation_parser_plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void GDScriptEditorTranslationParserPlugin::_add_id(const String &p_id, int p_li
126126
return;
127127
}
128128

129-
translations->push_back({ p_id, String(), String(), comment });
129+
translations->push_back({ p_id, String(), String(), comment, itos(p_line) });
130130
}
131131

132132
void GDScriptEditorTranslationParserPlugin::_add_id_ctx_plural(const Vector<String> &p_id_ctx_plural, int p_line) {
@@ -136,7 +136,7 @@ void GDScriptEditorTranslationParserPlugin::_add_id_ctx_plural(const Vector<Stri
136136
return;
137137
}
138138

139-
translations->push_back({ p_id_ctx_plural[0], p_id_ctx_plural[1], p_id_ctx_plural[2], comment });
139+
translations->push_back({ p_id_ctx_plural[0], p_id_ctx_plural[1], p_id_ctx_plural[2], comment, itos(p_line) });
140140
}
141141

142142
void GDScriptEditorTranslationParserPlugin::_traverse_class(const GDScriptParser::ClassNode *p_class) {

0 commit comments

Comments
 (0)