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.

Cannot extract using i18n.plural : undefined is not iterable!

See original GitHub issue

Hello, we use lingui v2.9.2 and we got issue extracting using i18n.plural:

This works:

export function _(
  id: MessageDescriptor | string,
  values?: Record<string, unknown>,
  messageOptions?: MessageOptions
): string {
  if (typeof id === 'string') {
    return i18n._(id, values, messageOptions)
  }
  return i18n._(id)
}

This fail:

export function _(id: MessageDescriptor | PluralProps): string {
  return !Object.prototype.hasOwnProperty.call(id, 'one')
    ? i18n._(id as MessageDescriptor)
    : i18n.plural(id as PluralProps)
}

It fails when we run lingui extract --clean, with the following error:

TypeError: src/libs/i18n.ts: undefined is not iterable!
    at module.exports.require.getIterator (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-runtime/node_modules/core-js/library/modules/core.get-iterator.js:5:42)
    at Transformer.transformChoiceMethod (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@lingui/babel-plugin-transform-js/transformer.js:199:56)
    at Transformer.transformMethod (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@lingui/babel-plugin-transform-js/transformer.js:393:21)
    at PluginPass.Transformer.transform (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/@lingui/babel-plugin-transform-js/transformer.js:69:25)
    at newFn (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/home/dka/workspace/github.com/pass-culture/pass-culture-app-native/node_modules/babel-traverse/lib/context.js:108:19) {
  _babel: true
}

We rather use the synthax of i18n.plural instead of i18n._, how can this be fixed ?

Reproduction

git clone https://github.com/pass-culture/pass-culture-app-native.git
cd pass-culture-app-native
nvm use
yarn
yarn run translations:extract

Related issues

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
semoalcommented, Apr 9, 2021

Quick update:

One thing we can’t fix without breaking others users, it’s not stripping spaces at the end of strings.

Not inmediately fix

For example this case:

<Text>{t`EAN\u00a0`}</Text>

Should be like this if you want that space, or " ":

<Text>{t`EAN`}{\u00a0}</Text>

A suggestion is to add a configuration property to lingui like trimTranslations: true/false, but i’ve need some time this weekend to develop this technique.

Inmediately fix

Pending for your side confirmation

  • When you can tell me if we fixed the unicode chars in Production.

Pending for my side

  • I’m going to check asap if I can resolve the warning about can’t use functions as child
1reaction
kopax-polyconseilcommented, Apr 8, 2021

Thanks, I was still working on my boilerplate, so I am giving up. I will try to see if there’s a way to start the application without those keys to see if we can investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: undefined is not iterable (cannot read property ...
In my case, the error was happening simply because the array I was iterating over had undefined as it's ...
Read more >
Plurals - i18next documentation
How to find the correct plural suffix? You can use this small utility to get the correct plural suffixes. Or try translation-check, it...
Read more >
ChangeDetection - Comparison of: Bean Validation specification
Anynot use of the Specification and the information described therein ... The lifecycle of a constraint validation implementation instance is undefined.
Read more >
Objects - Docassemble
The objects block declares that user is an instance of the class Individual . Objects have “attributes.” In the above example, name is...
Read more >
https://svn.python.org/projects/external/Jinja-2.1...
By default two example extensions exist: an i18n and a cache extension. ... name.value not in variables: parser.fail('unknown variable %r for pluralization' ...
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