disintegrator / next-with-lingui

A Next.js project that uses LinguiJS for internationalization
MIT License
27 stars 10 forks source link

Fix for compatiblity with the latest version of Lingui #3

Open iaincollins opened 5 years ago

iaincollins commented 5 years ago

Thank you so much for creating this example repository, it was super helpful.

I came across this while looking a for a good way to do isomorphic localisation with serverless with Next.js/React and was unable to run it out of the box - I think due to some breaking changes in Lingui- but it was a really great reference. I thought I'd raise this PR to show how I got it working.

Changes in this PR

Fix compatibility with the latest version of Lingui

Changing the module type and using a string replace in _document.js is obviously hacky, but it seems to work well. I have not done extensive browser testing, but have tried it in Chrome, Firefox and Safari.

Obviously it would be preferable to have either two different build exports or perhaps a UMD module from Lingui but I thought having something that worked (and that worked well with both isomorphic rendering and serverless, which modules like next-i18next do not) might help inform ongoing work like https://github.com/lingui/js-lingui/issues/333

I am very happy to discuss alternative approaches and to make changes if anyone has any better ideas on how to achieve this. :-) I am also interested in collaborating on some of the issues in #1.

Additional example

I am now using this approach on an experimental site, example URLs:

Source: https://github.com/glitchdigital/glitched.news