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

feat(i18n): add new script for checking missing translations #2034

Merged
merged 56 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9ca5232
feat(add new script for checking missing translations): translations
marcosvega91 May 2, 2020
4e9a02d
Merge branch 'master' into feature/check_translations
May 2, 2020
991eb51
Merge branch 'master' into feature/check_translations
May 2, 2020
48b16aa
Merge branch 'master' into feature/check_translations
May 2, 2020
99fd323
Merge branch 'master' into feature/check_translations
May 2, 2020
c3c1694
refactor: remove useless file
marcosvega91 May 2, 2020
ecab41d
Merge branch 'feature/check_translations' of github.com:marcosvega91/…
marcosvega91 May 2, 2020
75f9981
feat(checkmissingtranslations.ts): refactor
marcosvega91 May 3, 2020
d20b9c7
feat(checkmissingtranslations.ts): add language in logs
marcosvega91 May 3, 2020
7ab8195
feat(checkmissingtranslations.ts): change type of searchingPath
marcosvega91 May 3, 2020
5ef3f7e
feat(checkmissintranslations.ts): run script before default ones
marcosvega91 May 3, 2020
ede7b2e
feat(checkmissintranlations.ts): add colors to log
marcosvega91 May 3, 2020
78bc390
Merge branch 'master' into feature/check_translations
May 3, 2020
7694a1c
Merge branch 'master' into feature/check_translations
May 3, 2020
9002485
Merge branch 'master' into feature/check_translations
May 3, 2020
f5591a1
Merge branch 'master' into feature/check_translations
May 3, 2020
dc5c70b
Merge branch 'master' into feature/check_translations
May 4, 2020
e0cbbb9
Merge branch 'master' into feature/check_translations
May 4, 2020
746a35d
Merge branch 'master' into feature/check_translations
marcosvega91 May 14, 2020
6075cec
Merge branch 'master' into feature/check_translations
May 16, 2020
3dcf421
Merge branch 'master' into feature/check_translations
May 16, 2020
6afdea1
Merge branch 'master' into feature/check_translations
matteovivona May 16, 2020
2d14bbb
Merge branch 'master' into feature/check_translations
May 16, 2020
b033bde
Merge branch 'master' into feature/check_translations
May 17, 2020
c0564da
Merge branch 'master' into feature/check_translations
May 17, 2020
e34d0fe
Merge branch 'master' into feature/check_translations
May 19, 2020
de3d090
Merge branch 'master' into feature/check_translations
May 19, 2020
d8e36f4
Merge branch 'master' into feature/check_translations
May 19, 2020
bb61c99
Merge branch 'master' into feature/check_translations
May 20, 2020
4395885
Merge branch 'master' into feature/check_translations
May 20, 2020
e0b3c74
Merge branch 'master' into feature/check_translations
matteovivona May 23, 2020
fb8f86d
Merge branch 'master' into feature/check_translations
May 23, 2020
d66b98c
Merge branch 'master' into feature/check_translations
May 23, 2020
a76e298
Merge branch 'master' into feature/check_translations
May 23, 2020
919467e
Merge branch 'master' into feature/check_translations
May 24, 2020
a6f7647
Merge branch 'master' into feature/check_translations
matteovivona May 26, 2020
167955a
Merge branch 'master' into feature/check_translations
May 26, 2020
03c7225
Merge branch 'master' into feature/check_translations
May 26, 2020
e45c9e9
Merge branch 'master' into feature/check_translations
May 28, 2020
f3aa0f3
Merge branch 'master' into feature/check_translations
May 30, 2020
e51ca06
Merge branch 'master' into feature/check_translations
Jun 2, 2020
5697231
Merge branch 'master' into feature/check_translations
Jun 2, 2020
da62017
Merge branch 'master' into feature/check_translations
Jun 3, 2020
04afcc7
Merge branch 'master' into feature/check_translations
Jun 4, 2020
5df5e53
Merge branch 'master' into feature/check_translations
Jun 4, 2020
a5f42ee
Merge branch 'master' into feature/check_translations
Jun 5, 2020
34bc314
Merge branch 'master' into feature/check_translations
Jun 7, 2020
c013370
Merge branch 'master' into feature/check_translations
Jun 7, 2020
2d34c22
Merge branch 'master' into feature/check_translations
Jun 8, 2020
1b4fc4a
Merge branch 'master' into feature/check_translations
marcosvega91 Jun 8, 2020
099cc6a
Merge branch 'master' into feature/check_translations
Jun 8, 2020
b3da0ee
refactor(checktranslations): run script as js file
marcosvega91 Jun 8, 2020
50589c4
Merge branch 'feature/check_translations' of github.com:marcosvega91/…
marcosvega91 Jun 8, 2020
e589d21
Merge branch 'master' into feature/check_translations
Jun 8, 2020
30bb158
fix(i18n): fix build
marcosvega91 Jun 10, 2020
59dd02c
Merge branch 'feature/check_translations' of github.com:marcosvega91/…
marcosvega91 Jun 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
project: ['./tsconfig.json', './scripts/tsconfig.json'],
tsconfigRootDir: './',
},
settings: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
bin
# Logs
logs
*.log
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@types/validator": "~13.0.0",
"@typescript-eslint/eslint-plugin": "~2.34.0",
"@typescript-eslint/parser": "~2.34.0",
"chalk": "^4.0.0",
"commitizen": "~4.1.2",
"commitlint-config-cz": "~0.13.0",
"cross-env": "~7.0.0",
Expand Down Expand Up @@ -106,16 +107,17 @@
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"commit": "npx git-cz",
"start": "react-scripts start",
"start": "yarn translation:check && react-scripts start",
"build": "react-scripts build",
"prepublishOnly": "npm run build",
"test": "react-scripts test --detectOpenHandles",
"test": "yarn translation:check && react-scripts test --detectOpenHandles",
"test:ci": "cross-env CI=true react-scripts test --passWithNoTests",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\" \"scripts/**/*.{js,ts}\"",
"lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx}\" \"scripts/**/*.{js,ts}\" --fix",
"lint-staged": "lint-staged",
"commitlint": "commitlint",
"coveralls": "npm run test:ci -- --coverage --watchAll=false && cat ./coverage/lcov.info"
"coveralls": "npm run test:ci -- --coverage --watchAll=false && cat ./coverage/lcov.info",
"translation:check": "cd scripts && tsc && node ../bin/scripts/checkMissingTranslations.js"
},
"browserslist": {
"production": [
Expand Down
6 changes: 6 additions & 0 deletions scripts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: '../.eslintrc.js',
rules: {
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}]
}
}
78 changes: 78 additions & 0 deletions scripts/checkMissingTranslations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import chalk from 'chalk'
import { ResourceKey } from 'i18next'

import resources from '../src/locales'

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

const checkRecursiveTranslation = (
comparingLanguage: string,
searchingPath: string[],
defaultLanguageObject: ResourceKey,
comparingLanguageObject: ResourceKey,
) => {
if (typeof defaultLanguageObject === 'string' || typeof comparingLanguageObject === 'string') {
if (typeof defaultLanguageObject === 'object') {
console.log(
warning(
`Found a string for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage} while is and object for the default language`,
),
)
}
return
}
const defaultKeys: string[] = Object.keys(defaultLanguageObject)
const translatedKeys: string[] = Object.keys(comparingLanguageObject)
if (defaultKeys.length === 0 || translatedKeys.length === 0) {
return
}
defaultKeys.forEach((key) => {
if (!comparingLanguageObject[key]) {
console.warn(
warning(
`The key ${key} is not present for path ${searchingPath.join(
'-->',
)} and language ${comparingLanguage}`,
),
)
} else {
checkRecursiveTranslation(
comparingLanguage,
[...searchingPath, key],
defaultLanguageObject[key],
comparingLanguageObject[key],
)
}
})
}

const run = () => {
const languages = Object.keys(resources)
const defaultLanguage = 'en'
console.log(
success(
'🏁 Start finding translation problem comparing all languages with the default one (English)',
),
)
console.log('')
if (!resources[defaultLanguage]) {
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(success(`Checking ${language}`))
console.log('')
checkRecursiveTranslation(language, [language], resources[defaultLanguage], resources[language])
console.log('')
})
}

run()
8 changes: 8 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"include": ["./checkMissingTranslations.ts"],
"compilerOptions": {
"module": "commonjs",
"outDir": "../bin",
"target": "es5"
}
}
59 changes: 1 addition & 58 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,7 @@ import i18n from 'i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'

import translationAR from './locales/ar/translations'
import translationDE from './locales/de/translations'
import translationEnUs from './locales/enUs/translations'
import translationES from './locales/es/translations'
import translationFR from './locales/fr/translations'
import translationID from './locales/id/translations'
import translationIT from './locales/it/translations'
import translationJA from './locales/ja/translations'
import translationPtBR from './locales/ptBr/translations'
import translationRU from './locales/ru/translations'
import translationZhCN from './locales/zhCN/translations'

const resources: { [language: string]: any } = {
it: {
name: 'Italian',
translation: translationIT,
},
ar: {
name: 'Arabic',
translation: translationAR,
},
de: {
name: 'German',
translation: translationDE,
},
en: {
name: 'English, American',
translation: translationEnUs,
},
es: {
name: 'Spanish',
translation: translationES,
},
fr: {
name: 'French',
translation: translationFR,
},
id: {
name: 'Indonesian',
translation: translationID,
},
ja: {
name: 'Japanese',
translation: translationJA,
},
ptBR: {
name: 'Portuguese',
translation: translationPtBR,
},
ru: {
name: 'Russian',
translation: translationRU,
},
zhCN: {
name: 'Chinese',
translation: translationZhCN,
},
}
import resources from './locales'

i18n
// load translation using xhr -> see /public/locales
Expand Down
62 changes: 62 additions & 0 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Resource } from 'i18next'

import translationAR from './ar/translations'
import translationDE from './de/translations'
import translationEnUs from './enUs/translations'
import translationES from './es/translations'
import translationFR from './fr/translations'
import translationID from './id/translations'
import translationIT from './it/translations'
import translationJA from './ja/translations'
import translationPtBR from './ptBr/translations'
import translationRU from './ru/translations'
import translationZhCN from './zhCN/translations'

const resources: Resource = {
it: {
name: 'Italian',
translation: translationIT,
},
ar: {
name: 'Arabic',
translation: translationAR,
},
de: {
name: 'German',
translation: translationDE,
},
en: {
name: 'English, American',
translation: translationEnUs,
},
es: {
name: 'Spanish',
translation: translationES,
},
fr: {
name: 'French',
translation: translationFR,
},
id: {
name: 'Indonesian',
translation: translationID,
},
ja: {
name: 'Japanese',
translation: translationJA,
},
ptBR: {
name: 'Portuguese',
translation: translationPtBR,
},
ru: {
name: 'Russian',
translation: translationRU,
},
zhCN: {
name: 'Chinese',
translation: translationZhCN,
},
}

export default resources