question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack loader for message catalogs

See original GitHub issue

My goal is to load my messages without manually compiling (lingui compile) them during development. I don’t have a problem manually compiling them for a production build but having to do it manually after every change to the files is cumbersome.

I used create-react-app and ejected it to be able to add the lingui-react babel preset, which means I’m using webpack. I couldn’t find a webpack loader to watch and compile the catalogs.

I’m also a little confused about the lingui-i18n/dev package. I assumed I could use it to load my messages.json files and create catalogs from it on the fly, but from the tutorial it seems that I have to load the compiled .js catalogs anyway.

Is there an easy way to achieve what I want?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
tricoder42commented, Oct 16, 2018

Hey @pybuche, if you use @lingui/loader, you don’t have to run lingui compile manually. Loader actually creates production ready compiled catalogs.

These two import statements are identical:

// importing source catalog through loader
import fr from '@lingui/loader!conf/locale/fr/messages.json'
// importing compiled catalog
import fr from 'conf/locale/fr/messages.js'
2reactions
tricoder42commented, Nov 22, 2017

Just release lingui-loader@0.1.0. This is first release, please consider it experimental. I tried it with webpack example and it works fine. I’m releasing it early to get feedback as soon as possible.

Quickstart

  1. Install it
npm install --dev lingui-loader
  1. Load JSON message catalog using this loader:
import catalog from 'lingui-loader!locale/en/messages.json'

// catalog must be unpacked before passing to I18nProvider
<I18nProvider catalog={{ en: unpackCatalog(catalog) }} language="en">
...
</I18nProvider>

or using dynamic import

import { unpackCatalog } from 'lingui-i18n'
const catalogs = await import(
      /* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */
      `lingui-loader!../locale/${language}/messages.json`).then(unpackCatalog)

See webpack example.

I’ll add more docs tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference - Webpack Loader (@lingui/loader)
@lingui/loader is a webpack loader, which compiles messages on the fly: ... Simply prepend @lingui/loader: in front of path to message catalog you...
Read more >
lingui/loader
@lingui/loader. webpack loader for compiling message catalog on the fly. @lingui/loader is part of LinguiJS. See the documentation for all ...
Read more >
Webpack-loader | npm.io
Plugin loader for Sanity. Resolves parts based on a declared Sanity manifest and provides infrastructure for loading the required plugins.
Read more >
lingui/js-lingui - Gitter
import(/* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */ @lingui/loader!./locales/${lang}/messages.json ). I get back a catalog with empty ...
Read more >
lingui/loader - npm Package Health Analysis
webpack loader for lingui message catalogs For more information about how to use this package see README. Latest version published 19 days ago....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found