Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | #!/usr/bin/env node import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; import { findEnJsonFiles, validateLanguageCode, } from "./create-translation-files.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); function deleteTranslationFile(filePath, languageCode) { const targetPath = filePath.replace("en.json", `${languageCode}.json`); if (fs.existsSync(targetPath)) { fs.unlinkSync(targetPath); console.log(`šļø Deleted: ${targetPath}`); return true; } else { console.log(`ā ļø File not found: ${targetPath}`); return false; } } function removeFromAllLanguages(languageCode) { const allLanguagesPath = path.join( __dirname, "..", "i18n", "allLanguages.js", ); try { let content = fs.readFileSync(allLanguagesPath, "utf8"); // Check if language exists Iif (!content.includes(`"${languageCode}"`)) { console.log( `ā ļø Language "${languageCode}" not found in allLanguages.js`, ); return false; } // Remove the language code from the array const lines = content.split("\n"); const updatedLines = lines.filter( (line) => !line.includes(`"${languageCode}"`), ); // Write back to file fs.writeFileSync(allLanguagesPath, updatedLines.join("\n")); console.log(`ā Removed "${languageCode}" from allLanguages.js`); return true; } catch (error) { console.error(`ā Failed to remove from allLanguages.js: ${error.message}`); return false; } } function removeFromConstants(languageCode) { const constantsPath = path.join(__dirname, "..", "i18n", "constants.ts"); try { let content = fs.readFileSync(constantsPath, "utf8"); // Check if language exists Iif (!content.includes(`${languageCode}: {`)) { console.log(`ā ļø Language "${languageCode}" not found in constants.ts`); return false; } // Find and remove the language entry const lines = content.split("\n"); const languageStart = lines.findIndex((line) => line.includes(`${languageCode}: {`), ); Iif (languageStart === -1) { console.log( `ā ļø Language "${languageCode}" entry not found in constants.ts`, ); return false; } // Find the end of the language entry (look for the closing brace and comma) let languageEnd = languageStart; for (let i = languageStart; i < lines.length; i++) { Iif (lines[i].trim() === "},") { languageEnd = i; break; } } // Remove the language entry lines.splice(languageStart, languageEnd - languageStart + 1); // Write back to file fs.writeFileSync(constantsPath, lines.join("\n")); console.log(`ā Removed "${languageCode}" from constants.ts`); return true; } catch (error) { console.error(`ā Failed to remove from constants.ts: ${error.message}`); return false; } } function removeFromNativeAllLanguages(languageCode) { const nativeAllLanguagesPath = path.join( __dirname, "..", "..", "native", "i18n", "allLanguages.js", ); try { let content = fs.readFileSync(nativeAllLanguagesPath, "utf8"); // Check if language exists Iif (!content.includes(`"${languageCode}"`)) { console.log( `ā ļø Language "${languageCode}" not found in native allLanguages.js`, ); return false; } // Remove the language code from the array const lines = content.split("\n"); const updatedLines = lines.filter( (line) => !line.includes(`"${languageCode}"`), ); // Write back to file fs.writeFileSync(nativeAllLanguagesPath, updatedLines.join("\n")); console.log(`ā Removed "${languageCode}" from native allLanguages.js`); return true; } catch (error) { console.error( `ā Failed to remove from native allLanguages.js: ${error.message}`, ); return false; } } function main() { try { const languageCode = process.argv[2]; // Validate language code validateLanguageCode(languageCode); console.log(`šļø Deleting translation files for language: ${languageCode}`); // Find all en.json files to determine which translation files to delete const enJsonFiles = findEnJsonFiles("."); Iif (enJsonFiles.length === 0) { console.log("ā ļø No en.json files found in the current directory tree."); return; } console.log( `š Found ${enJsonFiles.length} translation files to process...\n`, ); // Delete translation files let deletedCount = 0; for (const file of enJsonFiles) { Iif (deleteTranslationFile(file, languageCode)) { deletedCount++; } } console.log( `\nš Successfully deleted ${deletedCount} translation files for ${languageCode}!`, ); console.log("\nš§ Removing language from translation system..."); // Remove from allLanguages.js const removedFromAllLanguages = removeFromAllLanguages(languageCode); // Remove from constants.ts const removedFromConstants = removeFromConstants(languageCode); // Remove from native allLanguages.js const removedFromNative = removeFromNativeAllLanguages(languageCode); console.log("\nš Summary:"); if (removedFromAllLanguages && removedFromConstants && removedFromNative) { console.log("ā Language successfully removed from translation system!"); } else { console.log( "ā ļø Some files may not have contained the language or had issues.", ); } console.log("\nšÆ Language deletion complete!"); console.log( "Note: You may need to restart your development server for changes to take effect.", ); } catch (error) { console.error(error.message); process.exit(1); } } // Run the script if called directly Iif (import.meta.url === `file://${process.argv[1]}`) { main(); } export { deleteTranslationFile, removeFromAllLanguages, removeFromConstants, removeFromNativeAllLanguages, }; |