From 357181798629ec4b6d5a492130282d0a047ed2ce Mon Sep 17 00:00:00 2001 From: Gregor Eichelberger Date: Thu, 22 Feb 2024 14:14:25 +0100 Subject: [PATCH 1/3] Enables i18ned footer links This changes the footer custom link type from `string` to `TranslatedString`, enabling links to resources, especially documents like PDFs, in different languages with just one link. --- backend/src/config/general.rs | 4 ++-- docs/docs/setup/config.toml | 2 +- frontend/src/config.ts | 2 +- frontend/src/layout/Footer.tsx | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/config/general.rs b/backend/src/config/general.rs index 5114c41d8..7fd6dac50 100644 --- a/backend/src/config/general.rs +++ b/backend/src/config/general.rs @@ -53,7 +53,7 @@ pub(crate) struct GeneralConfig { /// /// ``` /// footer_links = [ - /// { label = { en = "Example" }, link = "https://example.com" }, + /// { label = { en = "Example" }, link = { en = "https://example.com/en" } }, /// "about", /// ] /// ``` @@ -131,7 +131,7 @@ pub(crate) enum FooterLink { GraphiQL, Custom { label: TranslatedString, - link: String, + link: TranslatedString, } } diff --git a/docs/docs/setup/config.toml b/docs/docs/setup/config.toml index c2629ddec..75aae8f61 100644 --- a/docs/docs/setup/config.toml +++ b/docs/docs/setup/config.toml @@ -66,7 +66,7 @@ # # ``` # footer_links = [ -# { label = { en = "Example" }, link = "https://example.com" }, +# { label = { en = "Example" }, link = { en = "https://example.com/en/" } }, # "about", # ] # ``` diff --git a/frontend/src/config.ts b/frontend/src/config.ts index e698ed12b..edbb5e893 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -38,7 +38,7 @@ type Config = { type FooterLink = "about" | "graphiql" | { label: TranslatedString; - link: string; + link: TranslatedString; }; type InitialConsent = { diff --git a/frontend/src/layout/Footer.tsx b/frontend/src/layout/Footer.tsx index a4e364a5f..efdb2881b 100644 --- a/frontend/src/layout/Footer.tsx +++ b/frontend/src/layout/Footer.tsx @@ -44,7 +44,9 @@ export const Footer: React.FC = () => { ; } else { return
  • - {translatedConfig(entry.label, i18n)} + + {translatedConfig(entry.label, i18n)} +
  • ; } })} From 2a1bc4f7e3f2bf7a9bab4cada0e456b6b00251c5 Mon Sep 17 00:00:00 2001 From: Gregor Eichelberger Date: Fri, 23 Feb 2024 16:41:28 +0100 Subject: [PATCH 2/3] Allow optionally translated links Make the translated links optional, as breaking changes in the config is annoying. --- backend/src/config/general.rs | 10 +++++++++- docs/docs/setup/config.toml | 2 +- frontend/src/config.ts | 2 +- frontend/src/layout/Footer.tsx | 6 +++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/src/config/general.rs b/backend/src/config/general.rs index 7fd6dac50..b14c066b9 100644 --- a/backend/src/config/general.rs +++ b/backend/src/config/general.rs @@ -122,6 +122,14 @@ impl GeneralConfig { } } +#[derive(Debug, serde::Deserialize, serde::Serialize)] +#[serde(untagged)] +pub(crate) enum StringOrTranslatedString { + Simple(String), + Translated(TranslatedString), +} + + #[derive(Debug, serde::Deserialize, serde::Serialize)] #[serde(untagged)] pub(crate) enum FooterLink { @@ -131,7 +139,7 @@ pub(crate) enum FooterLink { GraphiQL, Custom { label: TranslatedString, - link: TranslatedString, + link: StringOrTranslatedString, } } diff --git a/docs/docs/setup/config.toml b/docs/docs/setup/config.toml index 75aae8f61..ca07079c9 100644 --- a/docs/docs/setup/config.toml +++ b/docs/docs/setup/config.toml @@ -66,7 +66,7 @@ # # ``` # footer_links = [ -# { label = { en = "Example" }, link = { en = "https://example.com/en/" } }, +# { label = { en = "Example" }, link = { en = "https://example.com/en" } }, # "about", # ] # ``` diff --git a/frontend/src/config.ts b/frontend/src/config.ts index edbb5e893..15c2a62e6 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -38,7 +38,7 @@ type Config = { type FooterLink = "about" | "graphiql" | { label: TranslatedString; - link: TranslatedString; + link: TranslatedString | string; }; type InitialConsent = { diff --git a/frontend/src/layout/Footer.tsx b/frontend/src/layout/Footer.tsx index efdb2881b..07eb9a19b 100644 --- a/frontend/src/layout/Footer.tsx +++ b/frontend/src/layout/Footer.tsx @@ -44,7 +44,11 @@ export const Footer: React.FC = () => { ; } else { return
  • - + {translatedConfig(entry.label, i18n)}
  • ; From db2ff9cfae3fe4f236bd2cbb53d498584fda2f89 Mon Sep 17 00:00:00 2001 From: Gregor Eichelberger Date: Mon, 26 Feb 2024 11:39:51 +0100 Subject: [PATCH 3/3] Add documentation Extend the footer_inks example to showcase both ways of declaring custom links and extending the description. --- backend/src/config/general.rs | 7 +++++-- docs/docs/setup/config.toml | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/config/general.rs b/backend/src/config/general.rs index b14c066b9..0c59038c9 100644 --- a/backend/src/config/general.rs +++ b/backend/src/config/general.rs @@ -49,11 +49,14 @@ pub(crate) struct GeneralConfig { /// By overwriting this default value, you can remove the default links and /// add custom ones. Note that these two default links are special and can /// be specified with only the shown string. To add custom ones, you need - /// to define a label and a link. Example: + /// to define a label and a link. The link is either the same for every language + /// or can be specified for each language in the same manner as the label. + /// Example: /// /// ``` /// footer_links = [ - /// { label = { en = "Example" }, link = { en = "https://example.com/en" } }, + /// { label = { en = "Example 1" }, link = "https://example.com" }, + /// { label = { en = "Example 2" }, link = { en = "https://example.com/en" } }, /// "about", /// ] /// ``` diff --git a/docs/docs/setup/config.toml b/docs/docs/setup/config.toml index ca07079c9..24d7928cc 100644 --- a/docs/docs/setup/config.toml +++ b/docs/docs/setup/config.toml @@ -62,11 +62,14 @@ # By overwriting this default value, you can remove the default links and # add custom ones. Note that these two default links are special and can # be specified with only the shown string. To add custom ones, you need -# to define a label and a link. Example: +# to define a label and a link. The link is either the same for every language +# or can be specified for each language in the same manner as the label. +# Example: # # ``` # footer_links = [ -# { label = { en = "Example" }, link = { en = "https://example.com/en" } }, +# { label = { en = "Example 1" }, link = "https://example.com" }, +# { label = { en = "Example 2" }, link = { en = "https://example.com/en" } }, # "about", # ] # ```