Merge pull request #5616 from NodeBB/auto-lang
Automatically detect user language based on browser accepts headerv1.18.x
commit
081578c7f4
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"language-settings": "Language Settings",
|
"language-settings": "Language Settings",
|
||||||
"description": "The default language determines the language settings for all users who are visiting your forum. <br />Individual users can override the default language on their account settings page.",
|
"description": "The default language determines the language settings for all users who are visiting your forum. <br />Individual users can override the default language on their account settings page.",
|
||||||
"default-language": "Default Language"
|
"default-language": "Default Language",
|
||||||
|
"auto-detect": "Auto Detect Language Setting for Guests"
|
||||||
}
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
var nconf = require('nconf');
|
||||||
|
var request = require('request');
|
||||||
|
|
||||||
|
var meta = require('../src/meta');
|
||||||
|
|
||||||
|
describe('Language detection', function () {
|
||||||
|
it('should detect the language for a guest', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/config', {
|
||||||
|
headers: {
|
||||||
|
'Accept-Language': 'de-DE,de;q=0.5',
|
||||||
|
},
|
||||||
|
}, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.ok(body);
|
||||||
|
|
||||||
|
assert.strictEqual(JSON.parse(body).userLang, 'de');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing when disabled', function (done) {
|
||||||
|
meta.configs.set('autoDetectLang', 0, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
|
||||||
|
request(nconf.get('url') + '/api/config', {
|
||||||
|
headers: {
|
||||||
|
'Accept-Language': 'de-DE,de;q=0.5',
|
||||||
|
},
|
||||||
|
}, function (err, res, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.ok(body);
|
||||||
|
|
||||||
|
assert.strictEqual(JSON.parse(body).userLang, 'en-GB');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue