Combining manually translated French pages with GTranslate

Popular automatic website translation tool

Combining manually translated French pages with GTranslate

Postby oxygensmith » Tue Oct 16, 2018 6:24 pm

Hi folks, GTranslate chat isn't working for me, so I'm coming to you.

The upshot of this post is that: I'm a Wordpress coder comfortable with editing PHP, Javascript, Wordpress template code. I'm wondering if it's possible to create our own GTranslate buttons on templates, instead of just activating the floating language switcher, or menu language switcher, via the plugin control panel.

The reason is, we are in the situation of soon launching a bilingual site that has some pages translated to French manually. But not all pages are translated.

So I am looking for:
- code snippets
- documentation
- hooks to use in GTranslate to make what I want happen
- experiences with trying to make this happen.

I think I have a pretty good strategy for using GTranslate in a situation where your site has some manually translated pages, but where you need the rest of the pages (and the surrounding menu and sitewide elements, etc.) translated when someone clicks "FR."

I am not using WPML to handle the translated articles, but I am using Advanced Custom Fields to create two fields for all posts and pages: 1) the language the article is in (EN or FR), and 2) its link to the other translation.

So what I need to do is create an "FR" button that goes through this logic (in PHP, using Wordpress functions):
- Is this a page or post that is linked to a manually translated version with a URL supplied?
--- If yes, 1) go to the post or page where the manual translation exists, and then 2) translate it (via GTranslate). Fire all the cookies so that the visitor is now cruising the site in French.
--- If no, just GTranslate to French normally.

The reason this is ideal is because, on manually translated blog posts where it's indicated the language is French, we put a "notranslate" div around the whole article and title. When GTranslate translates a manually translated French page, the manual translation remains, while GTranslate helpfully auto-translates everything else (sidebars, menu etc).

So for example, here is a site soon to be launched (please forgive the somewhat rough draft looking website):

If on this page in English:
https://nfarmers.ca/open-statement-on-n ... d-climate/" rel="nofollow" target="_blank

Has this translation:
https://nfarmers.ca/declaration-sur-lal ... le-climat/" rel="nofollow" target="_blank

Then what we *want* to do, when people are on the English page and click FR:
https://nfarmers.ca/open-statement-on-n ... d-climate/" rel="nofollow" target="_blank

... they should get here:
https://nfarmers.ca/fr/declaration-sur- ... le-climat/" rel="nofollow" target="_blank

It would do this logic in reverse when going from
https://nfarmers.ca/fr/declaration-sur- ... le-climat/" rel="nofollow" target="_blank
back to
https://nfarmers.ca/open-statement-on-n ... d-climate/" rel="nofollow" target="_blank

What I've already tried, and why I think I have to make my own buttons:

My planned, easy way to deal with this, where I wouldn't have to touch code at all, was simply to install the [url href="https://en-ca.wordpress.org/plugins/redirection/"]Redirection[/url] plugin. Part of the process of putting up an English and manually translated French article would then be setting up a redirect. Simple.

So, in the example above, we would just set up a redirect from:
https://nfarmers.ca/declaration-sur-lal ... le-climat/" rel="nofollow" target="_blank

...to:

https://nfarmers.ca/fr/declaration-sur- ... le-climat/" rel="nofollow" target="_blank

However, this doesn't work - Redirection chokes and we get a "too many redirects" error. This is because GTranslate sets up its own redirection in the htaccess file.

So, without Redirection, I think I have to set up my own EN/FR buttons that do some logic before letting GTranslate do its thing (basically, possibly supply a different URL to translate to GTranslate before GTranslate fires), but I don't yet know the best way to begin.

Any and all advice or support, tips, clues, snippets, documetation, etc. are super appreciated. Would love to hear about your experiences combining autotranslation with manual translation. It's been a headache for us but GTranslate gets us *so close* to what we want! (at a very reasonable / affordable budget)
oxygensmith
 
Posts: 2
Joined: Tue Oct 16, 2018 5:45 pm

Re: Combining manually translated French pages with GTransla

Postby Yana » Tue Oct 16, 2018 10:39 pm

Hi,

You can check our documentation here https://docs.gtranslate.io/how-tos .
I will ask our developer to check this .
Regards,

Yana Ghahramanyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Yana
 
Posts: 4499
Joined: Thu Jan 12, 2012 6:21 pm

Re: Combining manually translated French pages with GTransla

Postby oxygensmith » Thu Oct 18, 2018 5:43 pm

Thanks Yana.

All right, this answer is kind of helpful but not totally:

https://docs.gtranslate.io/how-tos/how- ... d-language" rel="nofollow" target="_blank

I might be able to do something with this, but I'd like to find a hook/filter/action, if it exists, in which I can interrupt and swap in a different URL when I click the "FR" button (so I can say, "GTranslate, go to the /fr/ version of another page of my choosing (the manually translated French one) rather than the /fr/ one you associate with this English page."

This would be a perfect way of handling "sites with some manual translation but not full manual translation" I think.

I will keep trying but if you can explain to the developers what I'm trying to do, and get an answer, that would be great.

Thanks again.
oxygensmith
 
Posts: 2
Joined: Tue Oct 16, 2018 5:45 pm

Re: Combining manually translated French pages with GTransla

Postby Edvard » Tue Oct 23, 2018 1:05 am

Hi,

This can be helpful:

Code: Select all
<a href="test.html" data-gt-href-fr="french.html" data-gt-href-es="spanish.html">...</a>


This tells us to use french.html link instead of test.html on French version, spanish.html on Spanish version.

Thanks!
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4399
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia


  • Related Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests

2GLux
cron