From 072b35fd54021d33123ca4b77a3ffc59595f6f2f Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Wed, 22 Dec 2021 21:08:44 +0200 Subject: [PATCH] Add some basics with translate functionality --- server/router/index.js | 2 + server/router/translate/index.js | 77 ++++++++++++++++++++++++++++++ server/views/translate-chapter.pug | 36 ++++++++++++++ server/views/translation-entry.pug | 4 +- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 server/router/translate/index.js create mode 100644 server/views/translate-chapter.pug diff --git a/server/router/index.js b/server/router/index.js index ae389ae..eec310a 100644 --- a/server/router/index.js +++ b/server/router/index.js @@ -22,6 +22,7 @@ module.exports = function (options) { var pledgesRouter = require('./pledges/')(options); var campaignsRouter = require('./campaigns/')(options); var apiRouter = require('./api/')(options); + var translateRouter = require('./translate/')(options); router.use('/library', libraryRouter); @@ -29,6 +30,7 @@ module.exports = function (options) { router.use('/campaigns', campaignsRouter); router.use('/account', accountRouter); router.use('/api', apiRouter); + router.use('/translate', translateRouter); return router; }; \ No newline at end of file diff --git a/server/router/translate/index.js b/server/router/translate/index.js new file mode 100644 index 0000000..9e81ff3 --- /dev/null +++ b/server/router/translate/index.js @@ -0,0 +1,77 @@ +const express = require('express') + +module.exports = function (options) { + const db = options.db; + var router = express.Router(); + + router.route('/:id') + .get(function(request, response, next) { + db.TranslationEntry.findByPk(request.params.id, { + include: [ + { + association: db.TranslationEntry.Entry, + required: true, + include: [ + { + association: db.Entry.Chapters, + required: true, + limit: 1, + // TODO: Order by chapter index + } + ] + } + ] + }).then(translationEntry => { + if (translationEntry) { + response.redirect(`/translate/${translationEntry.id}/chapter/${translationEntry.entry.chapters[0].id}`) + } else { + next() + } + }) + }) + + router.route('/:id/chapter/:chapterId') + .get(function(request, response, next) { + db.Chapter.findByPk(request.params.chapterId, { + include: [ + { + association: db.Chapter.Chunks, + include: [ + { + association: db.Chunk.Translation + } + ] + }, + { + association: db.Chapter.Entry, + required: true, + include: [ + { + association: db.Entry.TranslationEntries, + required: true, + where: { + id: request.params.id + } + }, + { + association: db.Entry.Dialect + } + ] + } + ] + }).then(chapter => { + if (chapter) { + response.display("translate-chapter", { + user: request.user, + pageTitle: `Translate Chapter ${chapter.name}`, + chapter: chapter + }) + } else { + next() + } + }).catch(error => { + next(error) + }) + }) + return router; +}; \ No newline at end of file diff --git a/server/views/translate-chapter.pug b/server/views/translate-chapter.pug new file mode 100644 index 0000000..a3da1d3 --- /dev/null +++ b/server/views/translate-chapter.pug @@ -0,0 +1,36 @@ +extend templates/layout.pug + +block content + .container + .center + h1= chapter.entry.translationEntries[0].name + h2= chapter.entry.name + + //- TODO: List chunks in the chapter + .row + .col.s12 + table + thead + tr + th #{chapter.entry.dialect.name} + th #{chapter.entry.translationEntries[0].name} + th + + tbody + each chunk in chapter.chunks + tr + td= chunk.text + td + if chunk.ossified + span= chunk.text + else if chunk.translation + span= chunk.translation.text + else + span= chunk.text.replaceAll(/./g, "  ") + td + if chunk.ossified + span nothing + else if chunk.translation + a.btn.blue review + else + a.btn.black translate \ No newline at end of file diff --git a/server/views/translation-entry.pug b/server/views/translation-entry.pug index 8627320..233e53b 100644 --- a/server/views/translation-entry.pug +++ b/server/views/translation-entry.pug @@ -4,4 +4,6 @@ block content .container .center h1= translationEntry.name - h2= translationEntry.entry.name \ No newline at end of file + h2= translationEntry.entry.name + + a.btn.black(href=`/translate/${translationEntry.id}`) Translate \ No newline at end of file