Skip to content
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

feat: add support for working with locale #1594

Merged
merged 1 commit into from
Nov 6, 2022
Merged

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Oct 5, 2022

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Use cases and why

    1. One use case
    1. Another use case

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • Added new tests to cover the fix / functionality

@mhevery mhevery force-pushed the pr-i18n branch 2 times, most recently from 015fab4 to f740a61 Compare October 5, 2022 22:00
@manucorporat
Copy link
Contributor

This PR introduces a new API, which implementation i am not sure it's entirely correct since use methods can only be used in rendering context, what's this for?

@mhevery mhevery changed the title feat: add support for retrieving request headers from Qwik City feat: add support for working with locale Oct 6, 2022
@@ -79,6 +79,17 @@ export const createContainerState = (containerEl: Element) => {
return containerState;
};

const envDataFromContainer = (containerEl: Element): Record<string, any> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envData is not container attributes, we are mixing semantics, not sure i like this, we are telling developers that envData is server only (for now), but it comes from envData, this breaks that semantic

Copy link
Member

@wmertens wmertens Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in our React codebase, we have plugins that can extract server data during render (injecting via <Provider> mosty), and then populate a global state object that gets serialized to the client, which gets read by the Providers on the client.
This has proven very useful, and I think this envData is similar to that.

@@ -268,6 +268,9 @@ export const inlinedQrl: <T>(symbol: T, symbolName: string, lexicalScopeCapture?
// @internal (undocumented)
export const inlinedQrlDEV: <T = any>(symbol: T, symbolName: string, opts: QRLDev, lexicalScopeCapture?: any[]) => QRL<T>;

// @alpha
export const isInUseContext: () => boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would make it @internal is we really need it, the fact that _context is defined does not mean that all use methods will work. Only useLexicalScope() works in all contexts

Copy link
Member

@wmertens wmertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • how can one set the first part of the URL to the locale?
  • how can one change the locale in the browser without losing state, e.g. while filling in a form?

Comment on lines 140 to 147
export function getQwikCityEnvData(
requestHeaders: Record<string, string>,
userResponse: UserResponseContext,
mode: QwikCityMode
): {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to switch this to an object argument to allow adding parameters in the future?

@@ -21,6 +26,8 @@ export function pageHandler<T = any>(
const { status, headers } = userResponse;
const { response } = requestCtx;
const isPageData = userResponse.type === 'pagedata';
const requestHeaders: Record<string, string> = {};
requestCtx.request.headers.forEach((value, key) => (requestHeaders[key] = value));
Copy link
Member

@wmertens wmertens Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have something similar in our React codebase, but we allow registering functions that extract environment data from a request object.

This way, more than headers can be used to set the environment data, it avoids having to copy all headers, and it allows running the render without a request object, like when you're rendering a PDF or in tests.

@DustinJSilk
Copy link
Contributor

This is great, it also solves a PR I sent to get access to request headers.

@mhevery mhevery force-pushed the pr-i18n branch 2 times, most recently from 2d4a344 to 4bc9186 Compare November 1, 2022 17:09
@mhevery mhevery changed the title feat: add support for working with locale feat: add support for working with lang Nov 1, 2022
@mhevery mhevery enabled auto-merge (squash) November 1, 2022 17:28
@mhevery mhevery disabled auto-merge November 1, 2022 17:30
@mhevery mhevery changed the title feat: add support for working with lang feat: add support for working with locale Nov 6, 2022
@mhevery mhevery dismissed manucorporat’s stale review November 6, 2022 22:56

solved per request

@mhevery mhevery enabled auto-merge (squash) November 6, 2022 22:57
@mhevery mhevery merged commit 2ffa6a6 into QwikDev:main Nov 6, 2022
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.

4 participants