diff --git a/.github/workflows/crowdin-i18n-curriculum-upload.yml b/.github/workflows/crowdin-i18n-curriculum-upload.yml index 5c4a38c1ec9..f6aeb0cf724 100644 --- a/.github/workflows/crowdin-i18n-curriculum-upload.yml +++ b/.github/workflows/crowdin-i18n-curriculum-upload.yml @@ -61,3 +61,13 @@ jobs: CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/' CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }} CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID_CURRICULUM }} + + - name: Hide Example Link in Nest an Anchor Element challenge + uses: ./tools/crowdin/actions/hide-specific-string + with: + filename: 'basic-html-and-html5/nest-an-anchor-element-within-a-paragraph.md' + string-content: Here's a link to www.freecodecamp.org for you to follow. + env: + CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/' + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID_CURRICULUM }} + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }} diff --git a/tools/crowdin/actions/hide-specific-string/action.yml b/tools/crowdin/actions/hide-specific-string/action.yml new file mode 100644 index 00000000000..fab7733439a --- /dev/null +++ b/tools/crowdin/actions/hide-specific-string/action.yml @@ -0,0 +1,12 @@ +name: 'Hide Specific String' +description: "Updates a specific string to be hidden" +runs: + using: 'node12' + main: './index.js' +inputs: + filename: + description: 'name of file with specific string to hide' + required: true + string-content: + description: 'text content of string to hide' + required: true diff --git a/tools/crowdin/actions/hide-specific-string/index.js b/tools/crowdin/actions/hide-specific-string/index.js new file mode 100644 index 00000000000..1eccdfd103e --- /dev/null +++ b/tools/crowdin/actions/hide-specific-string/index.js @@ -0,0 +1,34 @@ +require('dotenv').config({ path: `${__dirname}/../../.env` }); +const { getFiles } = require('../../utils/files'); +const { getStrings, changeHiddenStatus } = require('../../utils/strings'); +// eslint-disable-next-line import/no-unresolved +const core = require('@actions/core'); + +const filename = core.getInput('filename'); +const stringContent = core.getInput('string-content'); + +const hideString = async (projectId, fileName, string) => { + const fileResponse = await getFiles(projectId); + const targetFile = fileResponse.find(el => el.path.endsWith(filename)); + if (!targetFile) { + core.setFailed(`${fileName} was not found.`); + return; + } + + const stringResponse = await getStrings({ + projectId, + fileId: targetFile.fileId + }); + + const targetString = stringResponse.find(el => el.data.text === string); + if (!targetString) { + core.setFailed(`${string} was not found.`); + return; + } + + await changeHiddenStatus(projectId, targetString.data.id, true); + console.log('string hidden!'); +}; + +const projectId = process.env.CROWDIN_PROJECT_ID; +hideString(projectId, filename, stringContent); diff --git a/tools/crowdin/utils/strings.js b/tools/crowdin/utils/strings.js index 090efa0c630..aa0ed067eff 100644 --- a/tools/crowdin/utils/strings.js +++ b/tools/crowdin/utils/strings.js @@ -233,5 +233,6 @@ module.exports = { addTranslation, deleteTranslation, getLanguageTranslations, - deleteLanguageTranslations + deleteLanguageTranslations, + changeHiddenStatus };