-
Notifications
You must be signed in to change notification settings - Fork 91
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
i18n: pass locale to shop-api #104
Comments
I will investigate in it |
thanks gioboa, i have tried add "locale" to the option of requester, it works, but i don't think it's the best way to do the job because we are obliged to add locale option to many api calls...
|
@redaready, have you tried setting the locale in a Cookie just like it's done with the Vendure token? You might be facing |
with some help of sourcegraph cody: That error means you are calling getLocale() outside of a Qwik component or route. getLocale() relies on Qwik's locale context, so it can only be called within a Qwik component/route. Some options to fix this: Pass the locale as an argument to the function instead of calling getLocale():
Wrap the call in a Qwik component:
Use a Qwik route and access the locale from the request event:
Store the locale in a variable outside of the Qwik context and pass that in:
Hope this helps resolve your error! Let me know if you have any other questions. |
@giovramirez i think locale is a little bit diffrent with token, token is generated by vendure and then stored in cookie, locale on other hand, we must pass it to sdk calls at first invocations (ex: useCollectionsLoader and useAvailableCountriesLoader etc)... so i think we have no other choice than pass locale parameter to many sdk calls :-( |
You're right @redaready. Besides, we can't use a Cookie since most of the calls are executed on the server, so it's not an option to get the locale from Cookie. We have this interceptor where we can get the locale, store it outside of the Qwik context and use it globally within the app. However, I think for better readability of the codebase your approach of passing the locale parameter to every sdk looks better. @gioboa any thoughts on this matter? |
I need to investigate into the problem, I will look at it in few days. You are more then welcome to suggest a solution with a PR |
my approach was a global config variable for currencyCode and use it here
|
This sounds reasonable to me 👍 |
can we change locale per request in this way? sometimes storefront has a Language Selector component, we need to get locale value from request context(cookie, path, or header) to call api. i think the locale value proprity chain could be
|
Yep, if we change the path with a variable we can do whatever we want |
@redaready we did as you mentioned storing the user selection in a cookie and updating the client-side global config on changes. vendure backend already supports it and there was an issue here that came up with this approach which has been fixed |
Hi @gioboa sir , search in default vendure do not work with the search can we change startegy or query or make some multilingual search pugin same error in showing plugin in collection as it use search producxt gql to display product. , if we can work on it any suggestion or anything from your side |
@redaready did you solve this issue? If yes, how did you pass the locale to the vendure calls? |
Hi sir , the only solution in my opinion is to make a new search plug-in that support language , I will make plug-in for type sense and try to use to get language in search |
is there a way to pass the locale value of "extractLang(request.headers.get('accept-language'), request.url)" to shop-api call?
i have tried something like this, but a error raised: "Internal server error: Reading
locale
outside of context."The text was updated successfully, but these errors were encountered: