【问题标题】:React-Shopify Translations | How to get products in a second language from ShopifyReact-Shopify 翻译 |如何从 Shopify 获取第二语言的产品
【发布时间】:2020-09-25 10:30:34
【问题描述】:

我正在尝试从 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) 的商品。

【问题讨论】:

    标签: shopify gatsby language-translation gatsby-plugin shopify-storefront-api


    【解决方案1】:

    问题是由在 gatsby-node.js 中生成页面的“gatsby-source-shopify”插件引起的。它不考虑 HTTP 请求标头中的 Accept-Language。为了解决这个问题,我的团队已经完成了这个插件。

    这是一个链接: https://github.com/alex-borodin-vtlabs/gatsby-source-shopify-translated

    【讨论】:

    • 感谢您分享您的发现。我也在做类似的事情,我的 Shopify 前端是无头店面(React.js)。我想以 2 种语言显示产品数据。我可以使用 Shopify Storefront API 在店面获取翻译吗?
    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 2017-09-20
    • 1970-01-01
    • 2012-06-16
    • 2022-10-20
    相关资源
    最近更新 更多