-
Notifications
You must be signed in to change notification settings - Fork 21
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
🐛[Bug]local is not working. #60
Comments
@devisscher Is this likely to be cured? |
Hi @Yamashou, we tried reproducing this issue, it seems the locale is properly set when using it in an example app. Do you have any additional information on how you reproduced this? (Codesandox or code examples?) You can refer to this as an example: https://github.com/Shopify/discount-app-components/blob/main/src/stories/foundation/Provider.tsx - please let us know if you're still encountering the issue. |
@devisscher |
@devisscher |
@devisscher |
I've seen the same thing as well. We're using a Vite build, but it appears to be due to the way languages are imported in the import(
/* webpackChunkName: "DiscountAppComponents-i18n", webpackMode: "lazy-once" */
`/../../../../../../locales/${locale}.json`).then(dictionary => { That results in attempting to fetch import(`/node_modules/@shopify/discount-app-components/locales/${locale}.json`).then(dictionary => { That loads for me in a standard Vite build by attempting to fetch Perhaps there's some configuration that needs to be modified to make that work with Vite vs webpack (which that code seems to be referencing). |
After some tinkering, it seems like it may need to be left up to the consumer of this library to decide how to load in the translations. I think it'll be very difficult to make this library support dynamically loading translations that works with the various build tools out there (e.g., Webpack, Vite, Rollup, etc.). Perhaps there's a mechanism where a consumer can provide them directly to the provider similar to what is done in Polaris with the <PolarisAppProvider i18n={enPolarisTranslations}> In the Vite world, this allows us to build a map of all translations: const LOCALES = import.meta.glob('../../node_modules/@shopify/polaris/locales/*.json'); And then dynamically import them as needed: async loadPolarisTranslation(locale) {
const translations = await LOCALES[`../../node_modules/@shopify/polaris/locales/${locale}.json`]();
return translations;
} Once we have the translations for the current locale, we are able to pass them into the I created a fork and tried implementing a rudimentary version of this here. It's usage within Vite is something like this: import { AppProvider } from '@shopify/discount-app-components';
// The exact path for these will depend where your node_modules is.
// This example assumes the SomeComponent file lives in the root-project-folder/src/components folder.
const LOCALES = import.meta.glob('../../node_modules/@shopify/discount-app-components/locales/*.json');
function discountTranslations(locale) {
return LOCALES[`../../node_modules/@shopify/discount-app-components/locales/${locale}.json`]();
}
export default function SomeComponent({ locale, timezone, children }) {
return (
<AppProvider locale={locale} ianaTimezone={timezone} translationsFn={discountTranslations}>
{children}
</AppProvider>
);
} The example commit I gave is backwards compatible and falls back to the webpack chunk loading if no |
@mbaumbach I solved the problem by copying |
Issue summary
The language is not localized by AppProvider. AppProvider does not localize the language. No matter which language is specified, the display will always be in English. I have specified the following
Expected behavior
I hope that the language in the component will be Japanese!
Actual behavior
Always in English
Steps to reproduce the problem
Reduced test case
The best way to get your bug fixed is to provide a reduced test case. This CodeSandbox template is a great starting point.
Specifications
Or run
npx envinfo --system --binaries --browsers --npmPackages react,react-dom,@shopify/discount-app-components
to provide specifications on your environment including version numbers, browser, device, and operating system.Paste the results here:
The text was updated successfully, but these errors were encountered: