Skip to content

Commit c8fff02

Browse files
authored
fix more text rendering wiht translation (#835)
1 parent 32006db commit c8fff02

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/pages/blog/[id].js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { distanceToNow, formatDate } from '@/lib/date-formatting'
2929
import { MDXElements } from '@/lib/mdx-elements'
3030
import { getAllPostsIds, getPostData } from '@/lib/posts'
3131
import { i18nConfig } from '@/config/i18n.mjs'
32+
import { loadCatalog } from '../../i18n'
3233

3334
export default function Post({ source, frontmatter, postId, translation }) {
3435
const date = new Date(frontmatter.date)
@@ -123,7 +124,7 @@ export async function getStaticPaths() {
123124
}
124125
}
125126

126-
export async function getStaticProps({ params }) {
127+
export async function getStaticProps({ params, locale }) {
127128
const postData = getPostData(params.id)
128129
const filePath = path.join(process.cwd(), 'src/posts', postData.file)
129130
const source = fs.readFileSync(filePath, 'utf8')
@@ -136,11 +137,14 @@ export async function getStaticProps({ params }) {
136137
},
137138
})
138139

140+
const translation = await loadCatalog(locale ?? 'en')
141+
139142
return {
140143
props: {
141144
source: mdxSource,
142145
frontmatter: data,
143146
postId: params.id,
147+
translation,
144148
},
145149
}
146150
}

src/pages/blog/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Link } from '@/components/mdx'
2020
import { distanceToNow, formatDate } from '@/lib/date-formatting'
2121
import { getSortedPostsMetadata } from '@/lib/posts'
2222
import { generateRssFeed } from '@/lib/rss-feed'
23+
import { loadCatalog } from '../../i18n'
2324

2425
const SinglePost = ({ page }) => {
2526
const date = new Date(page.date)
@@ -109,12 +110,14 @@ export default function Blog({ allPostsData }) {
109110
)
110111
}
111112

112-
export async function getStaticProps({ params, locale = 'en' }) {
113+
export async function getStaticProps({ locale = 'en' }) {
113114
const allPostsData = getSortedPostsMetadata()
114115
generateRssFeed(allPostsData)
116+
const translation = await loadCatalog(locale)
115117
return {
116118
props: {
117119
allPostsData,
120+
translation,
118121
},
119122
}
120123
}

0 commit comments

Comments
 (0)