Skip to content

Commit

Permalink
Merge pull request #26 from Themrsajad/feature/language-switcher
Browse files Browse the repository at this point in the history
Feature/language switcher
  • Loading branch information
payam-zahedi authored Feb 2, 2025
2 parents 6fcab25 + de1522e commit 4d83e12
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
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

0 comments on commit 4d83e12

Please sign in to comment.