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

Access current lang in getStaticProps and getStaticPaths #92

Closed
maksymdukov opened this issue Mar 23, 2020 · 6 comments · Fixed by #93 or #95
Closed

Access current lang in getStaticProps and getStaticPaths #92

maksymdukov opened this issue Mar 23, 2020 · 6 comments · Fixed by #93 or #95
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@maksymdukov
Copy link

maksymdukov commented Mar 23, 2020

I wonder if there's a way to identify current language in exported getStaticProps and getStaticPaths functions to have an ability to fetch localized data?

@aralroca
Copy link
Owner

I'm not sure about some hack, but I guess that is not possible, at least right now.

However, I think that we should change our way to do the build in the CLI in order to provide it, using dynamic routes with [lang]. After that, it should be possible to get the current language via params.

Thank @maksymdukov to report this! This will be very useful for 0.13.0 release 🙂

@aralroca aralroca self-assigned this Mar 23, 2020
@aralroca aralroca added the enhancement New feature or request label Mar 23, 2020
@aralroca aralroca added this to the 0.13.0 milestone Mar 23, 2020
@aralroca
Copy link
Owner

When this issue will be solved vercel/next.js#11309 it will be trivial to wrap the lang to getStaticProps & getServerSideProps 🤞 Meanwhile, I'm going to investigate if there is another way to handle this!

@aralroca
Copy link
Owner

aralroca commented Mar 24, 2020

@maksymdukov from now on, the lang will be available on getStaticProps, getStaticProps and getServerSideProps.

I'm going to explain it better in the docs for 0.13.0 version. But a simple example:

export function getStaticProps({ lang }){
   return { props: { data: getDataFromLang(lang) } }
}

The 0.13.0 release will be available soon. However, I released the 0.13.0-canary.1 with that feature. Please, confirm that 0.13.0-canary.1 works in your case 👏!

https://github.com/vinissimus/next-translate/releases/tag/0.13.0-canary.1

@maksymdukov
Copy link
Author

@aralroca
Wow, that was fast.
It works, many thanks. :)

However there's one rare case which regexp in hasSpecialMethod doesn't cover:
export async function getStaticProps() {}

@aralroca
Copy link
Owner

Good catch!! Thanks, this should be fixed before 0.13.0 release! Thanks!

@aralroca
Copy link
Owner

aralroca commented Mar 24, 2020

@maksymdukov async function syntax should work in 0.13.0-canary.2 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants