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

Updating lang from hooks (onBeforeRoute, onPrerenderStart, ...) #63

Closed
ailectra opened this issue Feb 20, 2024 · 4 comments
Closed

Updating lang from hooks (onBeforeRoute, onPrerenderStart, ...) #63

ailectra opened this issue Feb 20, 2024 · 4 comments

Comments

@ailectra
Copy link

In previous versions, thanks to the getLang() function, I could use the onBeforeRoute hook to dynamically set the application's language with pageContext.lang. This approach allowed for flexible language management based on various conditions. However, after a recent update, it seems that getLang() has been replaced by getHeadSetting(). This new function, as it currently stands, solely fetches the language information from pageContext.configEntries, limiting the dynamic assignment of languages.

Given this change, I propose an enhancement to how language settings are retrieved and set within the onRenderClient and onRenderHtml hooks. Specifically, I suggest the following approach for determining the language setting:

const lang = getHeadSetting("lang", pageContext) || pageContext.lang || "en";

This code snippet aims to provide a fallback mechanism that:

  • Primarily attempts to retrieve the language setting using getHeadSetting("lang", pageContext).
  • If not available, it falls back to pageContext.lang.
  • Defaults to "en" if neither of the above yields a result.

This method would not only restore the flexibility previously offered by getLang() but also align with the current structure, ensuring backward compatibility and enhancing functionality.

Could the maintainers consider this proposal for implementation or provide guidance on how to best handle dynamic language settings under the new system?

@magne4000
Copy link
Member

magne4000 commented Feb 20, 2024

cc @brillout

@brillout
Copy link
Member

@ailectra Does the updated docs https://vike.dev/lang answer your question?

This method would not only restore the flexibility previously offered by getLang() but also align with the current structure, ensuring backward compatibility and enhancing functionality.

I agree that'd be nice. I think we can only be backwards compatible for lang (e.g. not for <head> meta tags). While I see the value of being backwards compatible here, I'm not sure how valuable this would be all-in-all. On the other hand, one issue is that it would make things slightly inconsistent. That said, I don't have a strong opinion here and, for example, if someone is up for creating a PR accross vike-{react,vue,solid} then I'd be up for merging it.

@ailectra
Copy link
Author

Yes the updated doc totally answers my question. Thank you.

@brillout
Copy link
Member

👍 Btw. we're looking for sponsors, in case that's something your company is up for.

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

No branches or pull requests

3 participants