Skip to content

Commit

Permalink
feat-wip: Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Oct 2, 2023
1 parent 7edec12 commit f07d7cd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
20 changes: 20 additions & 0 deletions public/locales/tr/servers.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,25 @@
"disk": "Disk",
"size": "Boyut",
"full": "Dolu"
},
"extensions": {
"title": "Eklentiler",
"description": "Sunucunuzda kullanılan eklentileri bu sayfa aracılığıyla yönetebilirsiniz.",
"add": "Ekle",
"remove": "Çıkar",
"upload": "Eklenti Yükle",
"name": "Eklenti Adı",
"version": "Versiyon",
"updated_at": "Güncellenme Tarihi",
"toasts": {
"assign": "Seçtiğiniz eklentiler sunucuya başarıyla atandı.",
"unassign": "Seçtiğiniz eklentiler sunucudan başarıyla kaldırıldı."
},
"unassign": {
"title": "Emin misiniz?",
"description": "Bu işlem geri alınamaz. Seçilen eklentiler sunucudan kaldırılacaktır, devam etmek istiyor musunuz?",
"no": "Vazgeç",
"yes": "Onayla"
}
}
}
20 changes: 19 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function middleware(request: NextRequest) {
if (
request.nextUrl.pathname.includes("_next") ||
request.nextUrl.pathname.includes("favicon") ||
request.nextUrl.pathname.includes("locales")
request.nextUrl.pathname.includes("locales") ||
isStaticAsset(request)
) {
return NextResponse.next()
}
Expand All @@ -24,6 +25,8 @@ export function middleware(request: NextRequest) {
}

if (currentUser && Date.now() > JSON.parse(currentUser).expired_at) {
console.log(request.referrer)

request.cookies.delete("currentUser")
const response = NextResponse.redirect(
new URL("/auth/login?redirect=" + urlBeforeRedirect, request.url)
Expand Down Expand Up @@ -55,3 +58,18 @@ export function middleware(request: NextRequest) {

return NextResponse.next()
}

function isStaticAsset(req: NextRequest) {
const extensions = [
".js",
".css",
".png",
".jpg",
".jpeg",
".gif",
".svg",
".mp3",
]
const requestPath = req.nextUrl.pathname.toLowerCase()
return extensions.some((extension) => requestPath.endsWith(extension))
}
49 changes: 29 additions & 20 deletions src/pages/servers/[server_id]/extensions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ServerExtensionPage() {
const tableRef = useRef<any>()
const sidebarCtx = useSidebarContext()
const { toast } = useToast()
const { i18n } = useTranslation()
const { t, i18n } = useTranslation("servers")

const columns: DivergentColumn<IExtension, string>[] = [
{
Expand All @@ -66,9 +66,9 @@ export default function ServerExtensionPage() {
{
accessorKey: "display_name",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Eklenti Adı" />
<DataTableColumnHeader column={column} title={t("extensions.name")} />
),
title: "Eklenti Adı",
title: t("extensions.name"),
cell: ({ row }) => (
<>
<Link
Expand All @@ -92,9 +92,12 @@ export default function ServerExtensionPage() {
{
accessorKey: "version",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Versiyon" />
<DataTableColumnHeader
column={column}
title={t("extensions.version")}
/>
),
title: "Versiyon",
title: t("extensions.version"),
},
{
accessorKey: "updated",
Expand All @@ -108,9 +111,12 @@ export default function ServerExtensionPage() {
})
},
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Güncellenme Tarihi" />
<DataTableColumnHeader
column={column}
title={t("extensions.updated_at")}
/>
),
title: "Güncellenme Tarihi",
title: t("extensions.updated_at"),
sortingFn: compareNumericString,
},
]
Expand Down Expand Up @@ -142,8 +148,8 @@ export default function ServerExtensionPage() {
})
.then(() => {
toast({
title: "Başarılı",
description: "Seçtiğiniz eklentiler sunucuya başarıyla atandı.",
title: t("success"),
description: t("extensions.toasts.assign"),
})
sidebarCtx[SIDEBARCTX_STATES.refreshSelected]()
fetchData()
Expand All @@ -161,8 +167,8 @@ export default function ServerExtensionPage() {
})
.then(() => {
toast({
title: "Başarılı",
description: "Seçtiğiniz eklentiler sunucudan başarıyla kaldırıldı.",
title: t("success"),
description: t("extensions.toasts.unassign"),
})
setSelected([])
tableRef.current?.resetRowSelection()
Expand All @@ -174,13 +180,13 @@ export default function ServerExtensionPage() {
return (
<>
<PageHeader
title="Eklentiler"
description="Sunucunuzda kullanılan eklentileri bu sayfa aracılığı ile yönetebilirsiniz."
title={t("extensions.title")}
description={t("extensions.description")}
rightSide={
<Link href="/settings/extensions">
<Button className="rounded-full">
<UploadCloud className="mr-2 h-4 w-4" />
Eklenti Yükle
{t("extensions.upload")}
</Button>
</Link>
}
Expand Down Expand Up @@ -209,23 +215,26 @@ export default function ServerExtensionPage() {
disabled={selected.length === 0}
>
<MinusCircle className="mr-2 h-4 w-4" />
Çıkar
{t("extensions.remove")}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Emin misiniz?</AlertDialogTitle>
<AlertDialogTitle>
{t("extensions.unassign.title")}
</AlertDialogTitle>
<AlertDialogDescription>
Bu işlem geri alınamaz. Seçilen eklentiler sunucudan
kaldırılacaktır, devam etmek istiyor musunuz?
{t("extensions.unassign.description")}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Vazgeç</AlertDialogCancel>
<AlertDialogCancel>
{t("extensions.unassign.no")}
</AlertDialogCancel>
<AlertDialogAction
onClick={() => onUnassignExtension(selected)}
>
Onayla
{t("extensions.unassign.yes")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
Expand Down

0 comments on commit f07d7cd

Please sign in to comment.