-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] - Add translation next-intl #15
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import EventsPage from "@/features/events"; | ||
import { unstable_setRequestLocale } from "next-intl/server"; | ||
|
||
type Props = { | ||
params: { locale: string }; | ||
}; | ||
const Events = ({ params: { locale } }: Props) => { | ||
unstable_setRequestLocale(locale); | ||
return <EventsPage />; | ||
}; | ||
export default Events; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Metadata } from "next"; | ||
import { NextIntlClientProvider } from "next-intl"; | ||
import { getMessages } from "next-intl/server"; | ||
import { Sora } from "next/font/google"; | ||
import "./globals.css"; | ||
import Wrapper from "@/components/layout/wrapper"; | ||
const sora = Sora({ subsets: ["latin"] }); | ||
|
||
export const metadata: Metadata = { | ||
title: "Welcome to Hammercode!", | ||
description: "Hammercode is a community based in Palu, Indonesia", | ||
}; | ||
|
||
export default async function LocaleRootLayout({ | ||
children, | ||
params: { locale }, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
params: { locale: string }; | ||
}>) { | ||
const messages = await getMessages(); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<link rel="icon" href="/assets/icons/ic_hmc-dark.svg" sizes="any" /> | ||
</head> | ||
<body className={sora.className}> | ||
<NextIntlClientProvider messages={messages}> | ||
<Wrapper>{children}</Wrapper> | ||
</NextIntlClientProvider> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Home from "@/features/home"; | ||
|
||
export default function HomePage() { | ||
return <Home />; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
import type { Metadata } from "next"; | ||
import { Sora } from "next/font/google"; | ||
import "./globals.css"; | ||
import Wrapper from "@/components/layout/wrapper"; | ||
import { ReactNode } from "react"; | ||
|
||
const sora = Sora({ subsets: ["latin"] }); | ||
|
||
export const metadata: Metadata = { | ||
title: "Welcome to Hammercode!", | ||
description: "Hammercode is a community based in Palu, Indonesia", | ||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<link rel="icon" href="/assets/icons/ic_hmc-dark.svg" sizes="any" /> | ||
</head> | ||
<body className={sora.className}> | ||
<Wrapper>{children}</Wrapper> | ||
</body> | ||
</html> | ||
); | ||
export default function RootLayout({ children }: Props) { | ||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
const NotFound = () => { | ||
return <div>404</div>; | ||
}; | ||
export default NotFound; | ||
"use client"; | ||
|
||
import Error from "next/error"; | ||
|
||
export default function NotFound() { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Error statusCode={404} /> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Home from "@/features/home"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default function HomePage() { | ||
return <Home />; | ||
export default function RootPage() { | ||
redirect("/en"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useTransition } from "react"; | ||
import { useLocale } from "next-intl"; | ||
import { useParams } from "next/navigation"; | ||
|
||
import { usePathname, useRouter } from "@/lib/navigation"; | ||
import { Locale } from "@/lib/i18n"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { Button } from "@/components/ui/button"; | ||
|
||
const LocaleToggle = () => { | ||
const locale = useLocale(); | ||
const router = useRouter(); | ||
const [isPending, startTransition] = useTransition(); | ||
const pathname = usePathname(); | ||
const params = useParams(); | ||
|
||
const handleSwitch = (value: string) => { | ||
const nextLocale = value as Locale; | ||
startTransition(() => { | ||
router.replace( | ||
// @ts-expect-error -- TypeScript will validate that only known `params` | ||
// are used in combination with a given `pathname`. Since the two will | ||
// always match for the current route, we can skip runtime checks. | ||
{ pathname, params }, | ||
{ locale: nextLocale } | ||
); | ||
}); | ||
}; | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button size="sm" variant="outline" className={`w-[3rem] font-normal`} disabled={isPending}> | ||
{locale === "id" ? "🇮🇩 ID" : "🇬🇧 EN"} | ||
<span className="sr-only">Toggle locale</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end" className="min-w-[3rem]"> | ||
<DropdownMenuItem onClick={() => handleSwitch("id")} className="cursor-pointer"> | ||
🇮🇩 ID | ||
</DropdownMenuItem> | ||
<DropdownMenuItem onClick={() => handleSwitch("en")} className="cursor-pointer"> | ||
🇬🇧 EN | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; | ||
|
||
export default LocaleToggle; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import Link from "next/link"; | ||
import { Link } from "@/lib/navigation"; | ||
import { ComponentProps } from "react"; | ||
import { pathnames } from "@/lib/config"; | ||
|
||
import { NavbarListType } from "./types"; | ||
|
||
const NavbarList = ({ title, link }: NavbarListType) => { | ||
function NavbarList<Pathname extends keyof typeof pathnames>({ href, ...rest }: ComponentProps<typeof Link<Pathname>>) { | ||
return ( | ||
<Link href={link}> | ||
<span>{title}</span> | ||
<Link href={href} {...rest}> | ||
<span>{rest.title}</span> | ||
</Link> | ||
); | ||
}; | ||
} | ||
|
||
export default NavbarList; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Pathnames, LocalePrefix } from "next-intl/routing"; | ||
|
||
export const defaultLocale = "en" as const; | ||
export const locales = ["en", "id"] as const; | ||
|
||
export const pathnames = { | ||
"/": "/", | ||
"/about": { | ||
en: "/about", | ||
id: "/tentang", | ||
}, | ||
"/events": { | ||
en: "/events", | ||
id: "/acara", | ||
}, | ||
"/contact": { | ||
en: "/contact", | ||
id: "/kontak", | ||
}, | ||
} satisfies Pathnames<typeof locales>; | ||
|
||
export const localePrefix: LocalePrefix<typeof locales> = "always"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { notFound } from "next/navigation"; | ||
import { getRequestConfig } from "next-intl/server"; | ||
import { locales } from "./config"; | ||
|
||
export type Locale = (typeof locales)[number]; | ||
|
||
export default getRequestConfig(async ({ locale }) => { | ||
if (!locales.includes(locale as Locale)) notFound(); | ||
|
||
return { | ||
messages: (await (locale === "en" ? import("../locales/en.json") : import(`../locales/${locale}.json`))).default, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createLocalizedPathnamesNavigation } from "next-intl/navigation"; | ||
import { locales, pathnames, localePrefix } from "./config"; | ||
export const { Link, getPathname, redirect, usePathname, useRouter } = createLocalizedPathnamesNavigation({ | ||
locales, | ||
pathnames, | ||
localePrefix, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Layout": { | ||
"navbar": { | ||
"link-1": "About", | ||
"link-2": "Events", | ||
"link-3": "Contact" | ||
} | ||
}, | ||
"HomePage": { | ||
"section-hero": { | ||
"title": "Improve Your Skill by Talking High-Quality Classes with Us!", | ||
"description": "Hammercode is a tech community based in Palu, Indonesia" | ||
} | ||
}, | ||
"EventsPage": { | ||
"title": "Events", | ||
"description": "Join the fun events and have an unforgettable experience!" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better di map keknya ini lung @mpsalunggg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lupa awkwkwk:') @vickyadrii
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sikat, nanti mention aje kalo sudah @mpsalunggg