translations

This commit is contained in:
Meutel 2014-06-29 12:50:28 +02:00
parent f0fba98124
commit a90653c421
3 changed files with 205 additions and 16 deletions

View File

@ -0,0 +1,46 @@
{
"bouquins": {
"homeTitle": "Library",
"homeGreetings": "Browse library",
"authors": "Authors",
"books": "Books",
"series": "Series",
"recent": "Last updates",
"previous": "Previous",
"next": "Next",
"empty": "Empty",
"cols": {
"booktitle": "Title",
"bookauthors": "Author(s)",
"bookserie": "Serie",
"authorname": "Name",
"authorbooks": "Books",
"seriename": "Name",
"serieauthors": "Author(s)",
"seriebooks": "Books"
},
"nav": {
"home": "Home",
"books": "Books",
"authors": "Authors",
"series": "Series"
},
"book": {
"download": "Download",
"authors": "Author(s)",
"serie": "Serie",
"language": "Language",
"tags": "Tag(s)",
"nocover": "No cover"
},
"author": {
"books": "Books",
"series": "Series",
"coauthors": "Co-Authors"
},
"serie": {
"books": "Books",
"authors": "Authors"
}
}
}

View File

@ -0,0 +1,46 @@
{
"bouquins": {
"homeTitle":"Bibliothèque",
"homeGreetings":"Naviguez dans la bibliothèque",
"authors": "Auteurs",
"books": "Livres",
"series": "Séries",
"recent": "Derniers ajouts",
"previous": "Précédent",
"next": "Suivant",
"empty": "Vide"
"cols": {
"booktitle": "Titre",
"bookauthors": "Auteur(s)",
"bookserie": "Série",
"authorname": "Nom",
"authorbooks": "Livres",
"seriename": "Nom",
"serieauthors": "Auteur(s)",
"seriebooks": "Livres"
},
"nav": {
"home": "Accueil",
"books": "Livres",
"authors": "Auteurs",
"series": "Séries"
},
"book": {
"download": "Télécharger",
"authors": "Author(s)",
"serie": "Série",
"language": "Langue",
"tags": "Tag(s)",
"nocover": "Pas de couverture"
},
"author": {
"books": "Livres",
"series": "Séries",
"coauthors": "Co-Auteurs"
},
"serie": {
"books": "Livres",
"authors": "Auteurs"
}
}
}

View File

@ -1,41 +1,40 @@
var express = require('express');
var router = express.Router();
var _ = require('underscore');
var paginate = require('../util/paginate');
var HashMap = require('hashmap').HashMap;
/* All books */
router.get('/', function(req, res) {
function find(db, pager, appendwhere, callback) {
var books = new HashMap();
req.paginate = new paginate(req);
var qparams = new Array();
var query = 'SELECT books.id as id,title,series_index,name as series_name,series.id AS series_id'+
' FROM books' +
' LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book' +
' LEFT OUTER JOIN series ON series.id = books_series_link.series';
query = req.paginate.appendInitialQuery(query,'books.sort',qparams,true);
if (req.query.sort == 'recent')
query+= ' ORDER BY books.last_modified DESC';
else
query+= ' ORDER BY books.sort';
if (appendwhere) {
query = appendwhere(query, qparams);
}
query+= ' LIMIT ? OFFSET ?';
qparams.push(req.paginate.perpage + 1);
qparams.push(req.paginate.offset);
req.db.each(query, qparams,
qparams.push(pager.perpage + 1);
qparams.push(pager.offset);
// console.log(query);
// console.log(qparams);
db.each(query, qparams,
function (err, book) {
if (books.count() < req.paginate.perpage) {
if (books.count() < pager.perpage) {
books.set(''+book.id, book);
} else
req.paginate.hasNext = true; /* more than perpage */
pager.hasNext = true; /* more than perpage */
},
function(err) {
if (err) console.log(err);
res.links(req.paginate.links());
/* query books authors */
var qAuthors = 'SELECT books_authors_link.book as book,authors.id as id,name FROM authors, books_authors_link WHERE books_authors_link.author = authors.id AND books_authors_link.book IN (';
for (var i=0;i<books.count()-1;i++) qAuthors+='?,';
qAuthors+='?)';
req.db.each(qAuthors, books.keys(),
db.each(qAuthors, books.keys(),
function(err, author) {
var book = books.get(''+author.book);
if (!book.authors) book.authors = new Array();
@ -43,11 +42,109 @@ router.get('/', function(req, res) {
},
function(err) {
if (err) console.log(err);
res.json(books.values());
callback(books.values());
}
);
}
);
}
/* All books */
router.get('/', function(req, res) {
var pager = new paginate(req);
find(req.db, pager,
function(query, qparams) {
/* books with given initial */
query = pager.appendInitialQuery(query,'books.sort',qparams,true);
/* recent */
if (req.query.sort == 'recent')
query+= ' ORDER BY books.last_modified DESC';
else
query+= ' ORDER BY books.sort';
return query;
},
function(books) {
res.links(pager.links());
res.json(books);
}
);
});
/* Search */
router.post('/', function(req,res) {
/* param q = search term
* Search in
* book.sort weight 1000
* author.sort weight 1
* serie.sort weight 5
* comment weight 100
*/
var found = new Array();
var term = '%'+req.body.q.toUpperCase()+'%';
console.log(term);
var nbqueries = 4;
var output = function(err) {
if (err) console.log(err);
nbqueries--;
if (nbqueries == 0) {
var merged = new HashMap();
_.each(found, function(elt) {
var weight = merged.get(''+elt.id) || 0;
merged.set(''+elt.id,weight+elt.weight);
});
/* sort ids by weight */
var ids = _.sortBy(merged.keys(), function(id) { return -1*merged.get(''+id); });
/* truncate */
var pager = new paginate(req);
ids.length = Math.min(ids.length,pager.perpage);
find(req.db, pager,
function(query, qparams) {
_.each(ids, function(id, index) {
if (index == 0)
query+=' WHERE books.id IN (';
else
query+=',';
query+='?';
qparams.push(id);
});
query+=')';
return query;
},
function(books) {
// TODO no pager res.links(pager.links());
/* sort by weight */
res.json(_.sortBy(books, function(book) { return -1*merged.get(''+book.id); }));
}
);
}
};
req.db.each('SELECT id FROM books WHERE UPPER(sort) LIKE ?', term,
function(err, row) { found.push( { id: row.id, weight: 1000 } ); },
function(err) { output(err); }
);
req.db.each('SELECT books_authors_link.book AS id FROM authors'+
' LEFT OUTER JOIN books_authors_link ON books_authors_link.author = authors.id'+
' WHERE UPPER(authors.sort) LIKE ?', term,
function(err, row) { found.push( { id: row.id, weight: 5 } ); },
function(err) { output(err); }
);
req.db.each('SELECT books_series_link.book AS id FROM series'+
' LEFT OUTER JOIN books_series_link ON books_series_link.series = series.id'+
' WHERE UPPER(series.sort) LIKE ?', term,
function(err, row) { found.push( { id: row.id, weight: 100 } ); },
function(err) { output(err); }
);
req.db.each('SELECT book FROM comments WHERE UPPER(text) LIKE ?', term,
function(err, row) { found.push( { id: row.book, weight: 10 } ); },
function(err) { output(err); }
);
});
/* Single book */