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

PHP - extract the children from this <div id="page-container"> then translate it and put them back into this same <div id="page-container"> #207

Open
richardsonoge opened this issue May 16, 2024 · 0 comments

Comments

@richardsonoge
Copy link

This code allowed me to extract all the children from this and translate it for free using Stichoza/google-translate-php's library. However, when I put it back into this , it doesn't give the same results. The HTML content is not preserved, it has lost all its style and without exception. Secondly, accents are also not supported in the French translation. Acute accents or other accents in French are not displayed correctly as "é" is displayed this way "é". Please, do something for me...

Here's part of my code, how I tried to translate my HTML:

$htmlContent = file_get_contents('fss4.html');
$getContent = getPageContainerContent($htmlContent);

$stringSplit = str_split($getContent, 3700);
$countStringSplit = count($stringSplit);

$translateHTML = '';

for ($i = 0; $i < $countStringSplit; $i++) {
    // Translate each chunk of html
    $translateHTML .= $tr->translate($stringSplit[$i]);
}

$getCorrectTranslateHtml = preg_replace('/\/\s/', '/', $translateHTML);

$getCorrectTranslateHtml = removeSpacesBetweenTags($getCorrectTranslateHtml);

$new_html = replace_page_container($htmlContent, $getCorrectTranslateHtml);
$new_html = html_entity_decode($new_html);
$new_html = iconv('utf-8', 'latin1', $new_html);
file_put_contents('fss4_translated.html', $new_html);

Can you help me get the same results as in the original HTML file without losing the format of my HTML and fix the accent problems for me too?

I think it's because the tags are missing or Google has changed the tag format. I uploaded my code and the HTML file of this project on Github, you could see all the codes so you can help me to solve this big problem please. Any help to solve it....

I hope my question is clear and if you find it not clear enough let me know in the comments.

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

No branches or pull requests

1 participant