Back translations

This commit is contained in:
2021-12-27 00:00:36 +02:00
parent e9935a3b37
commit 4a016ac16a
3 changed files with 115 additions and 1 deletions

2
package-lock.json generated
View File

@@ -24,7 +24,7 @@
}
},
"../mantra-db-models": {
"version": "0.0.6",
"version": "0.0.6.3",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",

View File

@@ -202,5 +202,115 @@ module.exports = function (options) {
next(error)
})
})
router.route('/:id/back')
.post(function(request, response, next) {
db.TranslationEntryVersion.findByPk(request.params.id, {
include: [
{
association: db.TranslationEntryVersion.EntryVersion,
required: true,
include: [
{
association: db.EntryVersion.Chapters,
required: true,
include: [
{
association: db.Chapter.Chunks,
required: true,
include: [
{
association: db.Chunk.Translation,
required: true,
// TODO: Where text is not null
}
]
}
]
},
{
association: db.EntryVersion.Entry,
include: [
{
association: db.Entry.Dialect
}
]
}
]
}
]
}).then((translationEntryVersion) => {
if (translationEntryVersion) {
// TODO: Create a backTranslation...
backTranslatedEntry = {}
return db.BackTranslation.create({
translationEntryVersionId: translationEntryVersion.id,
entry: {
name: translationEntryVersion.name + translationEntryVersion.entryVersion.entry.name,
url: `/translate/${request.params.id}`,
dialectId: translationEntryVersion.dialectId,
licenseId: "copyright", // Should be closed because it's a back translation not meant to be published
entryVersions: [
{
tag: translationEntryVersion.entryVersion.tag,
chapters: translationEntryVersion.entryVersion.chapters.map(chapter => {
return {
name: chapter.chunks[0].translation.text, // TODO: This isn't important...
chunks: chapter.chunks.map(chunk => {
return {
text: chunk.translation.text,
index: chunk.index
}
})
}
}),
translationEntryVersions: [
{
dialectId: translationEntryVersion.entryVersion.entry.dialect.id,
name: translationEntryVersion.entryVersion.entry.dialect.name
}
]
}
]
}
}, {
include: [
{
association: db.BackTranslation.Entry,
include: [
{
association: db.Entry.EntryVersions,
include: [
{
association: db.EntryVersion.Chapters,
include: [
{
association: db.Chapter.Chunks
}
]
},
{
association: db.EntryVersion.TranslationEntryVersions
}
]
}
]
}
]
})
} else {
return null
}
}).then(backTranslation => {
if (backTranslation) {
response.redirect(`/library/${backTranslation.entryId}`)
} else {
// TODO: Let user know we cannot back translate
response.redirect(`/translate/${request.params.id}`)
}
}).catch(error => {
next(error)
})
})
return router;
};

View File

@@ -20,4 +20,8 @@ block content
form(action=`/fork/t/${translationEntryVersion.id}`, method="post")
button.btn.black(type="submit") fork
.row
.col.s12
form(action=`/translate/${translationEntryVersion.id}/back`, method="post")
button.btn.black(type="submit") back translate
//- TODO: Give summary of chapters...