pad.libre-service.eu-etherpad/src/node/hooks/i18n.js

28 lines
946 B
JavaScript
Raw Normal View History

2012-11-10 14:12:17 +01:00
var Globalize = require('globalize')
, fs = require('fs')
, path = require('path')
exports.availableLangs = {en: 'English'}
2012-11-10 14:12:17 +01:00
fs.readdir(__dirname+"/../../locales", function(er, files) {
files.forEach(function(locale) {
locale = locale.split('.')[0]
if(locale.toLowerCase() == 'en') return;
2012-11-10 14:12:17 +01:00
require('globalize/lib/cultures/globalize.culture.'+locale+'.js')
2012-11-12 16:49:15 +01:00
var culture = Globalize.cultures[locale];
exports.availableLangs[culture.name] = culture.nativeName;
2012-11-10 14:12:17 +01:00
})
})
exports.expressCreateServer = function(n, args) {
args.app.get('/locale.ini', function(req, res) {
2012-11-12 16:49:15 +01:00
// let gloablize find out the preferred locale and default to 'en'
Globalize.culture(req.cookies['language'] || req.header('Accept-Language') || 'en');
2012-11-10 14:12:17 +01:00
var localePath = path.normalize(__dirname +"/../../locales/"+Globalize.culture().name+".ini");
res.sendfile(localePath, function(er) {
if(er) console.error(er)
});
})
}