mirror of
https://github.com/Spythere/spythere-portfolio.git
synced 2026-05-03 21:48:18 +00:00
translation (i18n)
This commit is contained in:
@@ -3,6 +3,7 @@ import { theme } from './theme';
|
||||
import { GlobalStyles } from './components/styles/Global.styled';
|
||||
import Navbar from './components/Navbar';
|
||||
import LandingSection from './components/LandingSection';
|
||||
import './i18n';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
|
||||
+35
-12
@@ -1,4 +1,11 @@
|
||||
import { StyledNavbar, StyledNavlink, StyledNavlinkBrand, StyledNavlinkList } from './styles/Navbar.styled';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
StyledLangButton,
|
||||
StyledNavbar,
|
||||
StyledNavlink,
|
||||
StyledNavlinkBrand,
|
||||
StyledNavlinkList,
|
||||
} from './styles/Navbar.styled';
|
||||
|
||||
interface NavLink {
|
||||
title: string;
|
||||
@@ -6,46 +13,62 @@ interface NavLink {
|
||||
}
|
||||
|
||||
function NavlinkList(props: { navlinks: NavLink[] }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<StyledNavlinkList>
|
||||
{props.navlinks.map((navlink) => (
|
||||
<StyledNavlink key={navlink.title} href={navlink.href}>
|
||||
{navlink.title}
|
||||
{t(`navbar.${navlink.title}`)}
|
||||
</StyledNavlink>
|
||||
))}
|
||||
|
||||
<LanguageChoice />
|
||||
</StyledNavlinkList>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NavlinkBrand(props: { name: string }) {
|
||||
return <StyledNavlinkBrand>{props.name}</StyledNavlinkBrand>;
|
||||
function LanguageChoice() {
|
||||
const { i18n } = useTranslation();
|
||||
|
||||
function changeLanguage() {
|
||||
i18n.changeLanguage(i18n.language == 'pl' ? 'en' : 'pl');
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<StyledLangButton onClick={changeLanguage}>{i18n.language}</StyledLangButton>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const navlinks = [
|
||||
// {
|
||||
// title: 'home',
|
||||
// href: '#',
|
||||
// },
|
||||
{
|
||||
title: 'HOME',
|
||||
title: 'about',
|
||||
href: '#',
|
||||
},
|
||||
{
|
||||
title: 'ABOUT',
|
||||
title: 'projects',
|
||||
href: '#',
|
||||
},
|
||||
{
|
||||
title: 'PROJECTS',
|
||||
href: '#',
|
||||
},
|
||||
{
|
||||
title: 'CONTACT',
|
||||
title: 'contact',
|
||||
href: '#',
|
||||
},
|
||||
];
|
||||
|
||||
export default function Navbar() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<StyledNavbar>
|
||||
<NavlinkBrand name="Spythere Portfolio" />
|
||||
<StyledNavlinkBrand>{t('navbar.title')}</StyledNavlinkBrand>
|
||||
<NavlinkList navlinks={navlinks} />
|
||||
</StyledNavbar>
|
||||
);
|
||||
|
||||
@@ -46,6 +46,10 @@ export const GlobalStyles = createGlobalStyle`
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
border: none;
|
||||
}
|
||||
|
||||
@keyframes typing {
|
||||
to { left: 100% }
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export const StyledNavlinkBrand = styled.div`
|
||||
|
||||
export const StyledNavlinkList = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1em;
|
||||
font-size: 1.1em;
|
||||
`;
|
||||
@@ -27,3 +28,15 @@ export const StyledNavlink = styled.a`
|
||||
/* color: black; */
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
export const StyledLangButton = styled.button`
|
||||
font-size: 1em;
|
||||
font-weight: bold;
|
||||
|
||||
padding: 0.25em 1em;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
|
||||
border: 1px solid ${({ theme }) => theme.colors.primary};
|
||||
background: none;
|
||||
`;
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
import localePL from './locales/pl.json';
|
||||
import localeEN from './locales/en.json';
|
||||
|
||||
const resources = {
|
||||
en: {
|
||||
translation: localeEN,
|
||||
},
|
||||
pl: {
|
||||
translation: localePL,
|
||||
},
|
||||
};
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
resources,
|
||||
lng: 'pl',
|
||||
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"navbar": {
|
||||
"title": "Spythere Portfolio",
|
||||
"home": "HOME",
|
||||
"about": "ABOUT",
|
||||
"projects": "PROJECTS",
|
||||
"contact": "CONTACT"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"navbar": {
|
||||
"title": "Spythere Portfolio",
|
||||
"home": "",
|
||||
"about": "O MNIE",
|
||||
"projects": "PROJEKTY",
|
||||
"contact": "KONTAKT"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user