Created
November 15, 2022 11:39
-
-
Save EdgardoRodriguezSolano/ba6244b586f8367f270d8db67db9aac0 to your computer and use it in GitHub Desktop.
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
const fs = require('fs-extra'); | |
const { difference } = require('lodash'); | |
const { languages } = require('../config'); | |
for (let i = 0; i < languages.length; i++) { | |
let checkResult = '✅'; | |
// ******************************** COMMON DIRECTORY ******************************** | |
const languageAbbreviation = languages[i]; | |
let commonDirectoryData, commonDirectoryKeys; | |
try { | |
const commonDirectory = `./src/sdk/ui/common/locale/gdpr/${languageAbbreviation}`; | |
fs.ensureDirSync(commonDirectory); | |
commonDirectoryData = JSON.parse( | |
fs.readFileSync(`${commonDirectory}/onesky.json`, 'utf8'), | |
); | |
commonDirectoryKeys = Object.keys(commonDirectoryData); | |
} catch (err) { | |
console.error( | |
`Web : An error Error while trying to read the common folder onesky.json file for the language ${languageAbbreviation}`, | |
err, | |
); | |
} | |
// ******************************** GDPR DIRECTORY ******************************** | |
let gdprDirectoryData, gdprDirectoryKeys; | |
try { | |
const gdprDirectory = `./src/sdk/ui/gdpr/locale/${languageAbbreviation}`; | |
fs.ensureDirSync(gdprDirectory); | |
gdprDirectoryData = JSON.parse( | |
fs.readFileSync(`${gdprDirectory}/onesky.json`, 'utf8'), | |
); | |
gdprDirectoryKeys = Object.keys(gdprDirectoryData); | |
} catch (err) { | |
console.error( | |
`Web : An error Error while trying to read the gdpr onesky.json file for the language ${languageAbbreviation}`, | |
err, | |
); | |
} | |
// ******************************** CTV DIRECTORY ******************************** | |
let ctvDirectoryData, ctvDirectoryKeys; | |
try { | |
const ctvDirectory = `./src/sdk/ui/ctv/locale/${languageAbbreviation}`; | |
fs.ensureDirSync(ctvDirectory); | |
ctvDirectoryData = JSON.parse( | |
fs.readFileSync(`${ctvDirectory}/onesky.json`, 'utf8'), | |
); | |
ctvDirectoryKeys = Object.keys(ctvDirectoryData); | |
} catch (err) { | |
console.error( | |
`Web : An error Error while trying to read the ctv onesky.json file for the language ${languageAbbreviation}`, | |
err, | |
); | |
} | |
// Make sure that no keys were omitted when doing the refactor | |
if ( | |
difference(gdprDirectoryKeys, commonDirectoryKeys).length > 0 || | |
difference(ctvDirectoryKeys, commonDirectoryKeys).length > 0 | |
) { | |
console.error('Key missing for language: ', languageAbbreviation); | |
checkResult = '🛑'; | |
} | |
// Make sure that there is no mismatch between translation | |
for (let key of commonDirectoryKeys) { | |
if ( | |
gdprDirectoryData[key] && | |
ctvDirectoryData[key] && | |
gdprDirectoryData[key] !== ctvDirectoryData[key] | |
) { | |
console.error( | |
'There is a translation mismatch for the following parameteres, key ', | |
key, | |
'language: ', | |
languageAbbreviation, | |
gdprDirectoryData[key], | |
ctvDirectoryData[key], | |
); | |
checkResult = '🛑'; | |
} | |
} | |
console.log(`${languageAbbreviation} ${checkResult}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment