2022-12-16 13:44:25 +01:00
import ScriptUtils from "./ScriptUtils"
2023-08-10 15:36:32 +02:00
import { Utils } from "../src/Utils"
2022-12-13 11:32:47 +01:00
import * as fs from "fs"
2022-12-16 13:44:25 +01:00
async function main ( args : string [ ] ) {
2023-07-09 10:25:55 +02:00
let directory = "./langs"
{
const dirs = [ "layers" , "themes" , "shared-questions" ]
for ( const dir of dirs ) {
const layerIndex = args . findIndex ( ( s ) = > s === "--" + dir )
if ( layerIndex >= 0 ) {
directory = "./langs/" + dir
args . splice ( layerIndex , 1 )
}
}
}
2022-12-16 13:44:25 +01:00
if ( args . length !== 1 ) {
2023-01-11 03:53:58 +01:00
console . log (
2023-07-09 10:25:55 +02:00
"Usage: first argument is the fully qualified key of the string to remove. Removes translations in the core translations, unless '--layers' or '--themes' is given"
2023-01-11 03:53:58 +01:00
)
2022-12-13 11:32:47 +01:00
return
}
2023-07-09 10:25:55 +02:00
// Path within the JSON which will be removed - not the path in the filesystem!
2022-12-13 11:32:47 +01:00
const path = args [ 0 ] . split ( "." )
2023-10-02 00:23:20 +02:00
console . log ( "Removing translation string " , path , "from the translations for " + directory )
2023-07-09 10:25:55 +02:00
const files = ScriptUtils . readDirRecSync ( directory , 1 ) . filter ( ( f ) = > f . endsWith ( ".json" ) )
2024-05-23 11:53:46 +02:00
const removedLanguages : string [ ] = [ ]
2022-12-13 11:32:47 +01:00
for ( const file of files ) {
2024-05-23 11:53:46 +02:00
const rawContents = fs . readFileSync ( file , { encoding : "utf-8" } )
const json = JSON . parse ( rawContents )
Utils . WalkPath ( path , json , ( found ) = > {
removedLanguages . push ( file )
2024-06-16 16:06:26 +02:00
console . log ( "Removing " , found )
2024-05-23 11:53:46 +02:00
return undefined
} )
const lastChar = rawContents . endsWith ( "\n" ) ? "\n" : ""
fs . writeFileSync ( file , JSON . stringify ( json , null , " " ) + lastChar )
}
2024-06-16 16:06:26 +02:00
if ( removedLanguages . length === 0 ) {
console . warn ( "No items removed. Doublecheck the paths" )
} else {
console . log ( "Removed items in " + removedLanguages . join ( ", " ) )
2022-12-13 11:32:47 +01:00
}
}
const args = [ . . . process . argv ]
args . splice ( 0 , 2 )
main ( args ) . then ( ( _ ) = > {
console . log ( "All done!" )
} )