summaryrefslogtreecommitdiff
path: root/src/node/hooks/i18n.js
blob: 4d42de048a115516d153584b2f9b418f40a0865c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var languages = require('languages')
  , fs = require('fs')
  , path = require('path')
  , express = require('express')

var localesPath = __dirname+"/../../locales";

// Serve English strings directly with /locales.ini
var localeIndex = fs.readFileSync(localesPath+'/en.ini')+'\r\n';

// add language base 'en' to availableLangs
exports.availableLangs = {en: languages.getLanguageInfo('en')}

fs.readdir(localesPath, function(er, files) {
  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'
    
    // add info language {name, nativeName, direction} to availableLangs
    exports.availableLangs[locale]=languages.getLanguageInfo(locale);
  })
})

exports.expressCreateServer = function(n, args) {

  args.app.use('/locales', express.static(localesPath));
  
  args.app.get('/locales.ini', function(req, res) {
    res.send(localeIndex);
  })
  
}