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

Already on GitHub? Sign in to your account

Request with no "accept-language" header #2

Closed
knation opened this Issue Jan 24, 2013 · 2 comments

Comments

Projects
None yet
3 participants

knation commented Jan 24, 2013

"preferredLocale" function in i18n.js fails when there is no accept-language header. Proposed fix:

preferredLocale: function(req) {
        req = req || this.request;

        if (!req || !req.headers) {
            return;
        }

        var accept = req.headers["accept-language"],
            self = this,
            prefLocale;

        if (accept) {
            accept.match(/(^|,\s*)([a-z]+)/g).forEach(function(locale) {
                if (!prefLocale && self.locales[locale]) {
                    prefLocale = locale;
                }
            });
        } else {
            prefLocale = self.defaultLocale;
        }

        return prefLocale;
    }

sylvinus commented Feb 2, 2013

I've fixed this and another undefined variable issue here:
sylvinus/i18n-node-2@85ffea9

Waiting for John to check my previous PR before submitting a new one!

This should have been fixed now

@jeresig jeresig closed this Mar 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment