问题描述
我正在尝试从Shopify商店获取第二语言的产品。
Storefront API声明HTTP请求标头必须包含Accept-Language:de,就我而言(在React中),设置应如下所示: https://shopify.dev/tutorials/manage-app-translations-with-admin-api#storefront-api-translation-header
const clientWithTranslatedContent = Client.buildClient({
domain: 'your-shop-name.myshopify.com',storefrontAccesstoken: 'your-storefront-access-token',language: 'de' // Accept-Language
});
如何工作,您可以在这里找到: https://github.com/Shopify/js-buy-sdk/blob/update-language-setting/src/client.js
我正在使用Shopify Webhook API版本2020-07(最新)。在gatsbyjs/gatsby#24173(注释)中,我找到了以下信息:在2020-04版中,Accept-Language标头支持翻译,但在我的情况下不起作用。
在构建应用程序时,我总是收到带有默认翻译(EN)的商品。
解决方法
该问题是由在gatsby-node.js中生成页面的“ gatsby-source-shopify”插件引起的。它没有考虑HTTP请求标头中的Accept-Language。为了解决该问题,我的团队完成了此插件的安装。
以下是链接: https://github.com/alex-borodin-vtlabs/gatsby-source-shopify-translated