2012-11-28 04:02:55 +01:00
|
|
|
var Globalize = require('globalize')
|
2012-11-10 14:12:17 +01:00
|
|
|
, fs = require('fs')
|
|
|
|
, path = require('path')
|
2012-11-14 17:01:59 +01:00
|
|
|
, express = require('express')
|
2012-11-10 14:12:17 +01:00
|
|
|
|
2012-11-14 17:01:59 +01:00
|
|
|
var localesPath = __dirname+"/../../locales";
|
|
|
|
|
2012-11-17 14:33:01 +01:00
|
|
|
// Serve English strings directly with /locales.ini
|
|
|
|
var localeIndex = fs.readFileSync(localesPath+'/en.ini')+'\r\n';
|
|
|
|
|
2012-11-20 19:46:17 +01:00
|
|
|
// add language base 'en' to availableLangs
|
2012-11-28 04:02:55 +01:00
|
|
|
exports.availableLangs = {};
|
|
|
|
exports.availableLangs['en'] = Globalize.cultures['en'];
|
2012-11-14 17:01:59 +01:00
|
|
|
|
|
|
|
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;
|
2012-11-12 18:04:21 +01:00
|
|
|
|
2012-11-14 17:01:59 +01:00
|
|
|
// build locale index
|
|
|
|
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
|
|
|
|
|
2012-11-28 04:02:55 +01:00
|
|
|
require('globalize/lib/cultures/globalize.culture.'+locale+'.js')
|
|
|
|
exports.availableLangs[locale]=Globalize.cultures[locale];
|
2012-11-10 14:12:17 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2012-11-28 04:02:55 +01:00
|
|
|
console.log(exports.availableLangs);
|
|
|
|
|
2012-11-10 14:12:17 +01:00
|
|
|
exports.expressCreateServer = function(n, args) {
|
|
|
|
|
2012-11-14 17:01:59 +01:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2012-11-20 19:46:17 +01:00
|
|
|
}
|