Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(checkmissintranlations.ts): add colors to log
Browse files Browse the repository at this point in the history
add library chalk to make logs more colored
  • Loading branch information
marcosvega91 committed May 3, 2020
1 parent 5ef3f7e commit ede7b2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -74,6 +74,7 @@
"@types/validator": "~13.0.0",
"@typescript-eslint/eslint-plugin": "~2.30.0",
"@typescript-eslint/parser": "~2.30.0",
"chalk": "^4.0.0",
"commitizen": "~4.0.3",
"commitlint-config-cz": "~0.13.0",
"cross-env": "~7.0.0",
Expand Down
6 changes: 6 additions & 0 deletions scripts/.eslintrc.js
@@ -0,0 +1,6 @@
module.exports = {
extends: '../.eslintrc.js',
rules: {
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}]
}
}
31 changes: 21 additions & 10 deletions scripts/checkMissingTranslations.ts
@@ -1,6 +1,11 @@
import { Resource, ResourceKey } from 'i18next'
import chalk from 'chalk'
import i18n from '../src/i18n'

const error = chalk.bold.red
const warning = chalk.keyword('orange')
const success = chalk.keyword('green')

const checkRecursiveTranslation = (
comparingLanguage: string,
searchingPath: string[],
Expand All @@ -10,9 +15,11 @@ const checkRecursiveTranslation = (
if (typeof defaultLanguageObject === 'string' || typeof comparingLanguageObject === 'string') {
if (typeof defaultLanguageObject === 'object') {
console.log(
`πŸ“™ Found a string for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage} while is and object for the default language`,
warning(
`Found a string for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage} while is and object for the default language`,
),
)
}
return
Expand All @@ -24,10 +31,12 @@ const checkRecursiveTranslation = (
}
defaultKeys.forEach((key) => {
if (!comparingLanguageObject[key]) {
console.log(
`πŸ“™ The key ${key} is not present for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage}`,
console.warn(
warning(
`The key ${key} is not present for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage}`,
),
)
} else {
checkRecursiveTranslation(
Expand All @@ -45,19 +54,21 @@ const run = () => {
const languages = Object.keys(resources)
const defaultLanguage = 'en'
console.log(
'🏁 Start finding translation problem comparing all languages with the default one (English)',
success(
'🏁 Start finding translation problem comparing all languages with the default one (English)',
),
)
console.log('')
if (!resources[defaultLanguage]) {
console.log('πŸ“• We have a big problem.... the english language is not found!')
console.log(error('We have a big problem.... the english language is not found!'))
process.exit(1)
}

languages.forEach((language) => {
if (language === defaultLanguage) {
return
}
console.log(`🀞Checking ${language}`)
console.log(success(`Checking ${language}`))
console.log('')
checkRecursiveTranslation(language, [language], resources[defaultLanguage], resources[language])
console.log('')
Expand Down

0 comments on commit ede7b2e

Please sign in to comment.