Js-lingui: How to handle SSR

Created on 21 Sep 2018  路  6Comments  路  Source: lingui/js-lingui

I really like this library, but I have some problems getting it to work as I like using SSR (with nextjs).
Basically, what I want is to render only the messages of the requested locale and have SSR do it's work.
Using Nextjs I can use a getInitialProps function, but the data is required to be serializable and that's where the problem comes in; the compiled bundles contain pluralization functionality.

I think my three options are:

  • ignore pluralization
  • include all messages on the client (I don't want to do this)
  • include the pluralization library in the client

Am I missing something? Any help/ideas would be appreciated.

wontfix

Most helpful comment

Hey @tkvw,
SSR is something which needs to be figured out. @disintegrator made an example with Next.js https://github.com/disintegrator/next-with-lingui. I'm going to review it and it'll be added to Next.js examples.

Right now I can't help you much because I don't have any knowledge at all with SSR. I'll get back to you once I review that example and try it on my own.

All 6 comments

Hey @tkvw,
SSR is something which needs to be figured out. @disintegrator made an example with Next.js https://github.com/disintegrator/next-with-lingui. I'm going to review it and it'll be added to Next.js examples.

Right now I can't help you much because I don't have any knowledge at all with SSR. I'll get back to you once I review that example and try it on my own.

@tricoder42 : thanks for the reply. For now I've opted for option 1. When I'll have time I'll create an example how I solved it.

Hi guys,

Have you encountered any progress on this topic?

@tricoder42 I can't find your Next.js example anywhere. Is it up yet?

Cheers

@cJayyy https://github.com/disintegrator/next-with-lingui

This is my attempt at figuring it out with @tricoder42. He left some notes about it worth reading: https://github.com/disintegrator/next-with-lingui/issues/1

@disintegrator

Hey,
Thanks for pointing out. I've seen your repo but didn't notice the note from @tricoder42 .
Based on those is there any upgrade coming up to your example?

/ I am really grateful for your implementation but I am wondering if it's wise to use it on production. I am pretty new to react and it's SSR possibilities therefore I can't really see-through your example and fully understand it.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings