const fs = require('fs');
const root = "./src"
let allFiles = []


function getFiles(dir){
    let files = fs.readdirSync(dir)
    files.forEach(file => {
        let path = dir + '/' + file
        if(fs.lstatSync(path).isDirectory()){
            getFiles(path)
        }else allFiles.push(path)
    })
}

getFiles(root)
let messages = new Set()
allFiles.forEach(file => {
    let data = fs.readFileSync(file, {encoding: 'utf-8'})
    let matched = data.matchAll(/\$t\([\'\"]{1}([^\"\']+)[\'\"]{1}/g)
    let i = 0
    for(let item of matched){
        i ++
        messages.add(item[1])
    }
})
fs.writeFileSync("./i18n-messages.txt", Array.from(messages).join("\n"))
console.log("done!")