chore: run bun format to automatically format the frontend code

This commit is contained in:
t0ng7u
2026-07-01 06:38:41 +08:00
parent e514db20f7
commit 5bf3468362
679 changed files with 2719 additions and 1717 deletions
+50 -13
View File
@@ -138,7 +138,14 @@ function countLeafKeys(obj) {
return count
}
function reorderLikeBase(base, target, fill, extras, missing, currentPath = []) {
function reorderLikeBase(
base,
target,
fill,
extras,
missing,
currentPath = []
) {
// If base is an object, we keep base's key order and recurse.
if (isPlainObject(base)) {
const out = {}
@@ -148,10 +155,24 @@ function reorderLikeBase(base, target, fill, extras, missing, currentPath = [])
for (const key of Object.keys(base)) {
const nextPath = [...currentPath, key]
if (Object.prototype.hasOwnProperty.call(t, key)) {
out[key] = reorderLikeBase(base[key], t[key], f[key], extras, missing, nextPath)
out[key] = reorderLikeBase(
base[key],
t[key],
f[key],
extras,
missing,
nextPath
)
} else {
missing.push(nextPath.join('.'))
out[key] = reorderLikeBase(base[key], undefined, f[key], extras, missing, nextPath)
out[key] = reorderLikeBase(
base[key],
undefined,
f[key],
extras,
missing,
nextPath
)
}
}
@@ -208,7 +229,8 @@ function isLikelyUntranslated({ locale, baseValue, value }) {
if (locale === 'ru') return true
// For fr/vi: still useful but noisier; keep it conservative.
if (locale === 'fr' || locale === 'vi') return /\b(the|and|or|to|with|please)\b/i.test(s)
if (locale === 'fr' || locale === 'vi')
return /\b(the|and|or|to|with|please)\b/i.test(s)
return false
}
@@ -234,7 +256,9 @@ async function main() {
const trans = json?.translation ?? {}
return { locale, score: countLeafKeys(trans) }
})
.sort((a, b) => b.score - a.score || a.locale.localeCompare(b.locale))[0]?.locale
.sort(
(a, b) => b.score - a.score || a.locale.localeCompare(b.locale)
)[0]?.locale
if (!baseLocale) throw new Error('No locale files found.')
@@ -289,31 +313,44 @@ async function main() {
}
if (Object.keys(extras).length > 0) {
await fs.writeFile(path.join(extrasDir, `${locale}.extras.json`), stableStringify(extras), 'utf8')
await fs.writeFile(
path.join(extrasDir, `${locale}.extras.json`),
stableStringify(extras),
'utf8'
)
} else {
await fs.rm(path.join(extrasDir, `${locale}.extras.json`), { force: true })
await fs.rm(path.join(extrasDir, `${locale}.extras.json`), {
force: true,
})
}
if (Object.keys(untranslated).length > 0) {
await fs.writeFile(
path.join(reportsDir, `${locale}.untranslated.json`),
stableStringify(untranslated),
'utf8',
'utf8'
)
} else {
await fs.rm(path.join(reportsDir, `${locale}.untranslated.json`), { force: true })
await fs.rm(path.join(reportsDir, `${locale}.untranslated.json`), {
force: true,
})
}
// Rewrite locale file in base order (even for en to normalize formatting)
await fs.writeFile(full, stableStringify(fixed), 'utf8')
}
await fs.writeFile(path.join(reportsDir, '_sync-report.json'), stableStringify(report), 'utf8')
console.log(`i18n sync done. Report: ${path.join(reportsDir, '_sync-report.json')}`)
await fs.writeFile(
path.join(reportsDir, '_sync-report.json'),
stableStringify(report),
'utf8'
)
console.log(
`i18n sync done. Report: ${path.join(reportsDir, '_sync-report.json')}`
)
}
main().catch((err) => {
console.error(err)
process.exitCode = 1
})