mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
improved language support
This commit is contained in:
parent
7fa6ffbe2a
commit
f19f7e65d8
@ -71,10 +71,10 @@ const noto = Noto_Serif_JP({
|
||||
variable: '--font-noto'
|
||||
});
|
||||
|
||||
export const SupportedLocales: SupportedLocale[] = ['ja', 'en'];
|
||||
const locales = ['en', 'ja'] as const;
|
||||
|
||||
export function generateStaticParams() {
|
||||
return SupportedLocales.map((locale) => ({ locale }));
|
||||
return locales.map((locale) => ({ locale }));
|
||||
}
|
||||
|
||||
export default async function RootLayout({
|
||||
@ -85,7 +85,7 @@ export default async function RootLayout({
|
||||
params: { locale?: SupportedLocale };
|
||||
}) {
|
||||
// Validate that the incoming `locale` parameter is valid
|
||||
const isValidLocale = SupportedLocales.some((cur: string) => cur === params?.locale);
|
||||
const isValidLocale = locales.some((cur: string) => cur === params?.locale);
|
||||
if (!isValidLocale) notFound();
|
||||
|
||||
if (params?.locale) {
|
||||
|
@ -1,11 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import clsx from 'clsx';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { createSharedPathnamesNavigation } from 'next-intl/navigation';
|
||||
|
||||
export type SupportedLocale = 'en' | 'ja';
|
||||
|
||||
const locales = ['en', 'ja'] as const;
|
||||
|
||||
function removeItem<T>(arr: Array<T>, value: T): Array<T> {
|
||||
const index = arr.indexOf(value);
|
||||
if (index > -1) {
|
||||
@ -15,6 +16,7 @@ function removeItem<T>(arr: Array<T>, value: T): Array<T> {
|
||||
}
|
||||
|
||||
export const LanguageControl = ({ lang }: { lang?: SupportedLocale }) => {
|
||||
const { Link, usePathname } = createSharedPathnamesNavigation({ locales });
|
||||
const pathName = usePathname();
|
||||
|
||||
const basePathName = () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user