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

Feature/language switcher #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"about": "About Us",
"cafeFlutter": "Cafe Flutter",
"community": "Community",
"team": "Our Team"
"team": "Our Team",
"donation": "Donate",
"language": "FA"
}
},
"footer": {
Expand Down
4 changes: 3 additions & 1 deletion public/locales/fa/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"about": "درباره ما",
"cafeFlutter": "کافه فلاتر",
"team": "تیم ما",
"community": "کامیونیتی"
"community": "کامیونیتی",
"donation": "حمایت مالی",
"language": "EN"
}
},
"footer": {
Expand Down
10 changes: 9 additions & 1 deletion src/components/widgets/header/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Logo from '~/components/widgets/header/Logo.astro';
import ToggleTheme from '~/components/common/ToggleTheme.astro';
import ToggleMenu from '~/components/common/ToggleMenu.astro';
import Button from '~/components/ui/Button.astro';

import { getRelativeLocaleUrl } from 'astro:i18n';
import { getHomePermalink } from '~/utils/permalinks';
import { trimSlash } from '~/utils/permalinks';
import type { CallToAction } from '~/types';
Expand Down Expand Up @@ -56,6 +56,13 @@ const currentPath = `/${trimSlash(new URL(Astro.url).pathname)}`;
// header actions base position
const callToActionPrimaryPosition = actions.filter((action) => action.position === 'primary');
const callToActionSecondaryPosition = actions.filter((action) => action.position === 'secondary');

const isHomepage = Astro.url.pathname === '/' || Astro.url.pathname === '/en';
const currentLang = currentPath.startsWith('/en') ? 'en' : 'fa';
const toggleLang = getRelativeLocaleUrl(
currentLang === 'fa' ? 'en' : 'fa',
currentLang === 'en' ? currentPath.slice(3) : isHomepage ? undefined : currentPath
);
---

<header
Expand Down Expand Up @@ -170,6 +177,7 @@ const callToActionSecondaryPosition = actions.filter((action) => action.position
{callToActionPrimaryPosition.map((btnProps) => (
<Button
{...btnProps}
href={toggleLang}
class="border-gray-300 text-gray-400 text-lg font-medium uppercase h-10 px-3 inline-flex justify-center items-center py-0 shadow-none w-auto"
/>
))}
Expand Down
7 changes: 3 additions & 4 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ export function headerData(translation: TranslationValues) {
],
actions: [
{
text: 'en',
href: 'https://github.com/onwidget/astrowind',
target: '_blank',
text: translation.header.menu.language,
target: '_self',
position: 'primary',
} as CallToAction,
{
text: 'حمایت مالی',
text: translation.header.menu.donation,
href: '/donate',
target: '_blank',
position: 'secondary',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/en/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import HeroSection from '~/components/widgets/hero/Hero.astro';
import i18n from '~/utils/i18n';

const metadata = {
title: 'Persin Flutter',
title: 'Persian Flutter',
ignoreTitleTemplate: true,
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Donation from '~/components/widgets/Donation.astro';
import i18n from '~/utils/i18n';
const metadata = {
title: 'Persin Flutter',
title: 'Persian Flutter',
ignoreTitleTemplate: true,
};
Expand Down