How to divide the state by selected language?

Hello developers!

I translate my Frontity site using the Polylang plugin, and create a separate version of each post for each language.
In order not to load all posts in all languages in the initial state, I need to filter them on the backend by some parameter in $ _REQUEST / $ _COOKIE.

Is there some way to pass the selected language from the user localStorage or cookies on the client to the initial request on the server?

Sorry but it seems I’ve found solution :slight_smile:

beforeCSR: ({ state, actions }) => {

  if (typeof window !== 'undefined' && typeof window.localStorage['frontity_lang'] !== 'undefined') {
    state.source.params.lang = window.localStorage['frontity_lang']

No, it doesn’t work :confused:

I see that it is possible to pass the language through “?frontity_lang” get parameter and get it on the server as follows.

beforeSSR: async ({ state, libraries, actions }) => {

  state.source.params.lang = typeof state.frontity.options.lang !== 'undefined' ? state.frontity.options.lang : 'en_US';

It remains to figure out how to transfer the language to this property programmatically.

Found a solution :partying_face:
Cookies can be obtained from Koa ctx in beforeSSR, then I pass language to request

state.source.params.lang = ctx.cookies.get('abc_lang');
1 Like