From 5f949b8457154d5b75a79765565977e8cbdf1e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Eixarch?= Date: Tue, 4 Dec 2012 12:12:58 +0100 Subject: [PATCH] Update language4translatewiki 0.1.3 --- src/node/hooks/i18n.js | 43 +++++++++++++----------------------------- src/package.json | 3 ++- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/node/hooks/i18n.js b/src/node/hooks/i18n.js index 3589dfb29..882e51569 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) { + var ext = path.extname(locale); + locale = path.basename(locale, ext).toLowerCase(); + if(locale == 'en' || ext != '.ini') return; - 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'; + // 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) { diff --git a/src/package.json b/src/package.json index e68053534..d2b03a97a 100644 --- a/src/package.json +++ b/src/package.json @@ -35,7 +35,8 @@ "security" : "1.0.0", "tinycon" : "0.0.1", "underscore" : "1.3.1", - "unorm" : "1.0.0" + "unorm" : "1.0.0", + "languages4translatewiki" : "0.1.3" }, "bin": { "etherpad-lite": "./node/server.js" }, "devDependencies": {