Skip to content
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

fix sidebar English language #286

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions components/Header/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { useEffect, useRef } from 'react';
import useFocusTrap from '../hooks/useFocusTrap';
import { useTheme } from 'next-themes';
import Link from 'next/link';
import LocalSwitcher from './LocalSwitcher';
import useTypedLocale from '@/hooks/useTypedLocale';
import clsx from 'clsx';
import { useTranslations } from 'next-intl';

type NavigationItems = {
title: string;
Expand All @@ -18,41 +22,41 @@ type NavItem = {
text?: string;
};

const navigationItems: NavigationItems[] = [
{
title: 'Newbies',
text: 'פעם ראשונה בקוד פתוח',
linkPath: '/newbies',
},
{
title: 'Members',
text: 'מי שכבר התנסה בקוד פתוח',
linkPath: '/members',
},
{
title: 'Maintainers',
text: 'בעלי פרויקטים שרוצים להצטרף',
linkPath: '/maintainers',
},
{
title: 'מי אנחנו',
linkPath: '/about',
},
{
title: 'הפרויקטים',
linkPath: '/projects',
},
];

interface SidebarProps {
isOpen: boolean;
toggleSidebar: () => void;
}

const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
const sidebarRef = useRef<HTMLDivElement | null>(null);

const localActive = useTypedLocale();
const { theme } = useTheme();
const t = useTranslations('Components.sideBar');
const navigationItems: NavigationItems[] = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this scope this array will be re declared on every render

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but how can I use the "useTranslations" hook outside this scope?

{
title: 'Newbies',
text: 'פעם ראשונה בקוד פתוח',
linkPath: '/newbies',
},
{
title: 'Members',
text: 'מי שכבר התנסה בקוד פתוח',
linkPath: '/members',
},
{
title: 'Maintainers',
text: 'בעלי פרויקטים שרוצים להצטרף',
linkPath: '/maintainers',
},
{
title: 'מי אנחנו',
linkPath: '/about',
},
{
title: 'הפרויקטים',
linkPath: '/projects',
},
];

useEffect(() => {
const handleOutsideClick = (event: MouseEvent) => {
Expand Down Expand Up @@ -83,14 +87,26 @@ const Sidebar: React.FC<SidebarProps> = ({ isOpen, toggleSidebar }) => {
return (
<div
ref={sidebarRef}
className={`fixed inset-y-0 right-0 z-50 bg-lightBg dark:bg-darkBg border-l border-l-blue-400 w-[75%] shadow-lg transform transition-transform ease-in-out duration-300 ${
isOpen ? '-translate-x-0' : 'translate-x-full'
}`}
className={clsx(
`fixed inset-y-0 z-50 bg-lightBg dark:bg-darkBg border-l
border-l-blue-400 w-[75%] shadow-lg transform transition-transform
ease-in-out duration-300`,
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not use dir here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't worked so well using dir

'left-0': localActive === 'en',
'right-0': localActive === 'he',
'-translate-x-0': isOpen,
'-translate-x-full': !isOpen && localActive === 'en',
'translate-x-full': !isOpen && localActive === 'he',
}
)}
>
{isOpen ? (
<div className="p-5 flex flex-col gap-14">
<div className="flex items-center justify-between">
<Darkmode />
<div className="flex gap-3 items-center">
<LocalSwitcher />
<Darkmode />
</div>
<button onClick={toggleSidebar}>
{theme === 'dark' ? (
<Image
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@radix-ui/react-accordion": "^1.1.2",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"clsx": "^2.1.1",
"embla-carousel-autoplay": "^8.0.0-rc12",
"embla-carousel-react": "^8.0.0-rc12",
"eslint": "8.43.0",
Expand Down
7 changes: 7 additions & 0 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
"firstParagraph": "It's worth trying our Questions & Answers section, and if the answer isn't there, we have the",
"discordTitle": "Discord Channel",
"secondParagraph": "with genuinely, the nicest people you'll ever meet, who are always willing to help anyone who needs it"
},
"sideBar": {
"newbies": "First time in Open Source",
"members": "already participated in Open Source",
"maintainers": "Project maintainers who wants to join",
"whoWeAre": "About us",
"theProjects": "The projects"
}
},
"Header": {
Expand Down
7 changes: 7 additions & 0 deletions public/locales/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@
"firstParagraph": "שווה לנסות את סקטור השאלות תשובות שלנו, ואם התשובה לא כאן, יש לנו את",
"discordTitle": "ערוץ הדיסקורד",
"secondParagraph": "עם אנשים באמת, אבל באמת, הכי נחמדים שיש ומוכנים לעזור לכל מי שרק צריך."
},
"sideBar": {
"newbies": "פעם ראשונה בקוד פתוח",
"members": "מי שכבר התנסה בקוד פתוח",
"maintainers": "בעלי פרויקטים שרוצים להצטרף",
"whoWeAre": "מי אנחנו",
"theProjects": "הפרויקטים"
}
},
"Header": {
Expand Down
Loading