• Resolved enricobt

    (@enricobt)


    Hello
    I was looking for a solution to integrate Google Translator into my site and also into AMP pages. I tested a couple of plugins, such as Google Website Translator and Advanced Google Translate plugins. Unfortunately, none of them work in AMP. Do you know if there is a solution, possibly free, for the integration of the Google translation service also within the AMP pages?
    thanks a lot
    Enrico

    • This topic was modified 2 years, 10 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    Thank you for the support topic, AMP doesn’t support Google Translate and we are not aware of any such services that can be supported.

    There has been some discussion on AMP upstream Github on how you can implement simple translation but that might be unstable.

    eg:
    <a href="https://translate.google.com/translate?hl=en&sl=en&tl=es&u=ampbyexample.com" rel="nofollow noopener" target="_blank">Translate</a>

    replace ampbyexample.com with your page url.

    Instead of using such services, we will recommend using Weglot Translate plugin which can help you translate your site into a different language.

    Hope this helps!

    Thread Starter enricobt

    (@enricobt)

    Hi Milind
    As for the use of a plug -in to translate my site, this is not an option as I have more than 3000 posts and will cost a fortune to translate them all.
    The script you proposed does not work and I think that Google Translate has a different syntax now.
    If you go to translate.google.com, select WebSite and then insert an URL (e.g my site is: magazine.lorenzovinci.it) for a web, you will get something like this: “magazine-lorenzovinci-it.translate.goog/?_x_tr_sl=it&_x_tr_tl=en&_x_tr_hl=it&_x_tr_pto=wapp”
    Best regards`

    • This reply was modified 2 years, 10 months ago by enricobt.
    Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    The Weglot plugin does auto-translation, feel free to try it on your local/dev/test site first.

    Make sure to check the Translate AMP page option in weglot settings.

    The code snippet I provided does the redirect once you click on the link and lands you on the same link

    check by adding the below code snippet in the functions.php file of the active theme on dev/local once added click on the link named Spanish in the footer.

    add_action( 'wp_footer', function() {
    	?>
    		<a href="https://translate.google.com/translate?hl=en&sl=en&tl=es&u=https://magazine.lorenzovinci.it/?amp" rel="nofollow noopener" target="_blank">Spanish</a>
    	<?php
    	});
    Thread Starter enricobt

    (@enricobt)

    Hello Milind
    thanks for your help.
    Of course, the plugin solution would be better, but too expensive with my huge amount of posts.
    Then I used your solution, but just adding this HTML code in a header widget:
    '< a href="https://translate.google.com/translate?hl=it&sl=it&tl=en&u=https://magazine.lorenzovinci.it/?amp" rel="nofollow noopener" target="_blank">English < /a>'
    The only problem is that when user press English 1st time, it will be ok, but any other click on it, it will go in a page error, as href got a new URL like this:
    u=https://magazine-lorenzovinci-it.translate.goog/
    There is any way to start always from original URL ?
    Thanks
    Enrico

    • This reply was modified 2 years, 10 months ago by enricobt.
    • This reply was modified 2 years, 10 months ago by enricobt.
    • This reply was modified 2 years, 10 months ago by Jan Dembowski.
    Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    Can you please try this updated code, it should take users to the actual translation page.

    add_action(
    	'wp_footer', function() {
    		global $wp;
    		$current_url = add_query_arg( $wp->query_vars, home_url( $wp->request ) );
    		if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
    			$current_url = amp_add_paired_endpoint( $current_url ); 
    		}
    		?>
    			<a href="https://translate.google.com/translate?hl=en&sl=en&tl=es&u=<?php echo esc_url( $current_url ); ?>" rel="nofollow noopener" target="_blank">Spanish</a>
    	<?php
    });
    Thread Starter enricobt

    (@enricobt)

    Hi Milind
    I used your code and actually it does the current page translation. But then it goes again to “double translation” URL error, as the href link “English” contained in any translated page (e.g.

    https://magazine-lorenzovinci-it.translate.goog/ricette/festa-del-papa-frittelle-di-riso-toscane-2/?_x_tr_sl=it&_x_tr_tl=en&_x_tr_hl=it) 
    <strong>is pointing to something like this </strong>: 
    "https://translate.google.com/website?sl=it&tl=en&hl=it&u=https://translate.google.com/translate?hl%3Dit%26sl%3Dit%26tl%3Den%26u%3Dhttps://magazine.lorenzovinci.it/...."


    I tried to add this code to check Google Translate url, but is not working too.

    Check if Google translate
    
    $origin = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    echo '<div class="mybox">'.$origin.'</div>';
    	if ( str_contains($origin, 'translate.google') ) { 
    		return '';
    		}
    End Check

    `
    Do you have any better solution on this ?

    Best Regards
    Enrico

    • This reply was modified 2 years, 10 months ago by enricobt.
    • This reply was modified 2 years, 10 months ago by Jan Dembowski.
    Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    Can you please try this code check.

    
    // check if accept language.
    $accept_language = filter_input( INPUT_SERVER, 'HTTP_ACCEPT_LANGUAGE', FILTER_SANITIZE_STRING );
    if ( empty( $accept_language ) ) {
    	return;
    }
    
    Thread Starter enricobt

    (@enricobt)

    HI Milind
    I tested the new suggested code, but this is not always working, as many times it returns NULL even when there are no translations in progress.
    If there is any other way to detect this Google translate URL, I will leave it like it was before last change, meaning that, if users click twice on “English translation” link, an error page will be shown by Google translator.
    Regards
    Enrico

    Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    hmm, that’s strange, I am not sure if there is any other reliable way to detect Google Translate URL.

    I will check for a solution and will update you

    Thread Starter enricobt

    (@enricobt)

    Hi Melind
    I think your code is okay, but browser page caching most likely makes it unsuitable for all conditions, as I’ve noticed there is different behavior depending on which browser you’re using, especially on desktop.
    You can try it yourself, I put your code back.
    [ redundant link removed ]
    Greetings
    Enrico

    • This reply was modified 2 years, 10 months ago by Jan Dembowski.
    Plugin Support Milind More

    (@milindmore22)

    Hello @enricobt

    Thank you for getting back, oh!! the cache was causing the issue.

    Plugin Support Milind More

    (@milindmore22)

    We hope our suggestion is helpful, I’ll mark this as resolved Open a new support topic if you face further issues, also feel free to leave a plugin review, we would love to hear your feedback.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Google Translator’ is closed to new replies.