Skip to content

Solve the Google Translate problem in v2 #7461

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

Open
Varixo opened this issue Mar 27, 2025 · 1 comment
Open

Solve the Google Translate problem in v2 #7461

Varixo opened this issue Mar 27, 2025 · 1 comment
Labels

Comments

@Varixo
Copy link
Member

Varixo commented Mar 27, 2025

Probably we should use some comments nodes for this


One of developer reported, that this code fixed problems with google translate in v2 (worth checking):

export const fix = () => {
    if (typeof Node !== "function" || !Node.prototype) {
        return;
    }

    const originalRemoveChild = Node.prototype.removeChild;
    const originalInsertBefore = Node.prototype.insertBefore;

    // @ts-expect-error
    Node.prototype.removeChild = function (child, ...rest) {
        if (child.parentNode !== this) {
            return child;
        }

        return originalRemoveChild.apply(this, [child, ...rest]);
    };

    // @ts-expect-error
    Node.prototype.insertBefore = function (newNode, referenceNode, ...rest) {
        if (referenceNode && referenceNode.parentNode !== this) {
            return newNode;
        }

        return originalInsertBefore.apply(this, [
            newNode,
            referenceNode,
            ...rest,
        ]);
    };
};
@Varixo Varixo converted this from a draft issue Mar 27, 2025
@Varixo Varixo added VERSION: upcoming major TYPE: bug Something isn't working labels Mar 27, 2025
@kanashimia
Copy link

kanashimia commented Apr 26, 2025

Suggestion: use separator like <!> (a valid HTML comment) and store indices to text between such separator nodes instead of char count, that will prevent problems with modifying text.
(or as an alternative <!:> or <!q>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

No branches or pull requests

2 participants