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

Makara 2 with locale from cookie is not localizing templates #77

Closed
ghost opened this issue Oct 7, 2015 · 1 comment
Closed

Makara 2 with locale from cookie is not localizing templates #77

ghost opened this issue Oct 7, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 7, 2015

Hi, I'm following the i18n example and makara 2.0 blog post / docs. but I'm not able to override the fallback locale in my kraken. Probably I'm missing something.

I have my middleware to read locale from cookies and setting it in the res.locals.locale and req.locale .

'use strict';
var bcp47 = require('bcp47');

module.exports = function () {
    return function (req, res, next) {
        var locale = req.cookies && req.cookies.locale;
        //Set the locality for this response. The template will pick the appropriate bundle
        res.locals.locale = req.locale = bcp47.parse(locale);        
        //res.locals.locale = req.locale = locale //I have tried also this 

        next();
    };
};

And in my config.json I have:

"locale": {
    "priority": 95,
    "enabled": true,
    "module": {
        "name": "path:./lib/locale"
    }
}

I have declared a route to set locale cookie into my index.js controller (usage eg: /setLanguage/EN-us )

router.get('/setLocale/:locale', function (req, res) {
    res.cookie('locale', req.params.locale);
    res.redirect('/');
});

The middleware works fine, and sets res.locals.locale and req.locale to the bcp47 object according to the locale cookie value.
But on the template rendering I always get the default locale message, and not my localized message taken from the correct .properties files.

I'm missing something or does it looks correct?

@ghost
Copy link
Author

ghost commented Oct 21, 2015

Actually it works, I was using wrong locale codes, like the one I wrote above: "EN-us".......
Sorry for opening this.

@ghost ghost closed this as completed Oct 21, 2015
This issue was closed.
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

0 participants