Files
Folo/scripts/copy-translation.ts
T
Stephen Zhou 46bc1876e8 feat(mobile): translation for settings (#3391)
* feat(mobile): translation for settings

* general

* appearance

* data control

* account

* invitation

* about

* privacy

* list

* actions

* update action

* update list and common words

* settings
2025-04-02 23:59:19 +08:00

48 lines
1.4 KiB
TypeScript

import fs from "node:fs"
import path from "node:path"
const sourceDir = "./locales/common"
const targetDir = "./locales/common"
const keysToCopy: string[] = [
// // kept the duplicate keys in locales/app
// "words.starred",
// "words.inbox",
// "words.feeds",
// "words.lists",
// "words.search",
"cancel",
"close",
"confirm",
]
const keysToPlace = ["words.cancel", "words.close", "words.confirm"]
const copyTranslations = (sourceDir: string, targetDir: string) => {
const sourceFiles = fs.readdirSync(sourceDir)
sourceFiles.forEach((file) => {
const sourceFilePath = path.join(sourceDir, file)
const targetFilePath = path.join(targetDir, file)
if (fs.statSync(sourceFilePath).isDirectory()) {
// Recursively copy translations from subdirectories
copyTranslations(sourceFilePath, targetFilePath)
} else if (path.extname(file) === ".json") {
const sourceContent = JSON.parse(fs.readFileSync(sourceFilePath, "utf-8"))
const targetContent = fs.existsSync(targetFilePath)
? JSON.parse(fs.readFileSync(targetFilePath, "utf-8"))
: {}
keysToCopy.forEach((key, index) => {
const targetKey = keysToPlace[index] ?? key
if (sourceContent[key] && !targetContent[targetKey]) {
targetContent[targetKey] = sourceContent[key]
}
})
fs.writeFileSync(targetFilePath, `${JSON.stringify(targetContent, null, 2)}\n`)
}
})
}
copyTranslations(sourceDir, targetDir)