added korean project locale support
This commit is contained in:
parent
38f6e755f0
commit
d899fbdee5
1 changed files with 17 additions and 7 deletions
|
@ -1,10 +1,8 @@
|
||||||
import { useState } from "react"
|
import { useContext, useState } from "react"
|
||||||
import { Helmet } from "react-helmet-async"
|
import { Helmet } from "react-helmet-async"
|
||||||
import { useLocation } from "react-router-dom"
|
import { useLocation } from "react-router-dom"
|
||||||
import styled from "styled-components"
|
import styled from "styled-components"
|
||||||
|
|
||||||
import { PageData, Map } from "../../../types/types"
|
|
||||||
|
|
||||||
import GithubLinkIcon from "../../components/GithubLinkIcon"
|
import GithubLinkIcon from "../../components/GithubLinkIcon"
|
||||||
import MainContent from "../../components/MainContent"
|
import MainContent from "../../components/MainContent"
|
||||||
import PostCard from "../../components/PostCard"
|
import PostCard from "../../components/PostCard"
|
||||||
|
@ -22,6 +20,9 @@ import portfolio from "../../data/portfolio.json"
|
||||||
import _map from "../../data/map.json"
|
import _map from "../../data/map.json"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
|
|
||||||
|
import type { PageData, Map } from "../../../types/types"
|
||||||
|
import { globalContext, SiteLocale } from "../../globalContext"
|
||||||
|
|
||||||
const map: Map = _map
|
const map: Map = _map
|
||||||
|
|
||||||
const StyledTitle = styled.h1<{ pageType: PageType }>`
|
const StyledTitle = styled.h1<{ pageType: PageType }>`
|
||||||
|
@ -53,13 +54,21 @@ enum PageType {
|
||||||
UNSEARCHABLE,
|
UNSEARCHABLE,
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchContent = async (pageType: PageType, url: string) => {
|
const fetchContent = async (
|
||||||
|
pageType: PageType,
|
||||||
|
url: string,
|
||||||
|
locale: SiteLocale
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
if (pageType == PageType.UNSEARCHABLE) {
|
if (pageType == PageType.UNSEARCHABLE) {
|
||||||
return await import(`../../data/content/unsearchable${url}.json`)
|
return await import(`../../data/content/unsearchable${url}.json`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await import(`../../data/content${url}.json`)
|
if (locale == "en") {
|
||||||
|
return await import(`../../data/content${url}.json`)
|
||||||
|
} else {
|
||||||
|
return await import(`../../data/content${url}.${locale}.json`)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -82,6 +91,7 @@ const categorizePageType = (url: string): PageType => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
|
const { globalState } = useContext(globalContext)
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
|
||||||
const [pageData, setPageData] = useState<PageData | undefined>(undefined)
|
const [pageData, setPageData] = useState<PageData | undefined>(undefined)
|
||||||
|
@ -163,7 +173,7 @@ const Page = () => {
|
||||||
repo: "",
|
repo: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchContent(pageType, url).then((fetched_content) => {
|
fetchContent(pageType, url, globalState.locale).then((fetched_content) => {
|
||||||
if (!fetched_content) {
|
if (!fetched_content) {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
return
|
return
|
||||||
|
@ -262,7 +272,7 @@ const Page = () => {
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
})
|
})
|
||||||
}, [location])
|
}, [location, globalState.locale])
|
||||||
|
|
||||||
if (isLoading) return <Loading />
|
if (isLoading) return <Loading />
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue