Skip to content

Commit 3a13780

Browse files
authored
Bulk translation (#2357)
1 parent ab5aa42 commit 3a13780

File tree

11 files changed

+851
-626
lines changed

11 files changed

+851
-626
lines changed

frontend/src/modules/project-detail/project-detail.jsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ const ProjectDetail = ({ data: inData, isModal, setVisible }) => {
113113
<div className={styles.detailView}>
114114
<div className={classNames('container', { isModal })}>
115115
<div className="head">
116-
<h5 className="h-caps-m">project</h5>
116+
<h5 className="h-caps-m">
117+
<Trans>Project</Trans>
118+
</h5>
117119
{data?.reviewStatus === 'SUBMITTED' && (
118120
<div className="pending">
119121
<h5>Pending Approval</h5>
@@ -205,21 +207,29 @@ const ProjectDetail = ({ data: inData, isModal, setVisible }) => {
205207
</SwiperSlide>
206208
))}
207209
</Swiper>
208-
<h3 className="h-m w-bold">Background</h3>
210+
<h3 className="h-m w-bold">
211+
<Trans>Background</Trans>
212+
</h3>
209213
<p className="two-cols">{data?.background}</p>
210-
<h3 className="h-m w-bold">Purpose</h3>
214+
<h3 className="h-m w-bold">
215+
<Trans>Purpose</Trans>
216+
</h3>
211217
<p className="two-cols">{data?.purpose}</p>
212218
<div className="cols">
213219
<div className="col outcomes">
214-
<h3 className="h-m w-bold">Expected Outcomes</h3>
220+
<h3 className="h-m w-bold">
221+
<Trans>Expected Outcomes</Trans>
222+
</h3>
215223
<ul>
216224
{data?.outcomes?.map((it) => (
217225
<li>{it}</li>
218226
))}
219227
</ul>
220228
</div>
221229
<div className="col highlights">
222-
<h3 className="h-m w-bold">Key Highlights</h3>
230+
<h3 className="h-m w-bold">
231+
<Trans>Key Highlights</Trans>
232+
</h3>
223233
<ul>
224234
{data?.highlights?.map((it) => {
225235
if (it.url && it.url !== '') {
@@ -263,7 +273,9 @@ const ProjectDetail = ({ data: inData, isModal, setVisible }) => {
263273
</div>
264274
<div className="cols">
265275
<div className="col">
266-
<h3 className="h-m w-bold">Life Cycle Stage</h3>
276+
<h3 className="h-m w-bold">
277+
<Trans>Life Cycle Stage</Trans>
278+
</h3>
267279
<div className="tag-list">
268280
{lifecycleTagsToShow?.map((tag) => (
269281
<div className="tag-item" key={tag?.tag}>
@@ -280,7 +292,9 @@ const ProjectDetail = ({ data: inData, isModal, setVisible }) => {
280292
</div>
281293
</div>
282294
<div className="col">
283-
<h3 className="h-m w-bold">Tags</h3>
295+
<h3 className="h-m w-bold">
296+
<Trans>Tags</Trans>
297+
</h3>
284298
<div className="tag-list">
285299
{tagsToShow?.map((tag) => (
286300
<div className="tag-item" key={tag?.tag}>

frontend/src/pages/[type]/[id].jsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import React, { memo } from 'react'
1+
import React, { memo, useState, useEffect } from 'react'
22
import { useRouter } from 'next/router'
33
import NewDetailsView from '../../modules/details-page/view'
44
import api from '../../utils/api'
55
import { getTypeByResource } from '../../modules/flexible-forms/view'
66
import { loadCatalog } from '../../translations/utils'
77
import Head from 'next/head'
88
import ProjectDetail from '../../modules/project-detail/project-detail'
9+
import translationService from '../../utils/translationService'
10+
import { LoadingOutlined } from '@ant-design/icons'
11+
import { Trans } from '@lingui/macro'
12+
import styles from './index.module.scss'
913

1014
const VALID_TYPES = [
1115
'initiative',
@@ -21,14 +25,16 @@ const VALID_TYPES = [
2125
]
2226

2327
const Details = ({
24-
data,
28+
data: initialData,
2529
translations,
2630
setLoginVisible,
2731
isAuthenticated,
2832
domainValue,
2933
}) => {
3034
const router = useRouter()
3135
const { type, id } = router.query
36+
const [data, setData] = useState(null)
37+
const [isLoading, setIsLoading] = useState(true)
3238
if (!VALID_TYPES.includes(type)) {
3339
return <p>Invalid type!</p>
3440
}
@@ -45,6 +51,45 @@ const Details = ({
4551
return slicedWords
4652
}
4753

54+
useEffect(() => {
55+
const translateData = async () => {
56+
setIsLoading(true)
57+
if (router.locale !== 'en' && initialData) {
58+
try {
59+
const dataWithType = {
60+
...initialData,
61+
type: type?.replace('-', '_'),
62+
id: initialData.id || id,
63+
}
64+
65+
const translated = await translationService.getTranslatedResources(
66+
[dataWithType],
67+
router.locale,
68+
['title', 'summary', 'background', 'purpose', 'highlights']
69+
)
70+
71+
setData(translated[0])
72+
} catch (error) {
73+
console.error('Translation error:', error)
74+
setData(initialData)
75+
}
76+
} else {
77+
setData(initialData)
78+
}
79+
setIsLoading(false)
80+
}
81+
82+
translateData()
83+
}, [router.locale, initialData, type, id])
84+
85+
if (isLoading || !data) {
86+
return (
87+
<div className={styles.loadingContainer}>
88+
<LoadingOutlined spin /> <Trans>Loading...</Trans>
89+
</div>
90+
)
91+
}
92+
4893
return (
4994
<>
5095
<Head>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.loadingContainer {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100vh;
6+
}

frontend/src/translations/locales/en.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)