Move locale detection to the client
* l10n.js is doing locale detection already, so we shouldn't interfere but help it do its job * this should also fix the ?lang embed parameter * Set language from cookie on page init for l10n to load the right translation
This commit is contained in:
parent
ffb7cf47f2
commit
f5563ab704
|
@ -1,13 +1,21 @@
|
||||||
var Globalize = require('globalize')
|
var Globalize = require('globalize')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
|
, express = require('express')
|
||||||
|
|
||||||
exports.availableLangs = {en: 'English'}
|
var localesPath = __dirname+"/../../locales";
|
||||||
fs.readdir(__dirname+"/../../locales", function(er, files) {
|
|
||||||
|
var localeIndex = '[*]\r\n@import url(locales/en.ini)\r\n';
|
||||||
|
exports.availableLangs = {en: 'English'};
|
||||||
|
|
||||||
|
fs.readdir(localesPath, function(er, files) {
|
||||||
files.forEach(function(locale) {
|
files.forEach(function(locale) {
|
||||||
locale = locale.split('.')[0]
|
locale = locale.split('.')[0]
|
||||||
if(locale.toLowerCase() == 'en') return;
|
if(locale.toLowerCase() == 'en') return;
|
||||||
|
|
||||||
|
// build locale index
|
||||||
|
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
|
||||||
|
|
||||||
require('globalize/lib/cultures/globalize.culture.'+locale+'.js')
|
require('globalize/lib/cultures/globalize.culture.'+locale+'.js')
|
||||||
var culture = Globalize.cultures[locale];
|
var culture = Globalize.cultures[locale];
|
||||||
exports.availableLangs[culture.name] = culture.nativeName;
|
exports.availableLangs[culture.name] = culture.nativeName;
|
||||||
|
@ -16,13 +24,10 @@ fs.readdir(__dirname+"/../../locales", function(er, files) {
|
||||||
|
|
||||||
exports.expressCreateServer = function(n, args) {
|
exports.expressCreateServer = function(n, args) {
|
||||||
|
|
||||||
args.app.get('/locale.ini', function(req, res) {
|
args.app.use('/locales', express.static(localesPath));
|
||||||
// let gloablize find out the preferred locale and default to 'en'
|
|
||||||
Globalize.culture(req.cookies['language'] || req.header('Accept-Language') || 'en');
|
args.app.get('/locales.ini', function(req, res) {
|
||||||
var localePath = path.normalize(__dirname +"/../../locales/"+Globalize.culture().name+".ini");
|
res.send(localeIndex);
|
||||||
res.sendfile(localePath, function(er) {
|
|
||||||
if(er) console.error(er)
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
|
||||||
<script type="text/javascript" src="static/js/l10n.js"></script>
|
<script type="text/javascript" src="static/js/l10n.js"></script>
|
||||||
<link rel="resource" type="application/l10n" href="locale.ini" />
|
<link rel="resource" type="application/l10n" href="locales.ini" />
|
||||||
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -185,6 +185,12 @@
|
||||||
return randomstring;
|
return randomstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(function(document) {
|
||||||
|
// Set language for l10n
|
||||||
|
var language = document.cookie.match(/language=(\w{2})/);
|
||||||
|
document.documentElement.lang = language? language[1] : 'en';
|
||||||
|
})(document)
|
||||||
|
|
||||||
// start the custom js
|
// start the custom js
|
||||||
if (typeof customStart == "function") customStart();
|
if (typeof customStart == "function") customStart();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
|
||||||
|
|
||||||
<script type="text/javascript" src="../static/js/l10n.js"></script>
|
<script type="text/javascript" src="../static/js/l10n.js"></script>
|
||||||
<link rel="resource" type="application/l10n" href="../locale.ini" />
|
<link rel="resource" type="application/l10n" href="../locales.ini" />
|
||||||
|
|
||||||
|
|
||||||
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
||||||
|
@ -399,7 +399,9 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var clientVars = {};
|
var clientVars = {};
|
||||||
(function () {
|
(function () {
|
||||||
|
// Set language for l10n
|
||||||
|
var language = document.cookie.match(/language=(\w{2})/);
|
||||||
|
document.documentElement.lang = language? language[1] : 'en';
|
||||||
|
|
||||||
var pathComponents = location.pathname.split('/');
|
var pathComponents = location.pathname.split('/');
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<meta name="robots" content="noindex, nofollow">
|
<meta name="robots" content="noindex, nofollow">
|
||||||
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
<link rel="shortcut icon" href="<%=settings.favicon%>">
|
||||||
<script type="text/javascript" src="../../static/js/l10n.js"></script>
|
<script type="text/javascript" src="../../static/js/l10n.js"></script>
|
||||||
<link rel="resource" type="application/l10n" href="../../locale.ini" />
|
<link rel="resource" type="application/l10n" href="../../locales.ini" />
|
||||||
<link rel="stylesheet" href="../../static/css/pad.css">
|
<link rel="stylesheet" href="../../static/css/pad.css">
|
||||||
<link rel="stylesheet" href="../../static/css/timeslider.css">
|
<link rel="stylesheet" href="../../static/css/timeslider.css">
|
||||||
<link rel="stylesheet" href="../../static/custom/timeslider.css">
|
<link rel="stylesheet" href="../../static/custom/timeslider.css">
|
||||||
|
@ -184,6 +184,9 @@
|
||||||
var clientVars = {};
|
var clientVars = {};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
// Set language for l10n
|
||||||
|
var language = document.cookie.match(/language=(\w{2})/);
|
||||||
|
document.documentElement.lang = language? language[1] : 'en';
|
||||||
|
|
||||||
var pathComponents = location.pathname.split('/');
|
var pathComponents = location.pathname.split('/');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue