Skip to content

Commit

Permalink
Merge pull request #406 from openstad/feature/expand-logs-on-translat…
Browse files Browse the repository at this point in the history
…ion-service

Added more specifics to log
  • Loading branch information
LorenzoJokhan committed Jun 28, 2023
2 parents fcda9cd + 4ac5057 commit 7049eef
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/cms/lib/modules/openstad-global/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ module.exports = (self, options) => {
const collection = self.apos.db.collection("deepl-translations");
const result = await collection.findOne({_id: cacheKey});
if (result) {
console.log("Receiving translations from cache");
console.log(`Receiving translations from cache for site ${origin}`);
return res.json(result.translations);
}

// content should always be a collection of dutch terms, translations to other languages are translated from dutch to (for example) english
if (destinationLanguage === 'nl') {
console.log("Target language is dutch, not translating and responding with the dutch sentences received");
console.log(`Target language is dutch, not translating and responding with the dutch sentences received for site ${origin}`);
return res.json(content);
}

Expand All @@ -49,16 +49,25 @@ module.exports = (self, options) => {
return res.status(500).json({ error: 'Could not translate the page at this time' });
}

const characterCount = content.map(word => word.length).reduce((total, a) => total + a, 0);

if (translator) {
console.log("No existing translations found, fetching translations from deepl")
console.log(`No existing translations found, fetching translations from deepl for site: ${origin} with charactersize of ${characterCount} and destination language ${destinationLanguage}`)

translator.translateText(
content,
sourceLanguageCode,
destinationLanguage,
).then(response => {
collection.findOneAndUpdate(
{"_id": cacheKey},
{ $set: { "translations": response}},
{ $set: {
"origin": origin,
"destinationLanguage": destinationLanguage,
"characters": characterCount,
"translations": response,
},
},
{upsert:true}
);
return res.json(response);
Expand Down

1 comment on commit 7049eef

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Published new image: openstad/frontend:master-7049eef

Please sign in to comment.