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 = ({
title = "",
@ -11,7 +11,7 @@ const HeadInfo = ({
<title>{title}</title>
<meta name="description" content={description}/>
{
languageList.map((item) => {
languages.map((item) => {
const currentPage = page;
let hrefLang = item.code;
if (item.lang == 'en') {
@ -25,7 +25,7 @@ const HeadInfo = ({
})
}
{
languageList.map((item) => {
languages.map((item) => {
const currentPage = page;
let hrefLang = item.code;
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 = [
{
code: "en-US",
lang: "en",
language: "English",
},
{
code: "zh-CN",
lang: "zh",
language: "简体中文",
},
{
code: "ja-JP",
lang: "ja",
language: "日本語",
},
}
]
export const pathnames = {
@ -26,3 +29,10 @@ export const localePrefix = 'as-needed';
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
// all requests that have a locale prefix
'/(en|zh)/:path*',
'/(en|zh|ja)/:path*',
// Enable redirects that add missing locales
// (e.g. `/pathnames` -> `/en/pathnames`)

Loading…
Cancel
Save