简体   繁体   English

如何根据所选的Google翻译窗口小部件语言显示不同的产品

[英]How to Show Different Products Depending on Google Translate Widget Language Chosen

I am developing a website with shopping cart that will have different products per country. 我正在开发一个带有购物车的网站,每个国家都会有不同的产品。 Customer wants to use Google Translate to change language. 客户希望使用Google翻译更改语言。

We thought one website with different product categories for each country would be best. 我们认为,针对每个国家/地区使用不同产品类别的网站是最好的。 So someone in France chooses FR in Google Translate, and we have some code to show the FR product category. 因此,法国的某人在Google Translate中选择了FR,我们有一些代码来显示FR产品类别。

But I cant find how to determine in my website code (PHP) what language is chosen by the Google Translate Widget. 但是我找不到如何在我的网站代码(PHP)中确定Google翻译窗口小部件选择了哪种语言。 The URL stays the same, so I cannot query the URL. URL保持不变,因此我无法查询URL。

How would one be able to determine at the server level (PHP) what language has been chosen by the Google Translate Widget? 如何才能在服务器级别(PHP)确定Google翻译窗口小部件选择了哪种语言?

I wonder if this is even possible as its probably using Javascript to change it, so would there be other ways to tap into the Google Translate Widget so I could use Javascript to show the correct product category? 我不知道这是否可能,因为它可能使用Java脚本对其进行了更改,是否还有其他方法可以利用Google Translate Widget,以便可以使用Java脚本显示正确的产品类别?

This is the Google Widget Code 这是Google窗口小部件代码

<script type="text/javascript">
function googleTranslateElementInit()
{
    new google.translate.TranslateElement(
    {
        pageLanguage: 'en',
        includedLanguages: 'en,cy',
        layout: google.translate.TranslateElement.InlineLayout.SIMPLE
    },
    'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Thanks 谢谢

This is one way, but not ideal due to horrible hashes in the URL... 这是一种方法,但由于URL中的哈希值太高,因此不理想。

Google can auto translate the page content if you add #googtrans(en|TARGET_LANG_CODE) to the end of the URL, eg www.mydomain.com#googtrans(en|fr) 如果您在网址末尾添加#googtrans(en | TARGET_LANG_CODE),例如Google.mydomain.com#googtrans(en | fr),则Google可以自动翻译页面内容。

So setup a multi-country site like standard, eg /fr, /de etc. (sub-domains could be used or anything in the URL to specify what country, eg ?country=fr). 因此,请设置一个多国网站,例如标准网站,例如/ fr,/ de等(可以使用子域,也可以使用URL中的任何内容指定哪个国家/地区,例如?country = fr)。

Using links to each country section of the site, link to the country section with the hash on the end, eg www.mydomain.com/fr#googtrans(en|fr) or fr.mydomain.com#googtrans(en|fr) or www.mydomain.com?country=fr#googtrans(en|fr) 使用到站点每个国家部分的链接,到末尾带有散列的国家部分链接,例如www.mydomain.com/fr#googtrans(en|fr)或fr.mydomain.com#googtrans(en | fr)或www.mydomain.com?country=fr#googtrans(zh_CN)

The country section in the URL, eg /fr allows you to show the correct store for that country (and anything else you want to display for that country, perhaps call different images as Google cant translate those), and then the hash allows Google to translate it to the correct language. 网址中的国家/地区部分,例如/ fr,您可以显示该国家/地区的正确商店(以及该国家/地区要显示的其他任何内容,也可以调用不同的图片,因为Google无法翻译这些图片),然后通过散列,Google可以将其翻译成正确的语言。

Its a horrible hash to use! 它是一个可怕的哈希! Be good if we could not use the hash and just translate based on just /fr (probably can do this using the non-free API but this is just for the free widget). 如果我们不能使用哈希并仅基于/ fr进行翻译,那就很好了(可能可以使用非免费API来做到这一点,但这仅适用于免费小部件)。

Note: Its probably necessary to exclude the country sections eg /fr from being indexed in Google, because I would hazard a guess Google may see the original language content on these sub-sections before its JS translation kicks in, so we would not want that duplicate content. 注意:可能有必要将国家/地区部分(例如/ fr)排除在Google的索引之外,因为我可能会猜测Google在开始JS翻译之前可能会在这些子部分中看到原始语言内容,因此我们不希望这样重复内容。 I do not believe Google indexes the widget translated pages, so just disallow these sections in the robots.txt file. 我不相信Google会为小部件的翻译页面编制索引,因此请在robots.txt文件中禁止这些部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM