Google Apps Script error with i18next module

I am writing my project in ES6 and am currently facing a problem with the i18next module. https://www.i18next.com/

On my local system, when I import i18next import i18next from 'i18next'; and use it in my source files, everything works. However, after running npm run gulp (it combines all the source files into a single javascript file - main.js) and tries to load this code into the Google Apps script (using gapps upload ), it does not work with a Bad Request. Upload failed. error Bad Request. Upload failed. Bad Request. Upload failed. .

After checking on the Internet, I found that this error means that something is wrong with the syntax, so I tried to copy the code from main.js into google apps script and it displays the following syntax error:

Invalid property id. (Line 32, file "main")

Line 32:

 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 

This error occurs even if I import only the i18next module without doing anything with it.

Here is my 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']); }); 

Also tried using the i18n module, not working.

I want to use a text module for my translations, I do not need to configure the currency / date format. Just a text getter from translation files. It is impossible to use json po or any other extension (I will need to upload everything as one file in GAS, I don’t think they allow any files except .js)

my template files look like en.js :

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

just found a working solution!

after trying all the internationalization libraries and getting various errors related to gas and money, the node-polyglot module worked for me!

Still don't know why i18next is not working though

+5
source

Support for Google Apps Script for ES6 is limited. As far as I understand, GAS does not include any features introduced on ES5 and ES6.

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

Basic JavaScript Features

Script applications are based on JavaScript 1.6, plus several features from 1.7 and 1.8. Thus, many basic JavaScript functions are available in addition to the built-in and advanced Google services: you can use common objects such as Array, Date, RegExp, etc., As well as global Math and Object objects. However, since Apps Script runs on Google’s servers (not on the client side, with the exception of the HTML service pages), browser-based features such as DOM manipulation or window APIs are not available.

According to the Mozilla Developer Network , JavaScript 1.6 is compliant with ECMAScript 3 (ES3).

+1
source

Source: https://habr.com/ru/post/1268860/


All Articles