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
Update to resolve incompatiblity with breaking changes in Lingui
Somewhat hacky approach in _document.js to resolve the issue (changed export type to cjs, use string replace)
Now also checks hostname for the locale (e.g. en.example.com, fr.example.com)
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:
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
en.example.com
,fr.example.com
)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/333I 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