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

feat(i18n): display banner for outdated translations #22

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions public/locales/dk/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": 0,
"root.description": "Et alternativ til Nix økosystemet",

"header.community": "Community",
Expand Down
4 changes: 4 additions & 0 deletions public/locales/en/translations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"version": 0,
"i18n-outdated.title": "Outdated Translation",
"i18n-outdated.description": "This translation has not been updated to the latest version yet.",

"root.description": "An alternative to the Nix ecosystem",

"header.community": "Community",
Expand Down
14 changes: 14 additions & 0 deletions src/components/home/Home.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ import Hero from "./Hero.astro";
import Values from "./Values.astro";
import Goals from "./Goals.astro";
import Roadmap from "./Roadmap.astro";
import I18nOutdated from "../i18n/Outdated.astro";

import type { Params } from "../../i18n/utils";

const { lang } = Astro.params as Params;
import { isOutdated as i18nIsOutdated } from "../../i18n/utils";
---

<main class="grid place-items-center">
<Hero />

{
i18nIsOutdated(lang) && (
<div class="prose prose-invert py-16 px-4 max-w-4xl">
<I18nOutdated />
</div>
)
}
Copy link
Member

@hedyhli hedyhli May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about displaying this as a banner before the Hero instead? The hero does not take up the full width, but the header does. Currently, the warning looks to be a part of the content itself, which isn't.

Suggested change
<Hero />
{
i18nIsOutdated(lang) && (
<div class="prose prose-invert py-16 px-4 max-w-4xl">
<I18nOutdated />
</div>
)
}
{i18nIsOutdated(lang) && <I18nOutdated />}
<Hero />

See suggestion in the i18n component...


So putting it all together:
image


Keeping it in the same place as before:
image

	<Hero />
	{
		i18nIsOutdated(lang) && (
			<div class="pt-16 px-4 w-full max-w-4xl">
				<I18nOutdated />
			</div>
		)
	}

	<div class="prose prose-invert pb-16 px-4 max-w-4xl">
		<Values />
		<Goals />
		<Roadmap />
	</div>

Component:

	class="bg-yellow-800 bg-opacity-50 border-l-4 border-orange-500 text-orange-100 p-4"

A possible design that puts it at the very top, marking the entire page as "possibly outdated":
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to choose your initial suggestion of placing it above the hero. Somehow it attracts my attention much less when at the top. But also, it's much better above the hero than below it.


<div class="prose prose-invert py-16 px-4 max-w-4xl">
<Values />
<Goals />
Expand Down
14 changes: 14 additions & 0 deletions src/components/i18n/Outdated.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
import { useTranslations } from "../../i18n/utils";
import type { Params } from "../../i18n/utils";

const { lang } = Astro.params as Params;
const translation = useTranslations(lang);
---

<section id="i18n-outdated">
<h2>{translation("i18n-outdated.title")}</h2>
<p class="description">
{translation("i18n-outdated.description")}
</p>
</section>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this might look better to serve as a warning, apart from the content on the website itself:

Suggested change
<section id="i18n-outdated">
<h2>{translation("i18n-outdated.title")}</h2>
<p class="description">
{translation("i18n-outdated.description")}
</p>
</section>
<div
class="w-full max-w-4xl bg-yellow-800 bg-opacity-50 border-l-4 border-orange-500 text-orange-100 p-4"
role="alert"
>
<p class="font-bold">{translation("i18n-outdated.title")}</p>
<p>{translation("i18n-outdated.description")}</p>
</div>

Not quite sure about the use of id="i18n-outdated" currently, but feel free to adapt 😄

Copy link
Author

@liketechnik liketechnik May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stands out much better this way, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely much better now!

I noticed you still made the entire banner "prose-like". It'd be great to hear what other reviewers think, but I have two suggestions:

  1. I'd recommend against the use of headers in banners, because it competes visually with the hero and header. Although the banner should be attention seeking enough to warn users about the outdated nature of the page, it shouldn't steal attention to become one of the "main titles/headings" of the page. It's a little large right now and breaks the visual hierarchy of the page.

    For reference, my suggestion was sourced from: https://v1.tailwindcss.com/components/alerts#left-accent-border

  2. Note that we don't necessarily need prose here -- it's mostly for content-like elements, or ones from the output of say a markdown processor. This is entirely up to you, but for a non-content component like this, elements without prose would work just fine -- extra classes means an extra selectors (and hence possibly redundant properties) applied :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you still made the entire banner "prose-like". It'd be great to hear what other reviewers think, but I have two suggestions

I fully agree. Sorry, I was too invested in the original styling of the element, that I didn't realize that you didn't merely move the styling out of Home.astro (I'm working on getting better to thoroughly evaluate alternatives when I'm already invested in a solution - but sometimes I don't; that shouldn't happen, and I try to do better).

Both your suggestions are solid, let me adjust this too...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no worries!

8 changes: 8 additions & 0 deletions src/i18n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export function useTranslations(lang: keyof typeof ui) {
};
}

export function isOutdated(lang: keyof typeof ui) {
if ("version" in ui[lang]) {
return ui[lang]["version"] < ui[defaultLang]["version"];
} else {
return true;
}
}

export const getStaticPaths = (async () => {
return Object.keys(languages).map((name) => ({
params: { lang: name as keyof typeof languages },
Expand Down
Loading