feat: all passed
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-12-26 12:39:31 +01:00
parent f50dfa7358
commit 188840ccaa
1 changed files with 20 additions and 12 deletions

View File

@ -4,7 +4,6 @@ import path from 'path';
import { glob } from 'glob'; import { glob } from 'glob';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
const localesPath = path.resolve(__dirname + '../../i18n/locale');
let locales = {}; let locales = {};
async function init() { async function init() {
const files = await glob(['src/i18n/locale/**.yml', 'src/pages/**/locale/*.yml']); const files = await glob(['src/i18n/locale/**.yml', 'src/pages/**/locale/*.yml']);
@ -43,7 +42,8 @@ describe('🔍 Translation Keys Validation', async () => {
'src/pages/**/*.vue', 'src/pages/**/*.vue',
'src/components/**/*.vue', 'src/components/**/*.vue',
]); ]);
const regex = /\$t\(['"`]([\w.]+)['"`]\)|t\(['"`]([\w.]+)['"`]\)/g;
const regex = /(?:=\s*)\$t\(['"`]([\w.]+)['"`]\)|(?:=\s*)t\(['"`]([\w.]+)['"`]\)/g;
vueFiles.forEach((file) => { vueFiles.forEach((file) => {
const keys = new Set(); const keys = new Set();
@ -76,16 +76,24 @@ describe('🔍 Translation Keys Validation', async () => {
} }
Object.entries(locales).forEach(([locale, translations]) => { Object.entries(locales).forEach(([locale, translations]) => {
it(`should have all translation keys in ${locale}.${file}`, () => { it(`should have all translation keys in ${locale}.${file}`, () => {
const missingKeys = validateKeys(keys, translations); let missingKeys = validateKeys(keys, translations);
// try { if (missingKeys.length > 0) {
console.info( const parts = file.split(path.sep);
`xMissing keys in ${file}:${missingKeys.join(', ')}`, const cardIndex = parts.indexOf('Card');
missingKeys if (cardIndex > 0) {
); let previousElement = parts[cardIndex - 1];
expect(missingKeys, `xxMissing keys in ${file}`).toHaveLength(0); previousElement =
// } catch (error) { previousElement.charAt(0).toLowerCase() +
// console.error(`xxxMissing keys in ${file}${missingKeys.join(', ')}`); previousElement.slice(1);
// } console.log(`Elemento anterior a 'Card': ${previousElement}`);
const updatedKeys = new Set();
keys.forEach((key) => {
updatedKeys.add(`${previousElement}.${key}`);
});
missingKeys = validateKeys(updatedKeys, translations);
}
}
expect(missingKeys, `Missing keys in ${file}`).toHaveLength(0);
}); });
}); });
}); });