-
Notifications
You must be signed in to change notification settings - Fork 21
Feat [Shopify]: Internationalization Support for Shopify Loaders and Queries #1371
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
5e586d0
5cc3c6d
ce35c85
f0178dd
0ae284a
0220c31
1110e3a
5f8bb0b
fff74a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ import { | |
| QueryRootCollectionArgs, | ||
| QueryRootSearchArgs, | ||
| SearchResultItemConnection, | ||
| LanguageCode, | ||
| CountryCode | ||
| } from "../utils/storefront/storefront.graphql.gen.ts"; | ||
| import { toProduct } from "../utils/transform.ts"; | ||
| import { | ||
|
|
@@ -21,7 +23,7 @@ import { | |
| searchSortShopify, | ||
| sortShopify, | ||
| } from "../utils/utils.ts"; | ||
| import { Metafield } from "../utils/types.ts"; | ||
| import { LanguageContextArgs, Metafield } from "../utils/types.ts"; | ||
|
|
||
| export interface QueryProps { | ||
| /** @description search term to use on search */ | ||
|
|
@@ -70,6 +72,18 @@ export type Props = { | |
| * @description search for metafields | ||
| */ | ||
| metafields?: Metafield[]; | ||
| /** | ||
| * @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; | ||
| }; | ||
|
|
||
| // deno-lint-ignore no-explicit-any | ||
|
|
@@ -92,6 +106,8 @@ const loader = async ( | |
|
|
||
| const count = props.count ?? 12; | ||
| const metafields = expandedProps.metafields || []; | ||
| const languageCode = expandedProps?.languageCode ?? "PT"; | ||
| const countryCode = expandedProps?.countryCode ?? "BR"; | ||
|
Comment on lines
+109
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π§© Analysis chainVerify the hardcoded Portuguese/Brazil defaults. The defaults to
Hardcoded locale defaults could deliver incorrect localized content to international users. Would you like to verify if there's a specific reason for the PT/BR defaults, or should these default to π Script executed: #!/bin/bash
# Examine ProductList.ts file context around lines 109-110
cat shopify/loaders/ProductList.ts | head -130 | tail -50Length of output: 1425 π Script executed: #!/bin/bash
# Search for expandedProps initialization and definition
rg -n "expandedProps" shopify/loaders/ProductList.ts -B5 -A5Length of output: 2856 π Script executed: #!/bin/bash
# Search for any configuration or settings related to languageCode/countryCode
rg -n "languageCode|countryCode" shopify/loaders/ProductList.ts -B3 -A3Length of output: 1177 π Script executed: #!/bin/bash
# Look for environment variables or config files that might set these defaults
fd -e "config\|env\|settings" -type f | head -20Length of output: 170 π Script executed: #!/bin/bash
# Search for comments or documentation about PT/BR choice in the file
rg -n "PT|BR|Portuguese|Brazil|locale|language|country" shopify/loaders/ProductList.ts -B2 -A2Length of output: 850 π Script executed: #!/bin/bash
# Search for README, docs, or comments explaining the PT/BR choice
find . -maxdepth 2 -type f \( -name "README*" -o -name "*.md" \) | xargs grep -l "PT\|BR\|Portuguese\|Brazil\|locale\|language\|country" 2>/dev/null | head -10Length of output: 109 π Script executed: #!/bin/bash
# Search entire codebase for any configuration or context about locale defaults
rg -n "languageCode.*PT|countryCode.*BR|PT.*BR" --type-add "config:*.{json,yaml,yml,toml,env}" -t config -t ts -t js 2>/dev/null | head -20Length of output: 92990 π Script executed: #!/bin/bash
# Check if there's an AppContext or global config that might set these
rg -n "AppContext|LanguageCode|CountryCode" shopify/ -l | head -10Length of output: 299 Document or reconfigure the hardcoded PT/BR locale defaults. The defaults for Either:
|
||
|
|
||
| let shopifyProducts: | ||
| | SearchResultItemConnection | ||
|
|
@@ -119,15 +135,18 @@ const loader = async ( | |
| }); | ||
|
|
||
| if (isQueryList(props)) { | ||
|
|
||
| const data = await storefront.query< | ||
| QueryRoot, | ||
| QueryRootSearchArgs & HasMetafieldsMetafieldsArgs | ||
| QueryRootSearchArgs & HasMetafieldsMetafieldsArgs & LanguageContextArgs | ||
| >({ | ||
| variables: { | ||
| first: count, | ||
| query: props.query, | ||
| productFilters: filters, | ||
| identifiers: metafields, | ||
| languageCode, | ||
| countryCode, | ||
| ...searchSortShopify[sort], | ||
| }, | ||
| ...SearchProducts, | ||
|
|
@@ -139,12 +158,15 @@ const loader = async ( | |
| & QueryRootCollectionArgs | ||
| & CollectionProductsArgs | ||
| & HasMetafieldsMetafieldsArgs | ||
| & LanguageContextArgs | ||
| >({ | ||
| variables: { | ||
| first: count, | ||
| handle: props.collection, | ||
| filters, | ||
| identifiers: metafields, | ||
| languageCode, | ||
| countryCode, | ||
| ...sortShopify[sort], | ||
| }, | ||
| ...ProductsByCollection, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.