Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Notation: Cannot read property 'indexOf' of undefined #377

Open
mrgcl opened this issue Jul 4, 2018 · 1 comment
Open

Object Notation: Cannot read property 'indexOf' of undefined #377

mrgcl opened this issue Jul 4, 2018 · 1 comment

Comments

@mrgcl
Copy link

mrgcl commented Jul 4, 2018

I'm using Express + Handlebars with the library.
When I enable objectNotation, the project crashes. With object notation disabled, regular key/value pairs work just fine.

Relevant code:

i18n.configure({
    locales: availableLocales,
    defaultLocale: 'en',
    directory: __dirname + '/locales',
    cookie: 'locale',
    objectNotation: true
});

app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.png'))); // TODO: ver por que no funciona
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.engine('hbs', hbs.__express);
app.use(cookieParser());
app.use(i18n.init);
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

hbs.registerHelper('__', function () {
    return i18n.__.apply(this, arguments);
});
hbs.registerHelper('__n', function () {
    return i18n.__n.apply(this, arguments);
});

app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);

Route

router.get('/', function(req, res) {
    res.render('index', {});
});

Template

<p>{{{__ "this.is.nested"}}}</p>

Locale

{
    "this": {
        "is": {
            "nested": "whatever"
        }
    }
}

Error message:

TypeError: /Users/mrg/WebstormProjects/myproj/views/error.hbs: Cannot read property 'indexOf' of undefined
    at translate (/Users/mrg/WebstormProjects/myproj/node_modules/i18n/i18n.js:862:34)
    at Object.i18nTranslate (/Users/mrg/WebstormProjects/myproj/node_modules/i18n/i18n.js:220:13)
    at Object.<anonymous> (/Users/mrg/WebstormProjects/myproj/app.js:33:20)
    at Object.eval [as main] (eval at createFunctionContext (/Users/mrg/WebstormProjects/myproj/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:66)
    at main (/Users/mrg/WebstormProjects/myproj/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
    at ret (/Users/mrg/WebstormProjects/myproj/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
    at ret (/Users/mrg/WebstormProjects/myproj/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)
    at /Users/mrg/WebstormProjects/myproj/node_modules/hbs/lib/hbs.js:87:17
    at /Users/mrg/WebstormProjects/myproj/node_modules/hbs/lib/hbs.js:69:11
    at Object.done (/Users/mrg/WebstormProjects/myproj/node_modules/hbs/lib/async.js:74:20)
@lxinghe
Copy link

lxinghe commented Jul 26, 2021

Just encountered the same issue today in 2021. You have to turn that feature on by specifying the field "objectNotation" to be true in the configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants