此.props.t未被带有Typescript的react本机项目中的i18next扫描程序拾取
我正在使用Typescript开发react本机应用程序,并使用此.props.t未被带有Typescript的react本机项目中的i18next扫描程序拾取,typescript,react-native,i18next,react-i18next,Typescript,React Native,I18next,React I18next,我正在使用Typescript开发react本机应用程序,并使用react-i18next和i18next进行翻译。这是我的i18下一个扫描仪config: var fs = require("fs"); var path = require("path"); var typescript = require("typescript"); function typescriptTransform(options) { options = options || {}; if (!
react-i18next
和i18next
进行翻译。这是我的i18下一个扫描仪
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',
},
}
};
问题是扫描仪无法使用this.props.t
。如果我使用i18n.t
和i18next.t
,它会起作用,但我们希望继续使用从一开始就使用的这个.props.t
。我们希望使用this.props.t
的一个原因是,它是唯一一个可以与故事书
一起使用的工具。使用另外两个函数只是在故事中显示关键点
如果您建议修复i18next scanner
config(或其他内容),使代码扫描能够使用this.props.t
,我们将不胜感激。提前谢谢