refactor code

main
tt 9 months ago
parent e929ac1769
commit 2760d638b6

@ -1,4 +1,4 @@
import {languageList} from "~/configs/supportLanguage"; import { languages } from "~/config";
const HeadInfo = ({ const HeadInfo = ({
title = "", title = "",
@ -11,7 +11,7 @@ const HeadInfo = ({
<title>{title}</title> <title>{title}</title>
<meta name="description" content={description}/> <meta name="description" content={description}/>
{ {
languageList.map((item) => { languages.map((item) => {
const currentPage = page; const currentPage = page;
let hrefLang = item.code; let hrefLang = item.code;
if (item.lang == 'en') { if (item.lang == 'en') {
@ -25,7 +25,7 @@ const HeadInfo = ({
}) })
} }
{ {
languageList.map((item) => { languages.map((item) => {
const currentPage = page; const currentPage = page;
let hrefLang = item.code; let hrefLang = item.code;
let href = `${process.env.NEXT_PUBLIC_SITE_URL}/${item.lang}${currentPage}`; let href = `${process.env.NEXT_PUBLIC_SITE_URL}/${item.lang}${currentPage}`;

@ -4,17 +4,20 @@ export const locales = ['en', 'zh', 'ja'] as const;
export const languages = [ export const languages = [
{ {
code: "en-US",
lang: "en", lang: "en",
language: "English", language: "English",
}, },
{ {
code: "zh-CN",
lang: "zh", lang: "zh",
language: "简体中文", language: "简体中文",
}, },
{ {
code: "ja-JP",
lang: "ja", lang: "ja",
language: "日本語", language: "日本語",
}, }
] ]
export const pathnames = { export const pathnames = {
@ -26,3 +29,10 @@ export const localePrefix = 'as-needed';
export type AppPathnames = keyof typeof pathnames; export type AppPathnames = keyof typeof pathnames;
export const getLanguageByLang = (lang) => {
for (let i = 0; i < languages.length; i++) {
if (lang == languages[i].lang) {
return languages[i];
}
}
}

@ -1,26 +0,0 @@
export const languageList = [
{
code: "en-US",
lang: "en",
language: "English",
},
{
code: "zh-CN",
lang: "zh",
language: "简体中文",
},
{
code: "ja-JP",
lang: "ja",
language: "日本語",
}
]
export const getLanguageByLang = (lang) => {
for (let i = 0; i < languageList.length; i++) {
if (lang == languageList[i].lang) {
return languageList[i];
}
}
}

@ -16,7 +16,7 @@ export const config = {
// Set a cookie to remember the previous locale for // Set a cookie to remember the previous locale for
// all requests that have a locale prefix // all requests that have a locale prefix
'/(en|zh)/:path*', '/(en|zh|ja)/:path*',
// Enable redirects that add missing locales // Enable redirects that add missing locales
// (e.g. `/pathnames` -> `/en/pathnames`) // (e.g. `/pathnames` -> `/en/pathnames`)

Loading…
Cancel
Save