Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Fix for compatiblity with the latest version of Lingui #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iaincollins
Copy link

@iaincollins iaincollins commented May 25, 2019

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 lingui/js-lingui#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

@iaincollins iaincollins mentioned this pull request May 25, 2019
@iaincollins iaincollins changed the title Fix for compatiblity with the latest version of linqui Fix for compatiblity with the latest version of Lingui May 25, 2019
* 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`)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant