-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: Dynamic locale components and change
- Loading branch information
Showing
8 changed files
with
171 additions
and
109 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Playing() { | ||
return ( | ||
<div className="flex flex-col items-center justify-center h-screen"> | ||
<div className="text-4xl font-bold">Playing</div> | ||
</div> | ||
); | ||
} |
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,21 @@ | ||
"use client"; | ||
|
||
import useLocales from "@/hooks/useLocales"; | ||
|
||
export default function Locales() { | ||
const { locales, setLocale } = useLocales(); | ||
|
||
return ( | ||
<div className="flex flex-row justify-center gap-3 lg:gap-4 flex-wrap"> | ||
{locales.map((locale) => ( | ||
<button key={locale.code} onClick={() => setLocale(locale.code)}> | ||
<img | ||
src={locale.flag} | ||
title={locale.name} | ||
className="h-8 w-8 opacity-50 hover:opacity-100 hover:scale-105 transition" | ||
/> | ||
</button> | ||
))} | ||
</div> | ||
); | ||
} |
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,106 @@ | ||
import { useLocalStorage } from "usehooks-ts"; | ||
|
||
const locales = [ | ||
{ | ||
code: "en", | ||
name: "English", | ||
flag: "/flags/uk.svg", | ||
}, | ||
{ | ||
code: "fr", | ||
name: "Français", | ||
flag: "/flags/fr.svg", | ||
}, | ||
{ | ||
code: "it", | ||
name: "Italiano", | ||
flag: "/flags/it.svg", | ||
}, | ||
{ | ||
code: "es", | ||
name: "Español", | ||
flag: "/flags/es.svg", | ||
}, | ||
{ | ||
code: "ru", | ||
name: "Pусский", | ||
flag: "/flags/ru.svg", | ||
}, | ||
{ | ||
code: "de", | ||
name: "Deutsch", | ||
flag: "/flags/de.svg", | ||
}, | ||
{ | ||
code: "id", | ||
name: "Indonesia", | ||
flag: "/flags/id.svg", | ||
}, | ||
{ | ||
code: "cz", | ||
name: "Czech", | ||
flag: "/flags/cz.svg", | ||
}, | ||
{ | ||
code: "tr", | ||
name: "Turkish", | ||
flag: "/flags/tr.svg", | ||
}, | ||
{ | ||
code: "gr", | ||
name: "Greece", | ||
flag: "/flags/gr.svg", | ||
}, | ||
{ | ||
code: "zh_tw", | ||
name: "Traditionnal Chinese", | ||
flag: "/flags/zh_tw.svg", | ||
}, | ||
{ | ||
code: "ar", | ||
name: "Arabic", | ||
flag: "/flags/ar.svg", | ||
}, | ||
{ | ||
code: "eo", | ||
name: "Esperanto", | ||
flag: "/flags/eo.svg", | ||
}, | ||
{ | ||
code: "nl", | ||
name: "Dutch", | ||
flag: "/flags/nl.svg", | ||
}, | ||
{ | ||
code: "az", | ||
name: "Azərbaycan", | ||
flag: "/flags/az.png", | ||
}, | ||
] as const; | ||
|
||
function getBrowserLocale() { | ||
if (typeof navigator === "undefined") return "en"; | ||
|
||
return navigator.language?.split("-")[0] ?? "en"; | ||
} | ||
|
||
function getInitialLocale() { | ||
const browserLocale = getBrowserLocale(); | ||
return locales.find((locale) => locale.code === browserLocale) ?? locales[0]; | ||
} | ||
|
||
export default function useLocales() { | ||
const [currentLocale, setCurrentLocale] = useLocalStorage( | ||
"locale", | ||
getInitialLocale() | ||
); | ||
|
||
const setLocale = (locale: (typeof locales)[number]["code"]) => { | ||
const newLocale = locales.find((l) => l.code === locale); | ||
if (newLocale) { | ||
setCurrentLocale(newLocale); | ||
} | ||
}; | ||
|
||
return { locales, currentLocale, setLocale }; | ||
} |
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,15 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
transpilePackages: ["@repo/ui"], | ||
|
||
async redirects() { | ||
// Remove .php extension | ||
return [ | ||
{ | ||
source: "/:path*.php", | ||
destination: "/:path*", | ||
permanent: true, | ||
}, | ||
]; | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -5,7 +5,11 @@ | |
{ | ||
"name": "next" | ||
} | ||
] | ||
], | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./*"] | ||
} | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.