this.props.t 在使用 Typescript 的 React Native 项目中没有被 i18next-scanner 拾取

问题描述 投票:0回答:1

我正在使用 Typescript 构建 React Native 应用程序,并且使用

react-i18next
i18next
进行翻译。这是我的
i18next-scanner
配置:

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',
        },
    }
};

问题是扫描仪无法识别

this.props.t
的使用。如果我使用
i18n.t
i18next.t
,它就可以工作,但我们想坚持使用从一开始就使用的
this.props.t
。我们想要使用
this.props.t
的原因之一是因为它是唯一可以与
storybook
配合使用的。使用其他两个功能只是显示故事中的关键。

任何关于修复

i18next-scanner
配置(或其他)的建议,以使代码扫描能够识别
this.props.t
的使用,我们非常感激。预先感谢!

typescript react-native i18next react-i18next
1个回答
0
投票

选项:{ 默认Lng: 'en', 调试:正确, 功能:{ 列表:['t','this.props.t','i18next.t','i18n.t'],

© www.soinside.com 2019 - 2024. All rights reserved.