Alien Road Company

Google Search strives to make information accessible and useful to all users. To help address content gaps when a user queries in their local language, sometimes Google may translate the title link and snippet of a search result for results that aren’t in the language of the search query. A translated result is a Google Search feature that enables users to view results from other languages in their language, and can help publishers reach a larger audience.

Currently, translated results are available for English results to the following languages: Indonesian, Hindi, Kannada, Malayalam, Tamil, Telugu. It’s available on mobile devices with any browser that supports Google Search.

If the user clicks the translated title link, all further user interaction with the page is through Google Translate, which will automatically translate any links followed. By expanding the result, users can view the original title link and snippet, and access the entire page in the original language.

Clicking the translated title link in Google Search leads to a translated page, and expanding the result leads to the original version of the page

Google doesn’t host any translated pages. Opening a page through a translated result is no different than opening any other URL in Google Translate. This means that Javascript on the page is usually supported, as well as embedded images and other page features.If you run an ad network, you may need to take additional action to ensure that your ad network displays correctly after a user clicks a translated result. Learn more about enabling your ad network to work with translation-related Google Search features.

Monitor performance in Search Console 

To monitor clicks and impressions for translated results, you can use the Search Appearance filter in the Performance report.

Opting in or out of translated results

This feature is applicable across all pages and results based on the user’s language. You don’t need to do anything to opt in.

Translated results are like other translation-related features in Google Search. To opt out of all translation features in Google Search, use the notranslate directive:

<meta name="robots" content="notranslate">
<meta name="googlebot" content="notranslate">
HTTP/1.1 200 OK
Date: Tue, 25 May 2010 21:42:43 GMT
(…)
X-Robots-Tag: notranslate
(…)

Google Search offers several translation-related features that enable users to access translated content. If you run an ad network and your ads aren’t working properly on translated web pages, you’ll need to follow the steps in this guide to make sure your ads render or attribute correctly.

Our approach

When users access translated content provided by Google Translate from within search results, Google retrieves the page from the publisher, rewrites the source URL, and translates the web page after the user clicks the translated result.

Convert the Google Translate URL to the original URL

If you run an ad network that relies on the publisher’s source URL, you’ll need to convert the Google Translate URL to make sure your ads are working properly. Follow these steps to decode the publisher’s hostname:

  1. Extract the domain prefix from the hostname, by removing the .translate.goog suffix.
  2. Split the _x_tr_enc parameter by the , (comma) character and save it as encoding_list.
  3. Prepend the value of the _x_tr_hp parameter to the domain prefix, if it exists.
  4. If encoding_list contains 1 and the output begins with 1-, remove the 1- prefix from the output of step 2.
  5. If encoding_list contains 0 and the output begins with 0-, remove the 0- prefix from the output of step 3. If you removed the prefix, set is_idn to true. Otherwise, set is_idn to false.
  6. Replace /\b-\b/ (regex) with the . (dot) character.
  7. Replace the -- (double hyphen) character with the - (hyphen) character.
  8. If is_idn is set to true, add the punycode prefix xn--.
  9. Optional: Convert to Unicode.

Sample JavaScript code for decoding the hostname from a Google Translate URL 

function decodeHostname(proxyUrl) {
  const parsedProxyUrl = new URL(proxyUrl);
  const fullHost = parsedProxyUrl.hostname;
  // 1. Extract the domain prefix from the hostname, by removing the
        ".translate.goog" suffix
  let domainPrefix = fullHost.substring(0, fullHost.indexOf('.'));

  // 2. Split _x_tr_enc parameter by "," (comma), save as encodingList
  const encodingList = parsedProxyUrl.searchParams.has('_x_tr_enc') ?
      parsedProxyUrl.searchParams.get('_x_tr_enc').split(',') :
      [];

  // 3. Prepend value of _x_tr_hp parameter to the domain prefix, if it exists
  if (parsedProxyUrl.searchParams.has('_x_tr_hp')) {
    domainPrefix = parsedProxyUrl.searchParams.get('_x_tr_hp') + domainPrefix;
  }

  // 4. Remove '1-' prefix from the output of step 2 if encodingList contains
  //    '1' and the output begins with '1-'.
  if (encodingList.includes('1') && domainPrefix.startsWith('1-')) {
    domainPrefix = domainPrefix.substring(2);
  }

  // 5. Remove '0-' prefix from the output of step 3 if encodingList contains
  //    '0' and the output begins with '0-'.
  //    Set isIdn to true if removed, false otherwise.
  let isIdn = false;
  if (encodingList.includes('0') && domainPrefix.startsWith('0-')) {
    isIdn = true;
    domainPrefix = domainPrefix.substring(2);
  }

  // 6. Replace /\b-\b/ (regex) with '.' (dot) character.
  // 7. Replace '--' (double hyphen) with '-' (hyphen).
  let decodedSegment =
      domainPrefix.replaceAll(/\b-\b/g, '.').replaceAll('--', '-');

  // 8. If isIdn equals true, add the punycode prefix 'xn--'.
  if (isIdn) {
    decodedSegment = 'xn--' + decodedSegment;
  }
  return decodedSegment;
}

Reconstruct the URL

  1. Using the original page URL, replace the hostname with the decoded hostname.
  2. Remove all _x_tr_* parameters.

Test your code

You can create unit tests for your code using the following table. Given a proxyUrl, the decodeHostname must match the expected value.

The following table can only be used to test the hostname decoding. You’ll need to ensure that the path, fragment, and original parameters of the URL are preserved as is.

proxyUrldecodeHostname
https://example-com.translate.googexample.com
https://foo-example-com.translate.googfoo.example.com
https://foo--example-com.translate.googfoo-example.com
https://0-57hw060o-com.translate.goog/?_x_tr_enc=0xn--57hw060o.com (⚡?.com)
https://1-en--us-example-com/?_x_tr_enc=1en-us.example.com
https://0-en----w45as309w-com.translate.goog/?_x_tr_enc=1xn--en--w45as309w.com (en-⚡?.com)
https://1-0-----16pw588q-com.translate.goog/?_x_tr_enc=0,1xn----16pw588q.com (⚡-?.com)
https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=lllanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk
https://lanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch-co-uk.translate.goog/?_x_tr_hp=www-lwww.llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk
https://a--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-com.translate.goog/?_x_tr_hp=a--xn--xn--xn--xn--xn--------------------------aa-xn-xn-xn-xn-xn-------------aa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com
https://g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b-com.translate.goog/?_x_tr_enc=0&_x_tr_hp=0-xn--g5h3969ntadg44juhyah3c9aza87iiar4i410avdl8d3f1fuq3nz05dg5b.com (?????‍♂️????????????????????.com)

Author

alienroad

Leave a comment

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir