diff options
author | Iván Eixarch <miao.org@gmail.com> | 2012-12-04 12:12:58 +0100 |
---|---|---|
committer | Iván Eixarch <miao.org@gmail.com> | 2012-12-04 12:12:58 +0100 |
commit | 5f949b8457154d5b75a79765565977e8cbdf1e8a (patch) | |
tree | 04f107ca06282605b585e33d705fbc8be8f64293 /src/node/hooks | |
parent | b21c4403b2c9fa34b8913effeabb71484af075fb (diff) | |
download | etherpad-lite-5f949b8457154d5b75a79765565977e8cbdf1e8a.zip |
Update language4translatewiki 0.1.3
Diffstat (limited to 'src/node/hooks')
-rw-r--r-- | src/node/hooks/i18n.js | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/src/node/hooks/i18n.js b/src/node/hooks/i18n.js index 3589dfb2..882e5156 100644 --- a/src/node/hooks/i18n.js +++ b/src/node/hooks/i18n.js @@ -1,4 +1,4 @@ -var http = require ('http') +var languages = require('languages4translatewiki') , fs = require('fs') , path = require('path') , express = require('express') @@ -10,37 +10,20 @@ var localeIndex = fs.readFileSync(localesPath+'/en.ini')+'\r\n'; exports.availableLangs = {'en': {'nativeName': 'English'}}; -// build availableLangs with translatewiki web API -var request = http.request ('http://translatewiki.net/w/api.php?action=query&meta=siteinfo&siprop=languages&format=json', - function (res) { - var twLangs = ''; - res.setEncoding ('utf8'); - res.on ('data', function (chunk) { twLangs += chunk; }); - res.on ('end', function () { - // twLangs = [{code: 'en', '*': 'English'}...] - twLangs = JSON.parse(twLangs)['query']['languages']; - - 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'; +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' - for (var l = 0; l < twLangs.length; l++) { - var code = twLangs[l]['code']; - if (locale == code) { - var nativeName = twLangs[l]['*']; - exports.availableLangs[code] = {'nativeName': nativeName}; - } - } - }); - }); - }); - }).on ('error', function(e) { - console.error('While query translatewiki API: '+e.message); - }).end(); + // add info language {nativeName, direction} to availableLangs + exports.availableLangs[locale]=languages.getLanguageInfo(locale); + }) +}) + exports.expressCreateServer = function(n, args) { |