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

[Editor] Fix parsing translations in EditorTranslationParserPlugin #99297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AThousandShips
Copy link
Member

@AThousandShips AThousandShips commented Nov 15, 2024

Method used passed arguments as return data which does not work with extensions, switched to using a Dictionary return. This might work in extensions after fixing typed array copying, but unsure, and I think this return format is safer in any case to use, and is the standard in most of the virtual methods like this (also any binding for this will have to use const_cast as the resulting methods will pass as const TypedArray<String> &)

Follow-up to:

See also:

@AThousandShips AThousandShips requested review from a team and dalexeev November 15, 2024 19:23
@AThousandShips
Copy link
Member Author

To illustrate the issue, this is the signature of the related _parse_file method, which is being fixed in the related PR:

        virtual void _parse_file(const String &p_path, const TypedArray<String> &p_msgids, const TypedArray<Array> &p_msgids_context_plural);

Haven't generated the headers for the current state but _get_comments will have the same signature and you need to const_cast those arguments, which is very unintuitive and fragile

@dalexeev
Copy link
Member

dalexeev commented Nov 19, 2024

I'm not familiar with the GDExtension issue, but it looks good to me as long as _get_comments() is consistent with _parse_file() (so I would prefer #92175 to be merged or at least approved first). However, I have a question:

  1. If we decide to break _parse_file() compatibility, maybe it makes sense to combine _parse_file() and _get_comments() into a single method that returns a table (Array[PackedStringArray], Array[Array], or Array[Dictionary]) with the columns msgid, msgctxt, msgid_plural, and comment? The required column would be msgid, the others can be left blank. I don't think it makes sense to separate msgids and msgids_context_plural as it is now, because it's all a single table under the hood anyway.
  2. If we want to maintain maximum compatibility, we could add a _parse_file_ext() or _parse_file_2() method and deprecate _parse_file(). This is more related to Fix some arguments being passed as references in virtual functions #92175, as _get_comments() did not appear in any stable release.

@AThousandShips
Copy link
Member Author

AThousandShips commented Nov 19, 2024

That makes sense, will test some alternatives for deprecation and update as needed

I'm not familiar enough with the code here to say if merging the two methods into one is feasible, but if it is might merging the two, dropping _get_comments and deprecating _parse_file, work?

The new method could be _parse_file_and_comments or something, would be less obscure to have as a replacement maybe

That way we could possibly detect if _parse_file_and_comments or what we call it is bound, and otherwise call the outdated one

Would depend on if we consider deprecation worth it, unsure what happens in other languages but it is possible to use it in godot-cpp but requires casting, I don't know how it works in C# though so confirming how the current methods work or don't work for plugins made in C# would be good

It does seem that these cases do work with plugins in GDScript so that's a reason to deprecate over entirely replacing, but will test with GDScript soon to confirm

@raulsntos
Copy link
Member

I don't know how it works in C# though so confirming how the current methods work or don't work for plugins made in C# would be good

I haven't tested personally but since Arrays in C# are reference types I imagine they may work. #99195 uses the method so, assuming the PR works, it would prove that the method works in C#.

Also, how is the GDExtension validation not complaining about breaking compatibility? Does it not check virtual methods?

@dalexeev
Copy link
Member

Also, how is the GDExtension validation not complaining about breaking compatibility? Does it not check virtual methods?

EditorTranslationParserPlugin._get_comments() is not in 4.3 stable. Only #92175 breaks compatibility, this PR can be considered as a non-breaking part of #92175.

@dalexeev
Copy link
Member

I'm not familiar enough with the code here to say if merging the two methods into one is feasible, but if it is might merging the two, dropping _get_comments and deprecating _parse_file, work?

The new method could be _parse_file_and_comments or something, would be less obscure to have as a replacement maybe

That way we could possibly detect if _parse_file_and_comments or what we call it is bound, and otherwise call the outdated one

I guess it depends on how we handle other cases in #92175. Yes, the fact that it seems to work in GDScript and C# is an argument for deprecation instead of removal/replacement. However, I don't think EditorTranslationParserPlugin is used very often, so breaking compatibility there is more acceptable than with core APIs like Object, Node, etc.

@AThousandShips
Copy link
Member Author

I'll see about some options today for this and #92175

@AThousandShips
Copy link
Member Author

AThousandShips commented Dec 3, 2024

Will try investigate this properly this week

Edit: haven't been able to find the time to investigate this yet but will try next week

@akien-mga
Copy link
Member

Bump :) This seems to be important to merge before 4.4, as IIUC it's fixing the return type of a newly exposed function.

@AThousandShips
Copy link
Member Author

Agreed, will try get to this before the end of the week!

@AThousandShips
Copy link
Member Author

Working on this and testing out making a new parse_file with the new compatibility system, will report back with results

@AThousandShips
Copy link
Member Author

AThousandShips commented Jan 17, 2025

Gotten it to work, and works correctly with existing code and plugins, just tested the plugin in GDScript so couldn't test the deprecation

The one question is if we keep get_comments as a deprecated method in tandem, for now I've simply dropped it, pushing soon

Edit: Will update the documentation after we've decided on a solution

@AThousandShips AThousandShips requested a review from a team as a code owner January 17, 2025 16:31
@AThousandShips AThousandShips changed the title [Editor] Fix return of EditorTranslationParserPlugin._get_comments [Editor] Fix parsing translations in EditorTranslationParserPlugin Jan 17, 2025
Method used passed arguments as return data which does not work with
extensions, switched to using a `Dictionary` return.
@AThousandShips AThousandShips requested a review from a team as a code owner January 17, 2025 17:16
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.

4 participants