js-lingui: i18n._ does not format values in production build

Describe the bug When using i18n._ with the second argument “values” those values are not inserted into the string in production build, but they are inserted into the string in development when running npm run start.

To Reproduce I have created a sample repository that can be used to reproduce the problem:

https://github.com/nmoinvaz/lingui-values-bug

Relevant code file: https://github.com/nmoinvaz/lingui-values-bug/blob/main/src/App.js

  • npm install
  • npm run start

In development the strings are properly replaced:

image

  • npm build
  • serve -s build

In production the strings are not properly replaced:

image

Expected behavior The values object should be inserted into the string. For example {a} should be replaced with 1.

Additional context

  • ling-ui version 3.9.0
  • Create React App

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27 (22 by maintainers)

Most upvoted comments

Screenshot 2021-06-14 at 19 40 31

Production build with remoteLoader():

    const compiledMessages = remoteLoader({
      messages: {
        "abc": "{a} hello {b} world {c} goodbye",
        "xyz": "123"
      }
    })
    i18n.load("en", compiledMessages);

Figured it out, works like a charm in development and production builds! Thank you.

Released with 3.10.3 with:

import { remoteLoader } from "@lingui/remote-loader"

Once I get free 10 minutes, I’ll write a section in the documentation

Polish some details and I’ll release a new version with this new tool

Hm, should be instant give it a try to 3.10.4, just released a fix about remoteLoader. Should be already available

I explained to you, why it fails in the previous comment. It won’t work as simply .json because Lingui doesn’t accept that, they need to be compiled.

I’m working on this feature (since someone requested it too), and this feature could be possibly just using the remoteLoader utility function

I am not using catalogs with string extraction because in my use case the localization files are loaded dynamically.