Skip to content

Feat [Shopify]: Internationalization Support for Shopify Loaders and Queries #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

yuriassuncx
Copy link
Contributor

@yuriassuncx yuriassuncx commented Apr 11, 2025

What is this Contribution About?

This PR introduces internationalization (i18n) support for the main Shopify queries and loaders used in Deco.cx. With this update, it's now possible to dynamically pass languageCode and countryCode values via the @inContext directive, allowing the Shopify Storefront API to return localized content for different languages and regions.


🧩 How It Works

✅ Loaders

Most loaders now accept the following optional props:

/**
 * @title Language Code
 * @description Language code for the storefront API
 * @example "EN" for English, "FR" for French, etc.
 */
languageCode?: LanguageCode;

/**
 * @title Country Code
 * @description Country code for the storefront API
 * @example "US" for United States, "FR" for France, etc.
 */
countryCode?: CountryCode;

These values are passed as variables to GraphQL queries and injected using the @inContext directive.


✅ Queries

All core Shopify queries have been refactored to use GraphQL variables in the @inContext directive (instead of interpolated JavaScript), making them fully compatible with GraphQL tooling and static code analysis like GraphQL Codegen.

Example:

query GetProduct(
  $handle: String, 
  $identifiers: [HasMetafieldsIdentifier!]!,
  $languageCode: LanguageCode,
  $countryCode: CountryCode
) @inContext(language: $languageCode, country: $countryCode) {
  product(handle: $handle) {
    ...Product
  }
}

On the TypeScript side, the variables are passed like this:

variables: {
  handle,
  identifiers: metafields,
  languageCode,
  countryCode,
}

🛠 Affected Queries

This pattern has been applied consistently across the following queries:

  • ListProducts
  • SearchProducts
  • ProductsByCollection
  • ProductRecommendations
  • GetProduct (and related queries)
  • Shop
  • Cart

These changes improve maintainability, tooling support (e.g., GraphQL Codegen), and ensure proper localization behavior across storefront queries.

🌍 Impact

  • Native internationalization support: Enables fully localized storefront experiences based on user preferences or geolocation.
  • Global readiness: Makes it easier to scale storefronts across multiple markets without duplicating logic.
  • Backward compatible: All new props are optional, ensuring existing implementations won’t break.
  • Improved DX (Developer Experience): Unified and transparent use of inContext across queries and loaders.

Loom Video

https://www.loom.com/share/8a8f204de9a745528ac2f84f44f428fa

Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.73.1 update
  • 🎉 for Minor 0.74.0 update
  • 🚀 for Major 1.0.0 update

@yuriassuncx yuriassuncx force-pushed the feat-shopify/inContext branch from 83ee56c to 735ee41 Compare May 16, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant