Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lingui extract doesn't handle i18n._ strings #1178

Closed
juanluispaz opened this issue Dec 14, 2021 · 5 comments · Fixed by #1309
Closed

Lingui extract doesn't handle i18n._ strings #1178

juanluispaz opened this issue Dec 14, 2021 · 5 comments · Fixed by #1309

Comments

@juanluispaz
Copy link

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" }
@semoal
Copy link
Contributor

semoal commented Dec 14, 2021

Hola Juan,

To get extracted you have to use the t`` macro. In that way the babel-plugin-extract-messages can know which value has to extract, the i18n it's used to interpolate between locales, plurals etc..

Since v3, you don't need to use i18n you can just use directly the macro.

For example:

import { t } from "@lingui/macro"

export default function App() {
   return t`This should be translated!`
}

@juanluispaz
Copy link
Author

Hi,

The macros are wonderful, but in the context where I'm using this it is not possible till we finish the migration and we can drop the restriction.

@tannerlyons
Copy link
Contributor

@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.

@borjaMiralles
Copy link

I can confirm that this workaround works, thanks @tannerlyons

@stale
Copy link

stale bot commented Mar 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants