Skip to content

Commit

Permalink
Merge pull request #5123 from newrelic/4204_download_translation_updates
Browse files Browse the repository at this point in the history
Download translation script updates
  • Loading branch information
moonlight-komorebi committed Dec 3, 2021
2 parents 9fb8254 + 6aa1561 commit 7134ca1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/check-translations-and-deserialize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
TRANSLATION_VENDOR_PROJECT: ${{ secrets.TRANSLATION_VENDOR_PROJECT }}
TRANSLATION_VENDOR_USER: ${{ secrets.TRANSLATION_VENDOR_USER }}
TRANSLATION_VENDOR_SECRET: ${{ secrets.TRANSLATION_VENDOR_SECRET }}
TRANSLATION_TYPE: human
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -95,14 +96,15 @@ jobs:
id: remove-batches
run: |
node ./scripts/actions/remove-completed-batch.js
fetch-machine-translated-content:
name: Fetch machine translated content
runs-on: ubuntu-latest
env:
TRANSLATION_VENDOR_PROJECT: ${{ secrets.TRANSLATION_VENDOR_MT_PROJECT }}
TRANSLATION_VENDOR_USER: ${{ secrets.TRANSLATION_VENDOR_MT_USER }}
TRANSLATION_VENDOR_SECRET: ${{ secrets.TRANSLATION_VENDOR_MT_SECRET }}
TRANSLATION_TYPE: machine
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
8 changes: 6 additions & 2 deletions scripts/actions/check-job-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const {

const { getAccessToken, vendorRequest } = require('./utils/vendor-request');
const { fetchAndDeserialize } = require('./fetch-and-deserialize');
const { configuration } = require('./configuration');

const PROJECT_ID = process.env.TRANSLATION_VENDOR_PROJECT;
const PROJECT_ID = configuration.TRANSLATION.VENDOR_PROJECT;

const uniq = (arr) => [...new Set(arr)];
const prop = (key) => (x) => x[key];
Expand Down Expand Up @@ -105,7 +106,10 @@ const getBatchStatus = (accessToken) => async ({ batchUid, jobId }) => {
const main = async () => {
try {
// load the items that we are being translated
const inProgressJobs = await getJobs({ status: 'IN_PROGRESS' });
const inProgressJobs = await getJobs({
status: 'IN_PROGRESS',
project_id: PROJECT_ID,
});
const batchUids = inProgressJobs.map((job) => {
return { batchUid: job.batch_uid, jobId: job.id };
});
Expand Down
29 changes: 29 additions & 0 deletions scripts/actions/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Module which holds configurable fields and their values for running scripts.
* At the moment, only contains configuration for translation workflow.
* @module configuration
* */

const configuration = {
/** Translation configuration section. */
TRANSLATION: {
/** API endpoint for translation vendor. */
VENDOR_API_URL: process.env.TRANSLATION_VENDOR_API_URL,
/** Project ID (from vendor) used for translation. */
VENDOR_PROJECT: process.env.TRANSLATION_VENDOR_PROJECT,
/** User ID (from vendor) used for authentication */
VENDOR_USER: process.env.TRANSLATION_VENDOR_USER,
/** User secret (from vendor) used for authentication */
VENDOR_SECRET: process.env.TRANSLATION_VENDOR_SECRET,
/** Value indicating if configured for 'human' or 'machine' translation. Can also be undefined indicating neither or both. */
TYPE: process.env.TRANSLATION_TYPE,
},
};

module.exports = {
/**
* Configurable fields and their values for running scripts.
* At the moment, only contains configuration for translation workflow.
*/
configuration,
};
2 changes: 2 additions & 0 deletions scripts/actions/deserialize-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const heading = require('hast-util-to-mdast/lib/handlers/heading');
const u = require('unist-builder');
const { last } = require('lodash');
const yaml = require('js-yaml');
const { configuration } = require('./configuration');

const component = (h, node) => {
if (!node.properties || !node.properties.dataType) {
Expand Down Expand Up @@ -74,6 +75,7 @@ const stripTranslateFrontmatter = () => {
const frontmatterObj = yaml.load(tree.children[0].value);
delete frontmatterObj.translate;
delete frontmatterObj.redirects;
frontmatterObj.translationType = configuration.TRANSLATION.TYPE;
const frontmatterStr = yaml
.dump(frontmatterObj, { lineWidth: -1 })
.trim();
Expand Down

0 comments on commit 7134ca1

Please sign in to comment.