Skip to content

Commit

Permalink
improvement: show default language on index path (remove /en path) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandstetterm authored Apr 3, 2024
1 parent cb9a685 commit 3db9234
Show file tree
Hide file tree
Showing 33 changed files with 220 additions and 141 deletions.
21 changes: 11 additions & 10 deletions src/components/Footer/Footer.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
---
import getTranslatedContent from "@utils/directus";
import {getLangFromUrl, getPathForLanguage} from "../../i18n/utils";
import { Github } from "@icons/Github";
import { Instagram } from "@icons/Instagram";
import { Linkedin } from "@icons/Linkedin";
import { Podcast } from "@icons/Podcast";
import { X } from "@icons/X";
import { Xing } from "@icons/Xing";
import { Inovex } from "@icons/Inovex";
import getTranslatedContent from "@utils/directus";
import "./Footer.scss";
const {lang} = Astro.params;
const content = await getTranslatedContent("Footer", lang!);
const lang = getLangFromUrl(Astro.url);
const content = await getTranslatedContent("Footer", lang);
---

<footer>
Expand Down Expand Up @@ -88,13 +89,13 @@ const content = await getTranslatedContent("Footer", lang!);
<nav class="footer__right">
<ul class="footer__internal-links">
<li>
<a href=`/${lang}#home`>{content.home}</a>
<a href={getPathForLanguage(lang, "#home")}>{content.home}</a>
</li>
<li>
<a href=`/${lang}#features`>{content.features}</a>
<a href={getPathForLanguage(lang, "#features")}>{content.features}</a>
</li>
<li>
<a href=`/${lang}#about`>{content.about}</a>
<a href={getPathForLanguage(lang, "#about")}>{content.about}</a>
</li>
<li>
<a href=`/new`>{content.getStarted}</a>
Expand All @@ -106,16 +107,16 @@ const content = await getTranslatedContent("Footer", lang!);
<div class="footer__bottom-content">
<ul class="footer__legal-links">
<li>
<a href=`/${lang}/data-protection`>{content.privacy}</a>
<a href={getPathForLanguage(lang, "/data-protection")}>{content.privacy}</a>
</li>
<li>
<a href=`/${lang}/cookie-policy`>{content.cookies}</a>
<a href={getPathForLanguage(lang, "/cookie-policy")}>{content.cookies}</a>
</li>
<li>
<a href=`/${lang}/terms`>{content.terms}</a>
<a href={getPathForLanguage(lang, "/terms")}>{content.terms}</a>
</li>
<li>
<a href=`/${lang}/legal-notice`>{content.legal_notice}</a>
<a href={getPathForLanguage(lang, "/legal-notice")}>{content.legal_notice}</a>
</li>
</ul>
<span>{content.copyright}</span>
Expand Down
15 changes: 8 additions & 7 deletions src/components/Navbar/Navbar.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
import getTranslatedContent from "@utils/directus";
import { getLangFromUrl, getPathForLanguage } from '../../i18n/utils';
import { Logo } from "../Logo";
import { Plus } from "../../icons/Plus";
import { Link } from "../Link/Link";
import getTranslatedContent from "@utils/directus";
import UserMenu from "@components/UserMenu/UserMenu";
import "./Navbar.scss";
const {lang} = Astro.params;
const content = await getTranslatedContent("Header", lang!);
const lang = getLangFromUrl(Astro.url);
const content = await getTranslatedContent("Header", lang);
const userMenuLabels = {
germanLabel: content.german,
Expand All @@ -20,18 +21,18 @@ const userMenuLabels = {
<nav id="navbar" class="navbar">
<ul>
<li>
<a aria-label={content.home} href=`/${lang}`>
<a aria-label={content.home} href={getPathForLanguage(lang, "/")}>
<Logo />
</a>
</li>
<li>
<a href=`/${lang}#home`>{content.home}</a>
<a href={getPathForLanguage(lang, "#home")}>{content.home}</a>
</li>
<li>
<a href=`/${lang}#features`>{content.features}</a>
<a href={getPathForLanguage(lang, "#features")}>{content.features}</a>
</li>
<li>
<a href=`/${lang}#about`>{content.aboutUs}</a>
<a href={getPathForLanguage(lang, "#about")}>{content.aboutUs}</a>
</li>
<li>
<UserMenu client:load {...userMenuLabels} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const UserMenu = ({
</a>
</li>
<li>
<a href="/en">
<a href="/">
<svg
width="32"
height="32"
Expand Down
17 changes: 17 additions & 0 deletions src/i18n/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const languages = {
en: 'English',
de: 'German',
};

const defaultLang = 'en';

export function getLangFromUrl(url: URL) {
const [, lang] = url.pathname.split('/');
if (lang in languages) return lang as keyof typeof languages;
return defaultLang;
}

export function getPathForLanguage(lang: keyof typeof languages, path: string) {
return lang === defaultLang ? path : `/${lang}${path}`;
}

8 changes: 5 additions & 3 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { getLangFromUrl } from "src/i18n/utils";
import Navbar from "../components/Navbar/Navbar.astro";
import Footer from "../components/Footer/Footer.astro";
Expand All @@ -7,10 +8,11 @@ export interface Props {
}
const { title } = Astro.props;
const lang = getLangFromUrl(Astro.url);
---

<!doctype html>
<html lang="en">
<html lang={lang}>
<head>
<meta charset="UTF-8" />
<meta name="description" content="Open source online retrospective & collaboration tool - fast onboarding, jump right into a session with your team" />
Expand All @@ -25,11 +27,11 @@ const { title } = Astro.props;
</head>
<body>
<div class="body_wrapper">
<Navbar />
<Navbar lang={lang} />
<main>
<slot />
</main>
<Footer />
<Footer lang={lang} />
</div>
</body>
</html>
Expand Down
15 changes: 8 additions & 7 deletions src/layouts/LegalLayout.astro
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
---
import { getLangFromUrl, getPathForLanguage } from "src/i18n/utils";
import getTranslatedContent from "@utils/directus";
import { ViewTransitions } from "astro:transitions";
import Layout from "./Layout.astro";
import getTranslatedContent from "@utils/directus";
import "./LegalLayout.scss";
const {lang} = Astro.params;
const content = await getTranslatedContent("Legal_Menu", lang!);
const lang = getLangFromUrl(Astro.url);
const content = await getTranslatedContent("Legal_Menu", lang);
const pathname = new URL(Astro.request.url).pathname;
const navItems = [
{
href: `/${lang}/data-protection`,
href: getPathForLanguage(lang, "/data-protection"),
name: content.privacy,
},
{
href: `/${lang}/cookie-policy`,
href: getPathForLanguage(lang, "/cookie-policy"),
name: content.cookies,
},
{
href: `/${lang}/terms`,
href: getPathForLanguage(lang, "/terms"),
name: content.terms,
},
{
href: `/${lang}/legal-notice`,
href: getPathForLanguage(lang, "/legal-notice"),
name: content.legal_notice,
},
];
Expand Down
20 changes: 0 additions & 20 deletions src/pages/[lang]/cookie-policy.astro

This file was deleted.

21 changes: 0 additions & 21 deletions src/pages/[lang]/data-protection.astro

This file was deleted.

20 changes: 0 additions & 20 deletions src/pages/[lang]/legal-notice.astro

This file was deleted.

26 changes: 0 additions & 26 deletions src/pages/[lang]/terms.astro

This file was deleted.

11 changes: 11 additions & 0 deletions src/pages/cookie-policy.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Cookie_Policy", "en");
---

<LegalLayout>
<section set:html={content.Cookie_Policy} />
</LegalLayout>
12 changes: 12 additions & 0 deletions src/pages/data-protection.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Privacy_Policy", "en");
---

<LegalLayout>
<section class="legal__content" set:html={content.Privacy_Policy} />
</LegalLayout>

11 changes: 11 additions & 0 deletions src/pages/de/cookie-policy.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Cookie_Policy", "de");
---

<LegalLayout>
<section set:html={content.Cookie_Policy} />
</LegalLayout>
12 changes: 12 additions & 0 deletions src/pages/de/data-protection.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Privacy_Policy", "de");
---

<LegalLayout>
<section class="legal__content" set:html={content.Privacy_Policy} />
</LegalLayout>

8 changes: 2 additions & 6 deletions src/pages/[lang]/index.astro → src/pages/de/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
import type { GetStaticPaths } from "astro";
import Hero from "@views/Hero/Hero.astro";
import Choices from "@views/Choices/Choices.astro";
import Uniqueness from "@views/Uniqueness/Uniqueness.astro";
Expand All @@ -9,18 +8,15 @@ import TargetUser from "@views/TargetUser/TargetUser.astro";
import Features from "@views/Features/Features.astro";
import Feedback from "@views/Feedback/Feedback.astro";
import AboutUs from "@views/AboutUs/AboutUs.astro";
export const getStaticPaths = (() => {
return [{ params: { lang: "en" } }, { params: { lang: "de" } }];
}) satisfies GetStaticPaths;
---

<Layout title="scrumlr.io - Online collaboration">
<Layout title="scrumlr.io - Online collaboration" >
<Hero />
<Choices />
<Uniqueness />
<Mobile />
<Features />
<TargetUser />
<Feedback />
<AboutUs />
</Layout>
11 changes: 11 additions & 0 deletions src/pages/de/legal-notice.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Legal_Notice", "de");
---

<LegalLayout>
<section set:html={content.legal_notice} />
</LegalLayout>
17 changes: 17 additions & 0 deletions src/pages/de/terms.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
import LegalLayout from "@layouts/LegalLayout.astro";
import getTranslatedContent from "@utils/directus.ts";
import "@styles/Legal.scss";
const content = await getTranslatedContent("Terms_Conditions", "de");
---

<LegalLayout>
<section set:html={content.Terms_Conditions} />
</LegalLayout>

<style>
section {
text-wrap: wrap;
}
</style>
Loading

0 comments on commit 3db9234

Please sign in to comment.