2017-06-15 38 views
5

我在ES6中編寫我的項目,目前正面臨i18next模塊的問題。 https://www.i18next.com/使用i18next模塊的Google Apps腳本錯誤

在我的本地系統上,當我導入i18next import i18next from 'i18next';並在我的源文件中使用它時,一切正常。但是,在我運行npm run gulp(它將所有源文件合併爲一個JavaScript文件 - main.js)並嘗試將該代碼上傳到Google Apps腳本(使用gapps upload)後,它會失敗,並顯示Bad Request. Upload failed.錯誤。

在線檢查後,我發現這個錯誤意味着有一些錯誤的語法,所以我試圖複製粘貼main.js代碼到谷歌Apps腳本,它顯示了以下語法錯誤:

Invalid property ID. (Line 32, file "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']); 
}); 

還試圖用國際化的模塊,不工作。

我想爲我的翻譯使用獲取文本模塊,不需要貨幣/日期格式自定義。只需從翻譯文件中獲取文本。不能使用JSON PO或任何其他分機(我需要上傳的所有作爲一個文件來氣,不認爲他們能夠比.js文件以外的任何文件)

我的模板文件都是這樣en.js

const res = { 
    template: { 
    "signIn":"Hello, <@#1>! Signed you in (#2)", 
    ... 
    }, 
    command: { 
    "signIn": "hi", 
    ... 
    } 
}; 
export default res; 

回答

5

剛剛找到工作解決方案!

在嘗試了所有的國際化庫並獲得各種天然氣和nongas相關錯誤後,node-polyglot模塊爲我工作!

仍然不知道爲什麼i18next心不是工作雖然

+1

真的很奇怪......知道這個問題的路線原因很有意思。 – jamuhl

+0

是的!我在i18next回購上創建了一個問題,但被告知我應該聯繫谷歌應用腳​​本,因爲這個問題可能與他們的方面有關。在應用程序腳本支持頁面上創建了一個問題,但沒有得到回覆 – JapanGuy

+0

@jamuhl哦,我剛剛意識到這是你在github上跟我說的。感謝您的幫助!我在我的其他基於瀏覽器的項目上有i18next工作!這很棒! – JapanGuy

1

爲ES6谷歌Apps腳本的支持是有限的原因。據我瞭解,GAS不包括ES5和ES6上引入的任何功能。

https://developers.google.com/apps-script/guides/services/#basic_javascript_features

Basic JavaScript features

Apps Script is based on JavaScript 1.6, plus a few features from 1.7 and 1.8. Many basic JavaScript features are thus available in addition to the built-in and advanced Google services: you can use common objects like Array, Date, RegExp, and so forth, as well as the Math and Object global objects. However, because Apps Script code runs on Google's servers (not client-side, except for HTML-service pages), browser-based features like DOM manipulation or the Window API are not available.

根據Mozilla Developer Network,JavaScript的1.6對應於ECMAScript的3(ES3)。

+0

我不知道這個,謝謝!但我認爲我的gulpfile將我的源代碼轉換爲javascript(不知道哪個版本)。而且我使用了幾個不同的節點模塊,並且僅在國際化模塊中出現語法錯誤(在應用程序腳本上)。其他一切按預期工作 – JapanGuy