Js-lingui: @lingui/cli v3 extract extracts no messages

Created on 19 Jun 2020  Β·  10Comments  Β·  Source: lingui/js-lingui

Describe the bug
When I run yarn lingui extract the po files gets created in the correct location, but they contain no messages, only header lines.

To Reproduce

  • This is a Expo (react-native) project.
  • Using @lingui/react for useLingui hook only.
  • Using only macros, no @lingui/react components.
import { Trans, t } from "@lingui/macro"

export default function App() {
   return (<View>
     <Trans>Tohle pΕ™eloΕΎ!</Trans>
     <Button title=t`ZavΕ™Γ­t` />
   </View>)
}

Running command yarn lingui extract with following output:

yarn run v1.22.4
$ /<my project dir>/node_modules/.bin/lingui extract
(use "yarn lingui extract" to update catalogs with new messages)
(use "yarn lingui compile" to compile catalogs for production)
Done in 0.74s.

Po files are created, but contain only header lines as follows:

$ cat assets/locale/cs.po 
msgid ""
msgstr ""
"POT-Creation-Date: 2020-06-19 15:20+0200\n"
"Mime-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: @lingui/cli\n"
"Language: cs\n"
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Plural-Forms: \n"

Expected behavior
Messages should be extracted into po files. Extraction worked with v2 cli.

Additional context

  • jsLingui version yarn lingui --version
    3.0.0-13
  • Babel version npm list @babel/core
β”œβ”€β”€ @babel/[email protected] 
└─┬ [email protected]
  β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”‚ └── @babel/[email protected]  extraneous
  β”‚ β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”‚ └── @babel/[email protected]  extraneous
  β”‚ β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”‚ └── @babel/[email protected]  extraneous
  β”‚ β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”‚ └── @babel/[email protected]  extraneous
  β”‚ β”œβ”€β”¬ @babel/[email protected]
  β”‚ β”‚ └── @babel/[email protected]  extraneous
  β”‚ └─┬ @babel/[email protected]
  β”‚   └── @babel/[email protected]  extraneous
  └─┬ [email protected]
    β”œβ”€β”¬ @babel/[email protected]
    β”‚ └── @babel/[email protected]  extraneous
    └─┬ @babel/[email protected]
      └── @babel/[email protected]  extraneous
  • Babel config (e.g. .babelrc) or framework you use (Create React App, Meteor, etc.)
$ cat babel.config.js 
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['macros'],
  };
}
  • This is my .linguirc
{
   "locales": [ "cs", "en", "de", "pl" ],
   "catalogs": [
    {
      "path": "assets/locale/{locale}",
      "include": [ "js", "App.js" ],
    },
   ],
   "format": "po",
   "sourceLocale": "cs"
}

I am aware v3 is not in production. Does that mean extraction don't work yet? https://github.com/lingui/js-lingui/issues/334

I have seen this bug, but it seems to be related to v2 and react components.
https://github.com/lingui/js-lingui/issues/415

Thanks in advance

Most helpful comment

@kub1x Released in 3.0.3. Cheers πŸ‘

All 10 comments

Hey @kub1x,
this might be bug that @lingui/cli doesn't correctly recognize yoru babel config. What if you have a simple static file instead of function, e.g:

// .babelrc
{
    "presets": ['babel-preset-expo'],
    "plugins": ['macros'],
}

@tricoder42 You're absolutely right! Changing babel config from module to JSON did the trick. Thank you very much.

Also closing as I think this solution just does the trick and is now documented. Guess if someone really needs the module format of babel config to work, it might be reopened then.

Sadly after some time I tried to run yarn lingui extract again now with lingui v3.0.0 and JSON form of .babelrc but with no result again. .po files get created, but contain no extracted messages, only headers. I'm reopening as it is exactly the same symptoms as before. Only this time I see a nice table at the end, stating nothing got extracted.

% yarn lingui extract --verbose
yarn run v1.22.10
$ /.../lingui-noextract-repro/node_modules/.bin/lingui extract --verbose
Extracting messages from source files…
Catalog statistics for assets/locales/{locale}/messages: 
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Language    β”‚ Total count β”‚ Missing β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ en (source) β”‚      0      β”‚    -    β”‚
β”‚ cs          β”‚      0      β”‚    0    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

(use "yarn lingui extract extract" to update catalogs with new messages)
(use "yarn lingui extract compile" to compile catalogs for production)
✨  Done in 1.07s.

I did try to put content of .babelrc into .linguirc's extractBabelOptions property. Same result.

Here is the repro repository. Just clone and run yarn, yarn lingui extract and look into assets directory.
https://github.com/kub1x/lingui-noextract-repro

This might be some stupid thing, but I feel like I've been looking everywhere.

Missing trailing slash in your include paths. Without slash the path is treated as a file, not directory

```diff
{
"locales": [ "cs", "en", "de", "pl" ],
"catalogs": [
{
"path": "assets/locale/{locale}",
- "include": [ "js", "App.js" ],
+ "include": [ "js/", "App.js" ],
},
],
"format": "po",
"sourceLocale": "cs"
}

@tricoder42 Did you try it after the fix? It didn't help for me. Still no messages gets extracted. There is also one message in App.js that wouldn't be affected by the config error you mentioned. I've pushed the js/ fix in the repro repo and thank you for the catch. But it is not fixed.

You're right, the root cause is that there're multiple paths. I've already fixed the bug and waiting for CI #803. Will release soon

@tricoder42 confirmed. That did it. Thanks!

@kub1x Released in 3.0.3. Cheers πŸ‘

@tricoder42, the extraction also fails with only one path (using .linguirc of documentation, for example): "include": ["src"].
If I change it for "include": ["src/"], translations are correctly extracted.
I'm using:

  • Lingui 3.0.3
  • CRA 4.0

This is mistake in docs. Directories must always end with slash

On 1. 11. 2020 22:57 +0100, MediaXtend notifications@github.com, wrote:

@tricoder42, the extraction also fails with only one path (using .linguirc of documentation, for example): "include": ["src"].
If I change it for "include": ["src/"], translations are correctly extracted.
I'm using:

β€’ Lingui 3.0.3
β€’ CRA 4.0

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Was this page helpful?
0 / 5 - 0 ratings