Skip to content

Commit

Permalink
Merge pull request #20 from opentelekomcloud-infra/static-i18n
Browse files Browse the repository at this point in the history
Localization
  • Loading branch information
tischrei authored Feb 21, 2024
2 parents 153ce3d + 3480e67 commit b3041c4
Show file tree
Hide file tree
Showing 21 changed files with 592 additions and 250 deletions.
26 changes: 26 additions & 0 deletions app/de/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Startpage from "@/components/pages/Startpage"
import Head from "next/head"


export default async function App() {
const metadata = await generateMetadata();
const startpageProps = {
locale: "de-DE" // Like Strapi API response
}
return (
<div>
<Head>
<title>{metadata.title}</title>
<meta name="description" content={metadata.description} />
</Head>
<Startpage props={startpageProps}></Startpage>
</div>
)
}

export async function generateMetadata() {
return {
title: "Discover the powerful services of our partners",
description: "Many start-ups and cloud service providers already work together with us an partners, using our technology and infrastructure for their cloud projects. This is a testament to their trust in the Open Telekom Cloud and our great partnership. You can start using these services today to improve your IT systems or your company's communications and benefit from the advantages of the GDPR-compliant European cloud."
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Overview from '@/components/Overview';
import Feature from '@/components/Feature';
import Teaser from '@/components/Teaser';
import { getAllPartners } from '@/lib/partners';
import PartnerContactForm from "@/components/ContactForm"
import PartnerContactForm from "@/components/PartnerContactForm"
import Quotation from "@/components/Quotation"
import Breadcrumbs from '@/components/Breadcrumbs';
import PartnerBreadcrumbs from '@/components/PartnerBreadcrumbs';
import Head from 'next/head';

let cachedPartnersData = null;
Expand All @@ -20,71 +20,43 @@ async function getCachedPartnersData() {
export default async function Page({ params }) {
// function to create partner pages

const { partner } = params;
const locale = "de-DE"
const linkLocale = "de"

// const { partner } = params;
const partners = await getCachedPartnersData()

// From all partners the one with the correct partner data is being collected.
let partnerData = partners.find(element => element.attributes.partner_id === params.partner);

const metadata = await generateMetadata({params});

// Overview
const overviewContent = {
headline: partnerData["attributes"]["overview_headline"],
description: partnerData["attributes"]["overview_description"],
product_type: partnerData["attributes"]["overview_product_type"],
company: partnerData["attributes"]["overview_company_name"],
website: partnerData["attributes"]["overview_website"],
media: partnerData.attributes.overview_media.data.attributes
}

// Teaser
const teaserContent = {
headline: partnerData["attributes"]["teaser_headline"],
description: partnerData["attributes"]["teaser_description"],
media: partnerData.attributes.teaser_media.data.attributes
}

// Features
const featuresContent = partnerData["attributes"]["features"]["data"]

// Quote
let quote = {}
if (partnerData.attributes.quotes.data) {
// prevent more than one quote
quote = partnerData.attributes.quotes.data[0]
}

// Compute the breadcrumb data based on the route
const breadcrumbs = [
{
label: 'Partners',
url: '/partners',
},
{
label: partnerData.attributes.overview_headline,
url: `/partners/${partnerData.attributes.partner_id}`,
},
];

return (
<div>
<Head>
<title>{metadata.title}</title>
<meta name="description" content={metadata.description} />
</Head>
<Breadcrumbs props={breadcrumbs}></Breadcrumbs>
<Overview props={overviewContent}></Overview>
<Teaser props={teaserContent}></Teaser>
{featuresContent.map(feature => {
<PartnerBreadcrumbs props={partnerData} linkLocale={linkLocale} locale={locale}></PartnerBreadcrumbs>
<Overview props={partnerData} locale={locale}></Overview>
<Teaser props={partnerData} locale={locale}></Teaser>
{partnerData["attributes"]["features"]["data"].map(feature => {
return (
<Feature key={feature["id"]} props={feature}></Feature>
<Feature key={feature["id"]} props={feature} locale={locale}></Feature>
)
})}
{/* Test if quote is existing */}
{quote && (
<Quotation props={quote}></Quotation>
<Quotation props={quote} locale={locale}></Quotation>
)}
<PartnerContactForm></PartnerContactForm>
<PartnerContactForm locale={locale}></PartnerContactForm>

</div>
)
Expand Down
2 changes: 1 addition & 1 deletion app/partners/page.js → app/de/partners/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { redirect } from 'next/navigation'

export default function Redirect({ }) {
// Click on 'Partner' link in breadcrumbs should redirect to home page
redirect('/')
redirect('/de')
}
26 changes: 26 additions & 0 deletions app/en/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Startpage from "@/components/pages/Startpage"
import Head from "next/head"


export default async function App() {
const metadata = await generateMetadata();
const startpageProps = {
locale: "en" // Like Strapi API response
}
return (
<div>
<Head>
<title>{metadata.title}</title>
<meta name="description" content={metadata.description} />
</Head>
<Startpage props={startpageProps}></Startpage>
</div>
)
}

export async function generateMetadata() {
return {
title: "Discover the powerful services of our partners",
description: "Many start-ups and cloud service providers already work together with us an partners, using our technology and infrastructure for their cloud projects. This is a testament to their trust in the Open Telekom Cloud and our great partnership. You can start using these services today to improve your IT systems or your company's communications and benefit from the advantages of the GDPR-compliant European cloud."
};
}
80 changes: 80 additions & 0 deletions app/en/partners/[partner]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Overview from '@/components/Overview';
import Feature from '@/components/Feature';
import Teaser from '@/components/Teaser';
import { getAllPartners } from '@/lib/partners';
import PartnerContactForm from "@/components/PartnerContactForm"
import Quotation from "@/components/Quotation"
import PartnerBreadcrumbs from '@/components/PartnerBreadcrumbs';
import Head from 'next/head';

let cachedPartnersData = null;

async function getCachedPartnersData() {
// get partner data from API and cache the value for the time creating the partner pages
if (cachedPartnersData === null) {
cachedPartnersData = await getAllPartners();
}
return cachedPartnersData;
}

export default async function Page({ params }) {
// function to create partner pages

const locale = "en"
const linkLocale = "en"

// const { partner } = params;
const partners = await getCachedPartnersData()

// From all partners the one with the correct partner data is being collected.
let partnerData = partners.find(element => element.attributes.partner_id === params.partner);

const metadata = await generateMetadata({params});

// Quote
let quote = {}
if (partnerData.attributes.quotes.data) {
// prevent more than one quote
quote = partnerData.attributes.quotes.data[0]
}

return (
<div>
<Head>
<title>{metadata.title}</title>
<meta name="description" content={metadata.description} />
</Head>
<PartnerBreadcrumbs props={partnerData} linkLocale={linkLocale} locale={locale}></PartnerBreadcrumbs>
<Overview props={partnerData} locale={locale}></Overview>
<Teaser props={partnerData} locale={locale}></Teaser>
{partnerData["attributes"]["features"]["data"].map(feature => {
return (
<Feature key={feature["id"]} props={feature} locale={locale}></Feature>
)
})}
{/* Test if quote is existing */}
{quote && (
<Quotation props={quote} locale={locale}></Quotation>
)}
<PartnerContactForm locale={locale}></PartnerContactForm>

</div>
)
}

export async function generateStaticParams() {
const partners = await getCachedPartnersData()
return partners.map((partner) => ({
partner: partner.attributes.partner_id
}));
}

export async function generateMetadata({ params }) {
const partners = await getCachedPartnersData()
let partnerData = partners.find(element => element.attributes.partner_id === params.partner);
return {
title: partnerData.attributes.overview_headline,
description: partnerData.attributes.overview_description
};

}
6 changes: 6 additions & 0 deletions app/en/partners/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { redirect } from 'next/navigation'

export default function Redirect({ }) {
// Click on 'Partner' link in breadcrumbs should redirect to home page
redirect('/en')
}
81 changes: 18 additions & 63 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,18 @@
import Index_header from "@/components/Index_Header"
import PartnerListing from "@/components/PartnerListing"
import HeroImage from "@/components/HeroImage"
import PartnerContactForm from "@/components/ContactForm"
import Breadcrumbs from "@/components/Breadcrumbs"
import TwoColumnsWithPicture from "@/components/TwoColumnsWithPicture"
import { getAllPartners, getAllTags, getAllWebAssets } from '@/lib/partners';
import Head from "next/head"


export default async function App() {
// representation of first page
const cachedPartnersData = await getAllPartners();
const cachedTagsData = await getAllTags();
const metadata = await generateMetadata();
const webAssets = await getAllWebAssets();

const mainHero = webAssets.find(asset => asset.attributes.name === 'main-hero-image')
const mainHeroHash = mainHero["attributes"]["media"]["data"]["attributes"]["hash"]
const mainHeroExt = mainHero["attributes"]["media"]["data"]["attributes"]["ext"]

const otcIcon = webAssets.find(asset => asset.attributes.name === 'otc-icon')
const otcIconHash = otcIcon["attributes"]["media"]["data"]["attributes"]["hash"]
const otcIconExt = otcIcon["attributes"]["media"]["data"]["attributes"]["ext"]

let heroMedia = {
backgroundImageUrl: `/api/${mainHeroHash}${mainHeroExt}`,
iconSrc: `/api/${otcIconHash}${otcIconExt}`,
iconAlt: otcIcon["attributes"]["name"]
}

const introMedia = webAssets.find(asset => asset.attributes.name === 'circle-partner-tp')
const introMediaHash = introMedia["attributes"]["media"]["data"]["attributes"]["hash"]
const introMediaExt = introMedia["attributes"]["media"]["data"]["attributes"]["ext"]

let intro = {
image: `${introMediaHash}${introMediaExt}`,
img_height: "517px",
headline: "Discover the powerful services of our partners",
text: ["Many start-ups and cloud service providers already work together with us an partners, using our technology and infrastructure for their cloud projects. This is a testament to their trust in the Open Telekom Cloud and our great partnership.", "You can start using these services today to improve your IT systems or your company's communications and benefit from the advantages of the GDPR-compliant European cloud."]
}

return (
<div>
<Head>
<title>{metadata.title}</title>
<meta name="description" content={metadata.description} />
</Head>
<HeroImage props={heroMedia}></HeroImage>
<Breadcrumbs></Breadcrumbs>
<TwoColumnsWithPicture props={intro}></TwoColumnsWithPicture>
<PartnerListing cachedPartners={cachedPartnersData} cachedTags={cachedTagsData}></PartnerListing>
<PartnerContactForm></PartnerContactForm>
</div>
)
}

export async function generateMetadata() {
return {
title: "Discover the powerful services of our partners",
description: "Many start-ups and cloud service providers already work together with us an partners, using our technology and infrastructure for their cloud projects. This is a testament to their trust in the Open Telekom Cloud and our great partnership. You can start using these services today to improve your IT systems or your company's communications and benefit from the advantages of the GDPR-compliant European cloud."
};
}
'use client';

import { redirect } from 'next/navigation'
import { useEffect } from 'react';

export default function Redirect({ }) {

// Redirection based on language
useEffect(() => {
const userLanguage = navigator.language;
if (userLanguage.startsWith('de')) {
redirect('/de')
} else {
redirect('/en')
}
}, [])
return null;
}
33 changes: 28 additions & 5 deletions components/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,51 @@ import styles from '/styles/Card.module.css';
import Image from 'next/image';
import Link from 'next/link'

function Card({props}) {
function Card({props, locale}) {
// representation of a partner inside of partner navigator
const [partner, setPartner] = useState(props)

let overviewMedia = partner.attributes.overview_media.data.attributes.hash
overviewMedia = overviewMedia.concat(partner.attributes.overview_media.data.attributes.ext)
let partnerTags = partner.attributes.tags.data

let overview_headline = ""
let overview_description = ""


if (locale === "en") {
overview_headline = partner.attributes.overview_headline
overview_description = partner.attributes.overview_description
} else {
partner.attributes.localizations.data.map(partner_localization => {
if (partner_localization.attributes.locale === locale) {
overview_headline = partner_localization.attributes.overview_headline
overview_description = partner_localization.attributes.overview_description
}
})
}

let href_link = ""
if (locale === "en") {
href_link = "/en"
} else if (locale === "de-DE") {
href_link = "/de"
}

return (
<div className={styles.card_container}>
<Link href={`/partners/${partner.attributes.partner_id}`}>
<Link href={`${href_link}/partners/${partner.attributes.partner_id}`}>
<div className={styles.card_body}>
<Image
src={`/api/${overviewMedia}`}
width={partner.attributes.overview_media.data.attributes.width}
height={partner.attributes.overview_media.data.attributes.height}
className={styles.image}
alt={partner.attributes.overview_headline}>
alt={overview_headline}>
</Image>
<div className={styles.content_container}>
<h3 className={styles.h3}>{partner.attributes.overview_headline}</h3>
<div className={styles.content}>{partner.attributes.overview_description}</div>
<h3 className={styles.h3}>{overview_headline}</h3>
<div className={styles.content}>{overview_description}</div>
{partnerTags.map(tag => {
return(
<div
Expand Down
Loading

0 comments on commit b3041c4

Please sign in to comment.