diff --git a/__tests__/missingTranslationKeys.js b/__tests__/missingTranslationKeys.js new file mode 100644 index 00000000..e41bb382 --- /dev/null +++ b/__tests__/missingTranslationKeys.js @@ -0,0 +1,18 @@ +const { exec } = require('child_process'); +console.log('TYPESCRIPT ERROR CHECK'); +console.log('=' + '='.repeat(50)); + +exec('tsc --noEmit', (error, stdout) => { + if (error) { + const output = stdout; + const filteredErrors = output.split('\n').filter(line => line.includes('TxKeyPath')); + if (filteredErrors.length > 0) { + console.log('❌ TypeScript errors containing TxKeyPath found:'); + console.log(filteredErrors.join('\n')); + } else { + console.log('✅ No TypeScript errors containing TxKeyPath found.'); + } + } else { + console.log('✅ No TypeScript errors found.'); + } +}); \ No newline at end of file diff --git a/__tests__/missingTranslations.js b/__tests__/missingTranslations.js index bcbf6c8c..044a5bcc 100644 --- a/__tests__/missingTranslations.js +++ b/__tests__/missingTranslations.js @@ -1,4 +1,3 @@ -const { exec } = require('child_process'); const fs = require('fs'); const path = require('path'); @@ -7,91 +6,81 @@ console.log('=' + '='.repeat(50)); // First, run the translation analysis try { - // Read settings.json to get language configuration - const settingsPath = path.join(__dirname, '..', 'minibits.inlang', 'settings.json'); - const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); + // Read settings.json to get language configuration + const settingsPath = path.join(__dirname, '..', 'minibits.inlang', 'settings.json'); + const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); - const defaultLanguage = settings.sourceLanguageTag; - const allLanguages = settings.languageTags; + const defaultLanguage = settings.sourceLanguageTag; + const allLanguages = settings.languageTags; - console.log(`Default language: ${defaultLanguage}`); - console.log(`All languages: ${allLanguages.join(', ')}`); - console.log('=' + '='.repeat(50)); + console.log(`Default language: ${defaultLanguage}`); + console.log(`All languages: ${allLanguages.join(', ')}`); + console.log('=' + '='.repeat(50)); - // Load all translation files - const translations = {}; - const i18nMessagesPath = path.join(__dirname, '..', 'src', 'i18n_messages'); + // Load all translation files + const translations = {}; + const i18nMessagesPath = path.join(__dirname, '..', 'src', 'i18n_messages'); - allLanguages.forEach(lang => { - const filePath = path.join(i18nMessagesPath, `${lang}.json`); - if (fs.existsSync(filePath)) { - try { - translations[lang] = JSON.parse(fs.readFileSync(filePath, 'utf8')); - } catch (error) { - console.error(`Error reading ${lang}.json:`, error.message); - translations[lang] = {}; - } - } else { - console.warn(`Translation file not found: ${lang}.json`); - translations[lang] = {}; - } - }); + allLanguages.forEach(lang => { + const filePath = path.join(i18nMessagesPath, `${lang}.json`); + if (fs.existsSync(filePath)) { + try { + translations[lang] = JSON.parse(fs.readFileSync(filePath, 'utf8')); + } catch (error) { + console.error(`Error reading ${lang}.json:`, error.message); + translations[lang] = {}; + } + } else { + console.warn(`Translation file not found: ${lang}.json`); + translations[lang] = {}; + } + }); - // Get keys from default language - const defaultKeys = Object.keys(translations[defaultLanguage] || {}); - const totalKeys = defaultKeys.length; + // Get keys from default language + const defaultKeys = Object.keys(translations[defaultLanguage] || {}); + const totalKeys = defaultKeys.length; - console.log(`Total keys in default language (${defaultLanguage}): ${totalKeys}`); - console.log('=' + '='.repeat(50)); + console.log(`Total keys in default language (${defaultLanguage}): ${totalKeys}`); + console.log('=' + '='.repeat(50)); - // Check each language - allLanguages.forEach(lang => { - if (lang === defaultLanguage) { - console.log(`\n${lang.toUpperCase()} (default language)`); - console.log(`✅ 100% translated (${totalKeys}/${totalKeys} keys)`); - return; - } + // Check each language + for (const lang of allLanguages) { + if (lang === defaultLanguage) { + console.log(`\n${lang.toUpperCase()} (default language)`); + console.log(`✅ 100% translated (${totalKeys}/${totalKeys} keys)`); + continue; + } - const currentKeys = Object.keys(translations[lang] || {}); - const currentTotal = currentKeys.length; - const missingKeys = defaultKeys.filter(key => !translations[lang].hasOwnProperty(key)); - const percentageTranslated = totalKeys > 0 ? Math.round((currentTotal / totalKeys) * 100) : 0; - - console.log(`\n${lang.toUpperCase()}`); - console.log(`📊 ${percentageTranslated}% translated (${currentTotal}/${totalKeys} keys)`); - - if (missingKeys.length > 0) { - console.log(`❌ Missing ${missingKeys.length} keys:`); - missingKeys.forEach(key => { - console.log(` - ${key}`); - }); - } else { - console.log(`✅ No missing keys!`); - } - }); + const currentKeys = Object.keys(translations[lang] || {}); + const currentTotal = currentKeys.length; + const missingKeys = defaultKeys.filter(key => !translations[lang].hasOwnProperty(key)); + const percentcageTranslated = totalKeys > 0 ? Math.round((currentTotal / totalKeys) * 100) : 0; + + console.log(`\n${lang.toUpperCase()}`); + console.log(`📊 ${percentcageTranslated}% translated (${currentTotal}/${totalKeys} keys)`); + + if (missingKeys.length === 0) { + console.log('✅ No missing keys!'); + } else { + console.log(`❌ Missing ${missingKeys.length} keys:`); + const maxToShow = 25; - console.log('\n' + '=' + '='.repeat(50)); - console.log('✅ Translation analysis complete!'); + for (const [i, key] of missingKeys.entries()) { + if (i >= maxToShow) break; + console.log(` - ${key}`); + } + + if (missingKeys.length > maxToShow) { + console.log(` ...and ${missingKeys.length - maxToShow} more. (fix these first)`); + } + + } + } + + console.log('\n' + '=' + '='.repeat(50)); + console.log('✅ Translation analysis complete!'); } catch (translationError) { - console.error('❌ Error during translation analysis:', translationError.message); + console.error('❌ Error during translation analysis:', translationError.message); } console.log('\n' + '=' + '='.repeat(50)); -console.log('TYPESCRIPT ERROR CHECK'); -console.log('=' + '='.repeat(50)); - -// Now run the TypeScript error checking -exec('tsc --noEmit', (error, stdout) => { - if (error) { - const output = stdout; - const filteredErrors = output.split('\n').filter(line => line.includes('TxKeyPath')); - if (filteredErrors.length > 0) { - console.log('❌ TypeScript errors containing TxKeyPath found:'); - console.log(filteredErrors.join('\n')); - } else { - console.log('✅ No TypeScript errors containing TxKeyPath found.'); - } - } else { - console.log('✅ No TypeScript errors found.'); - } -}); diff --git a/package.json b/package.json index 2513a75b..b8e036f0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "lint": "eslint .", "start": "react-native start", "test": "jest", - "test:i18n": "node __tests__/missingTranslations.js && node __tests__/incorrectTranslationPlaceholders.js", + "test:i18n": "node __tests__/missingTranslations.js && node __tests__/incorrectTranslationPlaceholders.js && node __tests__/missingTranslationKeys.js", "adb": "adb devices && adb reverse tcp:9090 tcp:9090 && adb reverse tcp:3000 tcp:3000 && adb reverse tcp:9001 tcp:9001 && adb reverse tcp:8081 tcp:8081", "adb:unreverse": "adb devices && adb reverse --remove-all", "adb:inspect": "adb shell input keyevent 82",