Shopify / ui-extensions

MIT License
268 stars 36 forks source link

Add tags, country ISO code, and language ISO code to extension API #801

Open kylebuildsstuff opened 1 year ago

kylebuildsstuff commented 1 year ago

Please list the related package(s)

"@shopify/checkout-ui-extensions-react": "^0.18.1",

If this related to specific APIs or components, please list them here

useCartLines useExtensionApi (currency, language, extensionLanguage`)

Is your feature request related to a problem? Please describe.

Merchants would like to show extensions based on tag-related logic, internationally. Price conversions and translations with the Storefront API require isoCodes like 'CA' and 'EN' (ISO 639-1 language codes && ISO 3166-1 alpha-2 country codes).

For tags, the app would have to call the StorefrontAPI upon every load because tag data is required before all the other logic.

For internationalization, the current data seems misaligned? Currency returns CAD, language returns en-CA, and extensionLanguage returns en, while the Storefront API returns CA and EN. And according to the docs, the hooks API may not always return data with a dash:

The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code

It's troubling because the @inContext directive requires a strict format and misformatting could be the difference between correct and incorrect translations.

In the meantime, I think this also means calling the Storefront API to fetch internationalization data upon every call is the most reliable way to get the right isoCode format required for the @inContext directive. It'd also be really difficult to test my own mappings across 80+ languages.

Describe the changes you are looking for

For tags, it'd be great to have product tags directly available within useCartLines

For internationalization, it'd be great to have the country code and language code, as given by the StorefrontAPI, available within a hook.

Describe alternatives you’ve considered

Directly calling the Storefront API upon load before further processing app logic.

Screenshots

Screen Shot 2023-03-15 at 3 04 57 PM
jeanffc commented 3 months ago

+1