i18next-scanner: component in Typescript files is no longer parsed
This is most probably caused by dfd5db12262ac404ba4cb6414c6e7f6312de14bb (2.6.2)
Version
- i18next: 11.3.6
- i18next-scanner: 2.6.3
Configuration
{
options: {
debug: "true",
lngs: ["en"],
attr: false,
func: {
extensions: [".ts", ".tsx"],
list: ["t", "props.t", "i18n.t"],
},
trans: {
extensions: [".ts", ".tsx"],
fallbackKey: true,
},
keySeparator: false,
nsSeparator: false,
},
}
Sample file
// test.tsx
import * as React from "react"
import { Trans } from "react-i18next"
const TestComp: React.SFC = () => (
<div className="test-comp">
<h3>
<Trans>This is a test</Trans>
</h3>
</div>
)
Result
“This is a test” is not present in the output. The strings using the t()
helper function are still correctly extracted.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 11
- Comments: 37 (17 by maintainers)
@beheh I think it might be useful if we can provide built-in support for transpiling TypeScript to ES5 if the file extension is
.ts
or.tsx
.I made package from @peitschie comment. Feel free to PR. https://github.com/nucleartux/i18next-scanner-typescript
Works very well thank you.
Also, make sure you have not put any
['.ts', '.tsx']
extensions from within the options, which would display the same error messageand not
This is still an issue, Any plan to make it happen? 😃
I have also experienced problems when using decorators.
I’m having the same problem with v2.6.5, I had to reverse to v2.6.1 because
acorn-jsx-walk
is not working forTrans
components. I don’t use typescrypt, I’m using ES6 for my code so that’s the “problem”. Here’s my example on a.jsx
file:On version
<=2.6.1
that would show up on my language files, and now it’s not. I don’t think this issue should be marked as an enhacement, this is a bug that broke things for many people.For anyone looking for hints towards a typescript solution, it appears possible using the typescript compiler api: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
An untested example of a custom transform function might be something like:
@messerm @daliusd and for those interested I’ve proposed a patch for the latest
acorn-jsx
in #112If you can’t wait, try
npm install @contentpass/i18next-scanner
.Would be curious to hear if this solves your issues as well.
I have the same problems described above for pure JavaScript code where we use object decomposition
{...ohterObject}
. I was checking the code and found thatacorn-jsx-walk
is 3 years old and still uses onacorn-jsx@3.0.0
. I wonder whether it would be worth to switch a more recent walker which works with the latest version ofacorn-jsx@5.0.1
?Edit: I see this is what @daliusd basically proposed in his latest post 😃.
This (almost) works with newer babel: plugins: [ ‘@babel/plugin-syntax-jsx’, ‘@babel/plugin-proposal-class-properties’, ‘@babel/plugin-proposal-object-rest-spread’, ‘@babel/plugin-transform-spread’, ‘@babel/plugin-transform-arrow-functions’, ],
Remaining problem is that acorn-jsx stops on JSX comments, e.g.
{/* comment *.}
. Maybe newest acorn version would solve the problem.what i’ve ended up doing, is to transpile typescript -> js to a temp directory, and run the scanner on it.