I am working on a react native app build with Typescript, and I'm using react-i18next
and i18next
for translation. This is my i18next-scanner
config:
var fs = require("fs");var path = require("path");var typescript = require("typescript");function typescriptTransform(options) { options = options || {}; if (!options.extensions) { options.extensions = [".tsx"]; } return function transform(file, enc, done) { const extension = path.extname(file.path); const parser = this.parser; let content = fs.readFileSync(file.path, enc); if (options.extensions.indexOf(extension) !== -1) { content = typescript.transpileModule(content, { compilerOptions: { target: 'es2018' }, fileName: path.basename(file.path) }).outputText; parser.parseTransFromString(content); parser.parseFuncFromString(content); } done(); };};module.exports = { options: { defaultLng: 'en', debug: true, func: { list: ['t', 'i18next.t', 'i18n.t'], extensions: ['.js', '.jsx', '.ts', '.tsx'] }, trans: { component: 'Trans', extensions: ['.js', '.jsx'], }, transform: typescriptTransform({ extensions: ['.ts', '.tsx'] }), lngs: ['en', 'nl'], ns: ['account', 'common'], defaultNs: 'common', resource: { loadPath: 'app/{{ns}}/i18n/{{lng}}.json', savePath: 'app/{{ns}}/i18n/{{lng}}.json', }, }};
The problem is that the scanner doesn't pick up the use of this.props.t
. It works if I use i18n.t
and i18next.t
, but we want to stick with this.props.t
which was used from the beginning. One reason that we want to use this.props.t
is because it's the only one that works with storybook
. Using the other two functions just shows the key in the stories.
Any suggestion for fixing the i18next-scanner
config (or something else), to make the scanning of the code pick up uses of this.props.t
is much appreciated. Thanks in advance!