I have 15 pages that use server side rendering in NextJS. I also have configured internationalization using NextJS’ standard internationalizations setup. In NextJS, I can get the current selected locale on the server side of things by grabbing the context
parameter inside of the getServerSideProps()
function – ie:
export async function getServerSideProps(context){
console.log(context.locale);
}
My server side pages all call a service, which calls a class, which then calls a helper function. This helper function that they all eventually call is only ever used on the server side.
Instead of passing context.locale
from getServerSideProps()
in all 15 pages (then passing the locale
to the class then to the helper function), is there a way for me to grab the locale in the helper function itself?