-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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 c# translation parser support #99195
base: master
Are you sure you want to change the base?
Add c# translation parser support #99195
Conversation
I've observed that dalexeev is adding support for comments to this system. But the corresponding PR has not been merged. In theory, I should follow up and let C# adopt the same approach to support comments. But obviously I need his changes to |
Hi, and thank you for your contribution 🙂 This is something I wanted to tackle for quite some time, but never got to, so I'm excited to see this PR! This is a quick first review, I haven't tested thoroughly. Did you by any chance forget to commit your I'm pretty sure the check for a public static class Foo
{
public static void Tr(string myString)
{
}
} I'm wondering if we could easily make this more resilient. Otherwise, I think this would be a very good addition 🥳 |
To avoid recompiling godot completely on my poor computer, I did the actual coding and testing in another godot source code directory where I was working. It seems that I forgot to move Regarding the selection problem you mentioned. It seems that simple ast parsing cannot fully handle these situations well, and more semantic analysis may be needed to more accurately identify the functions that need to be captured. I will try to use a new method to select. |
I followed up on dalexeev's PR. Added support for translation comments. In addition to supporting single-line comments, there are also multi-line single-line comments and C# multi-line comments. Exampleusing Godot;
using System;
public partial class Test : Node
{
public override void _Ready()
{
GD.Print(Tr("Tr1"));
GD.Print(Tr("Tr2", "ctx_a"));
GD.Print(Tr("Tr3")); // NO_TRANSLATE
GD.Print(Tr("Tr4")); // TRANSLATE: Message 4
// TRANSLATE: Message 5
GD.Print(Tr("Tr5"));
// Above comment.
// TRANSLATE: Message 6 Line 1
// Message 6 Line 2
// Message 6 Line 3
GD.Print(Tr("Tr6"));
// Above comment.
/* TRANSLATE: Message 7
* Message 7 Line 2
* Message 7 Line 3
* Message 7 Line 4
*/
GD.Print(TrN("Tr_n7", "Tr_n7_plural", 0, "ctx_b"));
GD.Print(Tr("Tr8", "ctx_c")); // TRANSLATE: Message 8.1
GD.Print(Tr("Tr8", "ctx_c")); // TRANSLATE: Message 8.1
GD.Print(Tr("Tr8", "ctx_c")); // TRANSLATE: Message 8.2
GD.Print(Tr("Tr8", "ctx_d")); // TRANSLATE: Message 8.3
// TRANSLATE: Message 9
// Empty line ^^
GD.Print(Tr("Tr9"));
GD.Print(Tr("Tr10")); // TRANSLATE: Message 10
GD.Print(Tr("Tr11"));
}
} # LANGUAGE translation for i18n_test for the following files:
# res://test.cs
#
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: i18n_test\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"
#: test.cs
msgctxt "ctx_a"
msgid "Tr2"
msgstr ""
#. TRANSLATORS: TRANSLATE: Message 7
#. * Message 7 Line 2
#. * Message 7 Line 3
#. * Message 7 Line 4
#: test.cs
msgctxt "ctx_b"
msgid "Tr_n7"
msgid_plural "Tr_n7_plural"
msgstr[0] ""
msgstr[1] ""
#. TRANSLATORS: TRANSLATE: Message 8.1
#. TRANSLATE: Message 8.2
#: test.cs
msgctxt "ctx_c"
msgid "Tr8"
msgstr ""
#. TRANSLATORS: TRANSLATE: Message 8.3
#: test.cs
msgctxt "ctx_d"
msgid "Tr8"
msgstr ""
#: test.cs
msgid "Tr1"
msgstr ""
#. TRANSLATORS: TRANSLATE: Message 4
#: test.cs
msgid "Tr4"
msgstr ""
#: test.cs
msgid "Tr5"
msgstr ""
#: test.cs
msgid "Tr6"
msgstr ""
#: test.cs
msgid "Tr9"
msgstr ""
#. TRANSLATORS: TRANSLATE: Message 10
#: test.cs
msgid "Tr10"
msgstr ""
#: test.cs
msgid "Tr11"
msgstr "" |
For a long time, the Godot engine lacks support for i18n string collection for C# scripts.
This PR implements CsharpTranslationParserPlugin by analyzing the AST returned by Roslyn and adds it to GodotTools.