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.

svelte-i18n cli extract - Typescript support?

See original GitHub issue

Describe the bug Extracting translations with svelte-i18n extract src/lib/components/Footer.svelte fails when declaring variable with Typescript’s type. Tried with --configDir /home/user/work/booking/web as well.

Logs See stacktraces.

To Reproduce This will fail:

<script lang="ts">
     import { _ } from 'svelte-i18n';

     export let name: string;
</script>
{$_('test')}

This works:

<script lang="ts">
     import { _ } from 'svelte-i18n';
</script>
{$_('test')}

Expected behavior Expect it to work the same in both cases mentioned.

Stacktraces

Stack trace

$ /home/user/work/booking/web/node_modules/.bin/svelte-i18n extract src/lib/components/Footer.svelte /home/user/work/booking/web/node_modules/svelte/compiler.js:16675 const error = new CompileError(message); ^

CompileError [ParseError]: Unexpected token at error (/home/user/work/booking/web/node_modules/svelte/compiler.js:16675:20) at Parser$1.error (/home/user/work/booking/web/node_modules/svelte/compiler.js:16753:10) at Parser$1.acorn_error (/home/user/work/booking/web/node_modules/svelte/compiler.js:16747:15) at Object.read_script [as read] (/home/user/work/booking/web/node_modules/svelte/compiler.js:8799:17) at tag (/home/user/work/booking/web/node_modules/svelte/compiler.js:15701:34) at new Parser$1 (/home/user/work/booking/web/node_modules/svelte/compiler.js:16712:22) at Object.parse$I [as parse] (/home/user/work/booking/web/node_modules/svelte/compiler.js:16844:21) at collectMessages (/home/user/work/booking/web/node_modules/svelte-i18n/dist/cli.js:186:26) at extractMessages (/home/user/work/booking/web/node_modules/svelte-i18n/dist/cli.js:218:5) at /home/user/work/booking/web/node_modules/svelte-i18n/dist/cli.js:269:9 { code: ‘parse-error’, start: { line: 4, column: 20, character: 78 }, end: { line: 4, column: 20, character: 78 }, pos: 78, filename: undefined, frame: “2: import { _ } from ‘svelte-i18n’;\n” + ‘3: \n’ + ‘4: export let name: string;\n’ + ’ ^\n’ + ‘5: \n’ + ‘6: </script>’ }

Information about your project:

"svelte": "^3.44.0",
"svelte-preprocess": "^4.10.7",
"@sveltejs/adapter-auto": "^1.0.0-next.83",
"@sveltejs/kit": "^1.0.0-next.516",
"vite": "^3.1.0",

  • Ubuntu 22.04

  • svelte-i18n version 3.4.1

Additional context Is there some option I’m missing, or is this a bug? Thank you!

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
petrsieglcommented, Nov 22, 2022

Yes, it works perfectly! Thank you so much for your help. Amazing work! 🥇

0reactions
kaisermanncommented, Nov 22, 2022

Can you try again with v3.5.1? I’ve tested in your repro and it worked as expected 🙏 We were missing a small thing while loading the “svelte.config.js” file

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Step-by-Step Guide to Svelte Localization | Phrase
Here's how to implement Svelte localization! ... Let's get to it! ... install Svelte is through the npx degit command from the command...
Read more >
svelte-i18n/extract.ts at main - GitHub
Internationalization library for Svelte. ... svelte-i18n/src/cli/extract.ts ... eslint-disable @typescript-eslint/no-non-null-assertion */.
Read more >
Svelte i18n Internationalization: how to localize a Svelte app
In this article, we will take you through a step-by-step guide on how to perform Svelte internationalization or “i18n”.
Read more >
svelte-i18n - npm
svelte -i18n uses stores to keep track of the current locale, dictionary of messages and the main format function. This way, we keep...
Read more >
Svelte <3 TypeScript
It's been by far the most requested feature for a while, and it's finally here: Svelte officially supports TypeScript.
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