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

37 lines
1 KiB
JavaScript
Raw Normal View History

2012-12-04 12:12:58 +01:00
var languages = require('languages4translatewiki')
2012-11-10 14:12:17 +01:00
, 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';
2012-12-04 13:02:23 +01:00
exports.availableLangs = {'en': {'nativeName': 'English', 'direction': 'ltr'}};
2012-12-04 12:12:58 +01:00
fs.readdir(localesPath, function(er, files) {
files.forEach(function(locale) {
var ext = path.extname(locale);
locale = path.basename(locale, ext).toLowerCase();
if(locale == 'en' || ext != '.ini') return;
// build locale index
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
2012-12-04 12:12:58 +01:00
// add info language {nativeName, direction} to availableLangs
exports.availableLangs[locale]=languages.getLanguageInfo(locale);
})
})
2012-11-28 04:02:55 +01:00
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
})
}