funktionswerk / hapi-i18n

Translation module for hapi based on mashpie's i18n module
MIT License
39 stars 22 forks source link

While translating the message i got undefined error #9

Closed sivabalan02 closed 7 years ago

sivabalan02 commented 7 years ago

I used glue plugin on my application. Here is my code:

i18n.js:


const register = (server, options, next) => {
server.register(
{
register: require('hapi-i18n'),
options : {locales: ["en"],directory: __dirname + "/../locales",
}
});
next();
};
register.attributes = {name: 'Internationalization'};
module.exports = register;```

en.json:
{
    "GREETING": "Welcome all",
}

In my routes i specified the i18n

```              {
        method : 'POST',
        path   : "/signup",
        config : {
            tags    : ['api'],
            description: 'Customer signup',
            /*validate: {
                options: {
                    abortEarly: false,
                },
                payload: signupSchema,
            }*/
        },
        handler: function(request, response){

            request.i18n.setLocale("en");
            console.log(request.i18n.getLocale());
            console.log(request.i18n.__("GREETING"));
            return response('Signup');
        }
    }```

But i only getting undefined error on it
funktionswerk commented 7 years ago

Can you provide a simplified setup that produces the undefined error? Maybe as a Git repo?

sivabalan02 commented 7 years ago

https://github.com/sivabalan02/hapi-i18n-issue When in call signup api http://localhost:8080/signup its gives undefined error

funktionswerk commented 7 years ago

There is a syntax error in your JSON file (remove the comma): https://github.com/sivabalan02/hapi-i18n-issue/blob/master/api/locales/en.json#L2 This caused a parseError when loading the i18n module. Unfortunately, i18n fails silently without any error message. You can display the logs of i18n by setting the DEBUG environment variable:

export DEBUG=i18n:*
sivabalan02 commented 7 years ago

Thanks funktionswerk. Now its working.