我正在使用 Typescript 构建一个反应原生应用程序,并且我正在使用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
and ,它会起作用i18next.t
,但我们想坚持this.props.t
从一开始就使用哪个。我们想要使用的一个原因this.props.t
是因为它是唯一可以与storybook
. 使用其他两个功能只是显示故事中的关键。
任何有关修复i18next-scanner
配置(或其他)的建议,以使代码的扫描得到使用,this.props.t
我们都非常感谢。提前致谢!