Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script error with i18next module

I am writing my project in ES6, and currently facing an issue with 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 I run npm run gulp (it combines all source files into one javascript file - main.js) and try to upload that code to Google Apps script (using gapps upload), it fails with a Bad Request. Upload failed. error.

After checking online I found out that this error means that there is something wrong with the syntax, so I tried to copy paste the code from main.js into google apps script and it shows 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 only import the i18next module without actually 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 to use the i18n module, doesnt work.

I want to use a get text module for my translations, dont need a currency/date format customisations. Just a text getter from translation files. Cannot use json po or any other extension (I will need to upload all as one file to GAS, dont think they allow any files other than .js)

my template files are like this en.js:

const res = {
  template: {
    "signIn":"Hello, <@#1>! Signed you in (#2)",
    ...
  },
  command: {
    "signIn": "hi",
    ...
  }
};
export default res;
like image 222
Nodir Rashidov Avatar asked Jun 15 '17 05:06

Nodir Rashidov


2 Answers

just found the working solution!

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

Still do not know the reason why i18next isnt working though

like image 151
Nodir Rashidov Avatar answered Oct 18 '22 05:10

Nodir Rashidov


Google Apps Script support for ES6 is limited. As I understand, GAS doesn't include any features introduced on ES5 and ES6.

From 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.

According to Mozilla Developer Network, JavaScript 1.6 corresponds to ECMAScript 3 (ES3).

like image 20
Rubén Avatar answered Oct 18 '22 03:10

Rubén