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

35 lines
985 B
JavaScript
Raw Normal View History

2012-11-10 14:12:17 +01:00
var Globalize = require('globalize')
, fs = require('fs')
, path = require('path')
, express = require('express')
2012-11-10 14:12:17 +01:00
var localesPath = __dirname+"/../../locales";
// Serve English strings directly with /locales.ini
var localeIndex = fs.readFileSync(localesPath+'/en.ini')+'\r\n';
exports.availableLangs = {en: 'English'};
fs.readdir(localesPath, function(er, files) {
2012-11-10 14:12:17 +01:00
files.forEach(function(locale) {
locale = locale.split('.')[0]
if(locale.toLowerCase() == 'en') return;
// build locale index
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
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.use('/locales', express.static(localesPath));
args.app.get('/locales.ini', function(req, res) {
res.send(localeIndex);
2012-11-10 14:12:17 +01:00
})
}