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.

Lingui extract doesn't handle i18n._ strings

See original GitHub issue

Describe the bug Lingui extract ignores i18n._

To Reproduce

import { i18n } from "@lingui/core"

export default function App() {
   return i18n._('This should be translated!')
}

Expected behavior The text should appear in the .po file

Additional context I review the source code and I found the function isI18nMethod defined at babel-plugin-extract-messages but it looks like is never used.

  • jsLingui version 3.12.1
  • Babel version 7.16.0
  • Your Babel config (.babelrc): .babelrc { "presets": [ "@babel/preset-env", "@babel/preset-react", "@lingui/babel-preset-react", "@babel/preset-typescript" ] }
  • Lingui config (.linguirc) .linguirc { "locales": ["en", "es", "de"], "sourceLocale": "en", "catalogs": [{ "path": "<rootDir>/src/app-react/locales/{locale}/translations", "include": ["<rootDir>/src/app-react"], "exclude": ["**/node_modules/**"] }], "format": "po-gettext", "compileNamespace": "ts" }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
tannerlyonscommented, Dec 20, 2021

@juanluispaz , you can use this workaround:

import { i18n } from "@lingui/core"

export default function App() {
   return i18n._(/*i18n*/ "This should be translated!");
}

The extractor uses /*i18n*/ as a marker for things to extract.

1reaction
borjaMirallescommented, Jan 4, 2022

I can confirm that this workaround works, thanks @tannerlyons

Read more comments on GitHub >

github_iconTop Results From Across the Web

lingui/js-lingui - Gitter
When I run lingui compile it doesn't compile strings for my pseudoLocale which is registered in the config. The culprit seems to be...
Read more >
lingui-react - npm
The simplest i18n component is Trans. It's used for simple, singular translations. It supports both variables and inline components. Suppose we ...
Read more >
Working with LinguiJS CLI
@lingui/cli provides the lingui command for extracting, ... The extract command looks for messages in the source files and extracts them: yarn extract....
Read more >
React i18n break lines in JSON String - Stack Overflow
I did set the text directly and it doesn't work either. I'm setting the text for the dialog via props. You think that...
Read more >
How to Localize JavaScript and React Apps with LinguiJS
Its simple syntax makes it easy to get started with, and should be familiar for users of other React i18n libraries. Lingui uses...
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