GTranslate: A Simple WordPress Translation Plugin Using Google Translate

I’ve hesitated to use machine translations of my site in the past. I’d love to have translators all over the planet to assist in translating my site for different audiences, but there’s no way I would recoup those costs.

That said, I noticed that my site content is shared internationally quite a bit – and many people are using Google Translate to read my content in their native language. That makes me optimistic that the translation may be good enough now that Google continues to improve using machine learning and artificial intelligence.

With that in mind, I wanted to add a plugin that offered translation using Google Translate, but I wanted something more comprehensive than a dropdown that translated the site. I want search engines to actually see and index my content internationally, which requires a couple of features:

My hope, of course, is that it will open my site up to a much wider audience, and there’s a great return on investment as I can increase my affiliate and advertising revenue – without requiring the effort of manual translation.

GTranslate WordPress Plugin

The GTranslate plugin and accompanying service incorporate all these features as well as many other options:

gtranslate translation dashboard
<a href="https://martech.zone" data-gt-href-fr="http://fr.martech.zone">Example</a>

The syntax is similar for an image:

<img src="original.jpg" data-gt-src-ru="russian.jpg" data-gt-src-es="spanish.jpg" />

And if you don’t want a section translated, you can add a class of notranslate.

<span class="notranslate">Do not translate this!</span>

Sign Up for a GTranslate 15-Day Trial

GTranslate and Header Permissions

If you’ve opted to configure GTranslate using subdomains, you may have an issue where assets like fonts on your site aren’t loading correctly. To correct this, you’ll need a plugin to update your HTTP Headers to enable Allow-Control-Allow-Origin to share the resources across subdomains.

Or you can utilize this code (updating your domain) to your child theme’s functions.php to automatically share resources across any subdomain:

// Add a policy for allowing assets to each of the subdomains.
function add_cors_http_header() {
    // Get the HTTP origin of the request
    $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';

    // Check if the origin ends with '.martech.zone' or is 'martech.zone'
    if (preg_match('/(\.martech\.zone|martech\.zone)$/', parse_url($origin, PHP_URL_HOST))) {
        header("Access-Control-Allow-Origin: $origin");
    }

    // Other headers
    header("Access-Control-Allow-Methods: GET");
    header("Cache-Control: max-age=604800, public"); // One-week caching
    $expires = gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'; // One-week expiration
    header("Expires: $expires");
    header("Vary: Accept-Encoding");
}
add_action('init', 'add_cors_http_header');
Exit mobile version