【发布时间】:2017-11-17 10:44:51
【问题描述】:
我正在用 ES6 编写我的项目,目前面临 i18next 模块的问题。 https://www.i18next.com/
在我的本地系统上,当我导入 i18next import i18next from 'i18next'; 并在我的源文件中使用它时,一切正常。但是,在我运行 npm run gulp(它将所有源文件合并到一个 javascript 文件 - main.js)并尝试将该代码上传到 Google Apps 脚本(使用 gapps upload)之后,它失败并出现 Bad Request. Upload failed. 错误。
网上查了发现这个错误说明语法有问题,所以我尝试将main.js中的代码复制粘贴到google apps脚本中,显示如下语法错误:
属性 ID 无效。 (第 32 行,文件“main”)
第 32 行:
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
即使我只导入 i18next 模块而不实际对其进行任何操作,也会发生此错误。
这是我的gulpfile:
import gulp from 'gulp';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import mocha from 'gulp-mocha';
const compileFile = 'main.js';
gulp.task('dest', () => {
browserify({
entries: ['src/'+compileFile]
})
.transform('babelify')
.plugin('gasify')
.bundle()
.pipe(source(compileFile))
.pipe(gulp.dest('dist'));
});
gulp.task('test', () => {
gulp.src('test/**/*.js', {read: false})
.pipe(mocha({
reporter: 'spec',
compilers: 'js:babel-core/register'
}));
});
gulp.task('default', ['test', 'dest'], () => {});
gulp.task('watch', () => {
gulp.watch('src/**/*.js', ['dest']);
});
也试过用i18n模块,不行。
我想使用获取文本模块进行翻译,不需要自定义货币/日期格式。只是翻译文件中的文本获取器。不能使用 json po 或任何其他扩展名(我需要将所有文件作为一个文件上传到 GAS,不要认为他们允许 .js 以外的任何文件)
我的模板文件是这样的en.js:
const res = {
template: {
"signIn":"Hello, <@#1>! Signed you in (#2)",
...
},
command: {
"signIn": "hi",
...
}
};
export default res;
【问题讨论】:
标签: javascript google-apps-script ecmascript-6 i18next