Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/utils/loadIntlMessages.ts
1006 views
1
import fs from "fs/promises"
2
import { GetStaticPropsContext } from "next"
3
import path from "path"
4
5
export default async function loadI18nMessages({
6
locale,
7
defaultLocale,
8
}: GetStaticPropsContext) {
9
// If the default locale is being used we can skip it
10
if (locale === defaultLocale) {
11
return {}
12
}
13
14
if (locale !== defaultLocale) {
15
const languagePath = path.join(process.cwd(), `locales/${locale}.json`)
16
try {
17
const contents = await fs.readFile(languagePath, "utf-8")
18
return JSON.parse(contents) as Record<string, string>
19
} catch (error) {
20
console.error(error)
21
}
22
}
23
}
24
25