-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Comments
cc @brillout |
@ailectra Does the updated docs https://vike.dev/lang answer your question?
I agree that'd be nice. I think we can only be backwards compatible for |
Yes the updated doc totally answers my question. Thank you. |
👍 Btw. we're looking for sponsors, in case that's something your company is up for. |
In previous versions, thanks to the
getLang()
function, I could use theonBeforeRoute
hook to dynamically set the application's language withpageContext.lang
. This approach allowed for flexible language management based on various conditions. However, after a recent update, it seems thatgetLang()
has been replaced bygetHeadSetting()
. This new function, as it currently stands, solely fetches the language information frompageContext.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
andonRenderHtml
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:
getHeadSetting("lang", pageContext)
.pageContext.lang
."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?
The text was updated successfully, but these errors were encountered: