Skip to content

Commit cd4c23e

Browse files
author
sheepzh
committed
Fix export
1 parent a72a35e commit cd4c23e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

script/crowdin/common.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ export async function mergeMessage(
8888
}
8989
const sourceItemSet = transMsg(existMessages[SOURCE_LOCALE])
9090
Object.entries(messages).forEach(([locale, itemSet]) => {
91-
let existMessage: any = existMessages[locale]
92-
if (!existMessage) {
93-
existMessages[locale] = existMessage = {}
94-
}
91+
let existMessage: any = existMessages[locale] || {}
9592
Object.entries(itemSet).forEach(([path, text]) => {
9693
if (!text) {
9794
// Not translated
@@ -105,6 +102,10 @@ export async function mergeMessage(
105102
const pathSeg = path.split('.')
106103
fillItem(pathSeg, 0, existMessage, text)
107104
})
105+
if (Object.keys(existMessage).length) {
106+
// Only merge the locale with any translated strings
107+
existMessages[locale] = existMessage
108+
}
108109
})
109110

110111
const existFile = fs.readFileSync(filePath, { encoding: 'utf-8' })

script/crowdin/export-translation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ async function processFile(client: CrowdinClient, file: SourceFilesModel.File, d
66
const itemSets: Partial<Record<timer.Locale, ItemSet>> = {}
77
for (const locale of ALL_TRANS_LOCALES) {
88
const lang = crowdinLangOf(locale)
9-
const items: any = await client.downloadTranslations(file.id, lang)
10-
itemSets[locale] = items
9+
const items: ItemSet = await client.downloadTranslations(file.id, lang)
10+
items && Object.keys(items).length && (itemSets[locale] = items)
1111
}
1212
await mergeMessage(dir, file.name.replace('.json', '.ts'), itemSets)
1313
}

0 commit comments

Comments
 (0)