Search code examples
linguijs

Is it possible to use linguijs in VUE application?


Hello is there a way how to use this library in VUE.js application?

Thank you

I have tried it in VUE application. Followed manual part how to use it in javascript application.

Included @lingui/core and all cli libs from manual.

But I faced these issues:

  • npm run extract > processeed only *.js files, *.vue files was ignored
  • npm run serve > log is full of error like invalid or not found module and so on...

Solution

  • As long Vue SFC files are not a valid javascript, linguijs built-in extractor could not parse and extract messages from them. However, thanks to extendable lingui architecture, it's possible to write custom extractors which would transpile your *.vue files to the plain old-fashioned Javascript.

    The concept is similar to loaders in webpack.

    There is an ongoing work on creating Vue extractor as official LinguiJS package here

    Regarding npm run serve it's most likely because you're trying to use @lingui/macro package where babel-plugin-macros is not enabled in your build pipeline.

    Note that vite-plugin-babel-macros is not supporting *.vue files, that might be a root cause of the problem.

    To learn more about integrating LinguiJS with Vue and Vite, you can refer to this issue for more information and potential solutions.