added korean project locale support

This commit is contained in:
Kim, Jimin 2022-03-26 20:52:21 +09:00
parent 38f6e755f0
commit d899fbdee5

View file

@ -1,10 +1,8 @@
import { useState } from "react"
import { useContext, useState } from "react"
import { Helmet } from "react-helmet-async"
import { useLocation } from "react-router-dom"
import styled from "styled-components"
import { PageData, Map } from "../../../types/types"
import GithubLinkIcon from "../../components/GithubLinkIcon"
import MainContent from "../../components/MainContent"
import PostCard from "../../components/PostCard"
@ -22,6 +20,9 @@ import portfolio from "../../data/portfolio.json"
import _map from "../../data/map.json"
import { useEffect } from "react"
import type { PageData, Map } from "../../../types/types"
import { globalContext, SiteLocale } from "../../globalContext"
const map: Map = _map
const StyledTitle = styled.h1<{ pageType: PageType }>`
@ -53,13 +54,21 @@ enum PageType {
UNSEARCHABLE,
}
const fetchContent = async (pageType: PageType, url: string) => {
const fetchContent = async (
pageType: PageType,
url: string,
locale: SiteLocale
) => {
try {
if (pageType == PageType.UNSEARCHABLE) {
return await import(`../../data/content/unsearchable${url}.json`)
}
if (locale == "en") {
return await import(`../../data/content${url}.json`)
} else {
return await import(`../../data/content${url}.${locale}.json`)
}
} catch (err) {
return
}
@ -82,6 +91,7 @@ const categorizePageType = (url: string): PageType => {
}
const Page = () => {
const { globalState } = useContext(globalContext)
const location = useLocation()
const [pageData, setPageData] = useState<PageData | undefined>(undefined)
@ -163,7 +173,7 @@ const Page = () => {
repo: "",
}
fetchContent(pageType, url).then((fetched_content) => {
fetchContent(pageType, url, globalState.locale).then((fetched_content) => {
if (!fetched_content) {
setIsLoading(false)
return
@ -262,7 +272,7 @@ const Page = () => {
setIsLoading(false)
})
}, [location])
}, [location, globalState.locale])
if (isLoading) return <Loading />