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

Enables i18ned footer links #1119

Merged
merged 3 commits into from
Feb 26, 2024
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
17 changes: 14 additions & 3 deletions backend/src/config/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "https://example.com" },
/// { label = { en = "Example 1" }, link = "https://example.com" },
/// { label = { en = "Example 2" }, link = { en = "https://example.com/en" } },
/// "about",
/// ]
/// ```
Expand Down Expand Up @@ -122,6 +125,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 {
Expand All @@ -131,7 +142,7 @@ pub(crate) enum FooterLink {
GraphiQL,
Custom {
label: TranslatedString,
link: String,
link: StringOrTranslatedString,
}
}

Expand Down
7 changes: 5 additions & 2 deletions docs/docs/setup/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "https://example.com" },
# { label = { en = "Example 1" }, link = "https://example.com" },
# { label = { en = "Example 2" }, link = { en = "https://example.com/en" } },
# "about",
# ]
# ```
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Config = {

type FooterLink = "about" | "graphiql" | {
label: TranslatedString;
link: string;
link: TranslatedString | string;
};

type InitialConsent = {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export const Footer: React.FC = () => {
</li>;
} else {
return <li key={i}>
<Link to={entry.link}>{translatedConfig(entry.label, i18n)}</Link>
<Link to={
typeof entry.link === "string"
? entry.link
: translatedConfig(entry.link, i18n)
}>
{translatedConfig(entry.label, i18n)}
</Link>
</li>;
}
})}
Expand Down
Loading