Skip to content

Commit 56ced3d

Browse files
committed
Add Arabic for translation
1 parent ee54bfb commit 56ced3d

File tree

9 files changed

+45
-37
lines changed

9 files changed

+45
-37
lines changed

src/app/components/HelpUs/MemberList.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { getMembers, MemberInfo } from "@api/crowdin"
8+
import { getMembers } from "@api/crowdin"
9+
import { useRequest } from "@app/hooks/useRequest"
910
import { t } from "@app/locale"
1011
import { ElDivider } from "element-plus"
11-
import { defineComponent, onMounted, ref } from "vue"
12+
import { defineComponent } from "vue"
1213

1314
const _default = defineComponent(() => {
14-
const list = ref<MemberInfo[]>([])
15-
onMounted(async () => {
15+
const { data: list } = useRequest(async () => {
1616
const members = await getMembers() || []
17-
members.sort((a, b) => (a.joinedAt || "").localeCompare(b.joinedAt || ""))
18-
list.value = members
17+
return members.sort((a, b) => (a.joinedAt || "").localeCompare(b.joinedAt || ""))
1918
})
2019
return () => (
2120
<div class="member-container">
2221
<ElDivider>{t(msg => msg.helpUs.contributors)}</ElDivider>
2322
<div>
24-
{list.value.map(({ avatarUrl, username }) => (
23+
{list.value?.map(({ avatarUrl, username }) => (
2524
<a href={`https://crowdin.com/profile/${username}`} target="_blank">
2625
<img src={avatarUrl} alt={username} title={username} />
2726
</a>

src/app/components/HelpUs/ProgressList.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
*/
77

88
import { getTranslationStatus, TranslationStatusInfo } from "@api/crowdin"
9-
import { ElLoading, ElProgress, ProgressProps } from "element-plus"
10-
import { defineComponent, onMounted, Ref, ref } from "vue"
9+
import { ElProgress, ProgressProps } from "element-plus"
10+
import { defineComponent } from "vue"
1111
import localeMessages from "@i18n/message/common/locale"
1212
import { t } from "@app/locale"
13+
import { useRequest } from "@app/hooks/useRequest"
1314

1415
type SupportedLocale = timer.Locale | timer.TranslatingLocale
1516

@@ -39,6 +40,7 @@ const localeCrowdMap: { [locale in SupportedLocale]: string } = {
3940
vi: "vi",
4041
sk: "sk",
4142
mn: "mn",
43+
ar: "ar",
4244
}
4345

4446
const crowdLocaleMap: { [locale: string]: SupportedLocale } = {}
@@ -50,12 +52,14 @@ type ProgressInfo = {
5052
progress: number
5153
}
5254

53-
function convert2Info(translationStatus: TranslationStatusInfo): ProgressInfo {
54-
const { languageId, translationProgress } = translationStatus
55-
return {
56-
locale: crowdLocaleMap[languageId] || languageId,
57-
progress: translationProgress
58-
}
55+
const convert2Info = ({ languageId, translationProgress }: TranslationStatusInfo): ProgressInfo => ({
56+
locale: crowdLocaleMap[languageId] || languageId,
57+
progress: translationProgress
58+
} satisfies ProgressInfo)
59+
60+
const compareLocale = ({ progress: pa, locale: la }: ProgressInfo, { progress: pb, locale: lb }: ProgressInfo): number => {
61+
const progressDiff = (pb ?? 0) - (pa ?? 0)
62+
return progressDiff || la?.localeCompare?.(lb) || 0
5963
}
6064

6165
function computeType(progress: number): ProgressProps["status"] {
@@ -70,27 +74,19 @@ function computeType(progress: number): ProgressProps["status"] {
7074

7175
const CONTAINER_CLZ = 'progress-container'
7276

73-
async function queryData(listRef: Ref<ProgressInfo[]>) {
74-
const loading = ElLoading.service({ target: `.${CONTAINER_CLZ}`, text: t(msg => msg.helpUs.loading) })
77+
async function queryData(): Promise<ProgressInfo[]> {
7578
const langList = await getTranslationStatus()
76-
listRef.value = langList.map(convert2Info)
77-
.sort((a, b) => {
78-
const progressDiff = b.progress - a.progress
79-
if (progressDiff === 0) {
80-
return a.locale.localeCompare(b.locale)
81-
} else {
82-
return progressDiff
83-
}
84-
})
85-
loading.close()
79+
return langList?.map?.(convert2Info)?.sort(compareLocale)
8680
}
8781

8882
const _default = defineComponent(() => {
89-
const list: Ref<ProgressInfo[]> = ref([])
90-
onMounted(() => queryData(list))
83+
const { data: list } = useRequest(
84+
queryData,
85+
{ loadingTarget: `.${CONTAINER_CLZ}`, loadingText: t(msg => msg.helpUs.loading) },
86+
)
9187
return () => (
9288
<div class={CONTAINER_CLZ}>
93-
{list.value.map(({ locale, progress }) => (
89+
{list.value?.map?.(({ locale, progress }) => (
9490
<ElProgress percentage={progress} strokeWidth={22} status={computeType(progress)}>
9591
<span class="progress-text">{`${progress}%`}</span>
9692
<span class="language-name">{localeMessages[locale]?.name || locale}</span>

src/app/hooks/useRequest.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { ElLoadingService } from "element-plus"
12
import { Ref, onMounted, ref } from "vue"
23

34
type Option<T> = {
45
manual?: boolean
56
defaultValue?: T
7+
loadingTarget?: string | Ref<HTMLElement>
8+
loadingText?: string
69
}
710

811
type Result<T> = {
@@ -13,17 +16,21 @@ type Result<T> = {
1316
}
1417

1518
export const useRequest = <T,>(getter: () => Promise<T> | T, option?: Option<T>): Result<T> => {
16-
const { manual = false, defaultValue } = option || {}
19+
const { manual = false, defaultValue, loadingTarget, loadingText } = option || {}
1720
const data: Ref<T> = ref(defaultValue) as Ref<T>
1821
const loading = ref(false)
22+
let loadingInstance: { close?: () => void } = null
1923

2024
const refreshAsync = async () => {
2125
loading.value = true
26+
const loadingEl = typeof loadingTarget === "string" ? loadingTarget : loadingTarget?.value
27+
loadingEl && (loadingInstance = ElLoadingService({ target: loadingEl, text: loadingText }))
2228
try {
2329
const value = await getter?.()
2430
data.value = value
2531
} finally {
2632
loading.value = false
33+
loadingInstance?.close?.()
2734
}
2835
}
2936
const refresh = () => { refreshAsync() }

src/app/locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { I18nResultItem, I18nKey as _I18nKey, t as _t } from "@i18n"
99
import { tN as _tN } from "@i18n"
1010
import messages, { AppMessage } from "@i18n/message/app"
11-
import { VNode } from "vue"
11+
import type { VNode } from "vue"
1212

1313
export type I18nKey = _I18nKey<AppMessage>
1414

src/i18n/message/common/locale-resource.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,9 @@
8080
},
8181
"mn": {
8282
"name": "Монгол"
83+
},
84+
"ar": {
85+
"name": "عربي",
86+
"rtl": true
8387
}
8488
}

src/i18n/message/common/locale.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import resource from './locale-resource.json'
99

1010
type MetaBase = {
1111
name: string
12+
rtl?: boolean
1213
}
1314

1415
type Meta = MetaBase & {

src/util/fifo-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FIFOCache<T> {
1919
if (!threshold) {
2020
threshold = DEFAULT_THRESHOLD
2121
} else if (!Number.isInteger(threshold)) {
22-
throw new Error('Threashold MUST BE integer')
22+
throw new Error('Threshold MUST BE integer')
2323
} else if (threshold <= 0) {
2424
threshold = DEFAULT_THRESHOLD
2525
}

src/util/window.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { onMounted, onUnmounted } from "vue"
22

33
/**
44
* handle window visible change
5-
*
5+
*
66
* @since 1.4.4
77
*/
88
export function handleWindowVisibleChange(handler: () => void) {
9-
const hanlderInner = () => document.visibilityState === 'visible' && handler()
10-
onMounted(() => document.addEventListener('visibilitychange', hanlderInner))
11-
onUnmounted(() => document.removeEventListener('visibilitychange', hanlderInner))
9+
const handlerInner = () => document.visibilityState === 'visible' && handler()
10+
onMounted(() => document.addEventListener('visibilitychange', handlerInner))
11+
onUnmounted(() => document.removeEventListener('visibilitychange', handlerInner))
1212
}

types/timer/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ declare namespace timer {
5050
| 'vi'
5151
| 'sk'
5252
| 'mn'
53+
| 'ar'
5354

5455
type ExtensionMetaFlag = "rateOpen"
5556

0 commit comments

Comments
 (0)