-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* translate steps partially * fix error message * fix throw error syntax
- Loading branch information
1 parent
9814aa0
commit e7c0663
Showing
18 changed files
with
210 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
server/src/database/migrations/20230125051040-add-all-fields-translated-to-steps-i18n.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
let dbm; | ||
let type; | ||
let seed; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
let Promise; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function (options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
Promise = options.Promise; | ||
}; | ||
|
||
exports.up = function (db) { | ||
const filePath = path.join( | ||
__dirname, | ||
'sqls', | ||
'20230125051040-add-all-fields-translated-to-steps-i18n-up.sql', | ||
); | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) { | ||
if (err) return reject(err); | ||
console.log(`received data: ${data}`); | ||
|
||
resolve(data); | ||
}); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports.down = function (db) { | ||
const filePath = path.join( | ||
__dirname, | ||
'sqls', | ||
'20230125051040-add-all-fields-translated-to-steps-i18n-down.sql', | ||
); | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) { | ||
if (err) return reject(err); | ||
console.log(`received data: ${data}`); | ||
|
||
resolve(data); | ||
}); | ||
}).then(function (data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
6 changes: 6 additions & 0 deletions
6
.../database/migrations/sqls/20230125051040-add-all-fields-translated-to-steps-i18n-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE "steps_i18n" | ||
DROP COLUMN "all_fields_translated"; | ||
|
||
COMMIT; |
9 changes: 9 additions & 0 deletions
9
...rc/database/migrations/sqls/20230125051040-add-all-fields-translated-to-steps-i18n-up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE "steps_i18n" | ||
ADD COLUMN "all_fields_translated" BOOLEAN DEFAULT FALSE; | ||
|
||
UPDATE "steps_i18n" | ||
SET "all_fields_translated" = TRUE; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
import * as Steps from '../model'; | ||
// import translateSteps from '../../../services/translation/translate-steps'; | ||
// import * as Translation from '../../translations/model'; | ||
import translateSteps from '../../../services/translation/translate-steps'; | ||
import * as Translation from '../../translations/model'; | ||
|
||
const getStep = async ({ id /* lng */ }) => { | ||
const step = await Steps.getStepById(id, 'en'); | ||
return step; | ||
// return step as is for now, because we don't use this route for public | ||
// const [stepT] = await translateSteps({ | ||
// lng, | ||
// steps: [step], | ||
// }); | ||
const getStep = async ({ id, lng, forPublic }) => { | ||
const step = await Steps.getStepById(id, lng); | ||
if (!forPublic) { | ||
return step; | ||
} | ||
|
||
// if (!stepT.isTranslated) { | ||
// Translation.createStepI18n({ stepId: stepT.id, ...stepT }); | ||
// } | ||
const [stepT] = await translateSteps({ | ||
lng, | ||
steps: [step], | ||
}); | ||
|
||
// return stepT; | ||
if (!stepT.isTranslated || !step.allFieldsTranslated) { | ||
Translation.createStepI18n({ | ||
stepId: stepT.id, | ||
...stepT, | ||
allFieldsTranslated: true, | ||
}); | ||
} | ||
|
||
return { | ||
...stepT, | ||
id: step.id, | ||
checklist: [ | ||
stepT.thingsYouWillNeed.map((item) => ({ | ||
...item, | ||
stage: 'thingsYouWillNeed', | ||
})), | ||
stepT.whatYouWillNeedToKnow.map((item) => ({ | ||
...item, | ||
stage: 'whatYouWillNeedToKnow', | ||
})), | ||
].flat(), | ||
}; | ||
}; | ||
|
||
export default getStep; |
Oops, something went wrong.