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

Cannot extract message keys build by string interpolation #89

Closed
cbenz opened this issue Sep 11, 2020 · 2 comments · Fixed by #106
Closed

Cannot extract message keys build by string interpolation #89

cbenz opened this issue Sep 11, 2020 · 2 comments · Fixed by #106
Assignees
Labels
bug Something isn't working

Comments

@cbenz
Copy link

cbenz commented Sep 11, 2020

When running svelte-i18n extract as documented here on a file that formats a message with $_ using a message key build by string interpolation or concatenation, the CLI tool crashes with an exception.

There is such a message key in the Sapper template for svelte-i18n: $_('languages.' + item.replace('-', '_')) (source).

How to reproduce:

$ git clone https://github.com/kaisermann/sapper-template-i18n.git
$ npm install
$ ./node_modules/.bin/svelte-i18n extract "src/components/Nav.svelte"
(node:1180263) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
    at /home/cbenz/Dev/vendor/sapper-template-i18n/node_modules/svelte-i18n/dist/cli.js:17:2801
    at Array.forEach (<anonymous>)
    at h (/home/cbenz/Dev/vendor/sapper-template-i18n/node_modules/svelte-i18n/dist/cli.js:17:2644)
    at Command.<anonymous> (/home/cbenz/Dev/vendor/sapper-template-i18n/node_modules/svelte-i18n/dist/cli.js:17:4131)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1180263) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:1180263) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I've tried with some other patterns that also fail with the same exception:

$('key.' + value)
$(`key.${value}`)

Expected behavior: the message extractor could display a warning, and skip this message key. I understand that it can't guess all the possible values of the string interpolation.

I'm using:

  • node v14.2.0 (Arch Linux)
  • svelte-i18n 3.0.4 (latest version at the time I write the issue)
@kaisermann
Copy link
Owner

kaisermann commented Nov 6, 2020

Hey, @cbenz 👋 Fixed in 3.2.3 🎉 However, I didn't add any kind of warning/log for now.

@cbenz
Copy link
Author

cbenz commented Nov 6, 2020

Wow, that awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants