Skip to content

Commit 556cf7d

Browse files
authored
Merge pull request #12130 from ethereum/lang-menu-reduce-data
refactor: trim translation progress data
2 parents d3af5ac + 49cbdaf commit 556cf7d

File tree

4 files changed

+329
-1240
lines changed

4 files changed

+329
-1240
lines changed

src/components/LanguagePicker/useLanguagePicker.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import type {
1313
import { MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
1414
import { languages } from "@/lib/utils/translations"
1515

16-
import progressData from "@/data/translationProgress.json"
16+
import progressDataJson from "@/data/translationProgress.json"
1717

1818
import { DEFAULT_LOCALE } from "@/lib/constants"
1919

20-
const data = progressData as ProjectProgressData[]
20+
const progressData = progressDataJson satisfies ProjectProgressData[]
2121

2222
export const useLanguagePicker = (
2323
handleClose?: () => void,
@@ -88,20 +88,24 @@ export const useLanguagePicker = (
8888
}
8989

9090
// English will not have a dataItem
91-
const dataItem = data.find(
91+
const dataItem = progressData.find(
9292
({ languageId }) =>
9393
i18nItem.crowdinCode.toLowerCase() === languageId.toLowerCase()
9494
)
9595

9696
const approvalProgress =
97-
localeOption === DEFAULT_LOCALE ? 100 : dataItem?.approvalProgress || 0
97+
localeOption === DEFAULT_LOCALE
98+
? 100
99+
: Math.floor(
100+
(dataItem!.words.approved / dataItem!.words.total) * 100
101+
) || 0
98102

99-
if (data.length === 0)
103+
if (progressData.length === 0)
100104
throw new Error(
101105
"Missing translation progress data; check GitHub action"
102106
)
103107

104-
const totalWords = data[0].words.total
108+
const totalWords = progressData[0].words.total
105109

106110
const wordsApproved =
107111
localeOption === DEFAULT_LOCALE

0 commit comments

Comments
 (0)