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 3 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
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
8 changes: 8 additions & 0 deletions src/components/home/Home.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ 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">
{i18nIsOutdated(lang) && <I18nOutdated />}

<Hero />

<div class="prose prose-invert py-16 px-4 max-w-4xl">
Expand Down
18 changes: 18 additions & 0 deletions src/components/i18n/Outdated.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
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"
class="prose prose-invert w-full max-w-4xl bg-yellow-800 bg-opacity-50 border-l-4 border-orange-500 text-orange-100 p-4"
role="alert"
>
<h2>{translation("i18n-outdated.title")}</h2>
<p class="description">
{translation("i18n-outdated.description")}
</p>
</section>
11 changes: 11 additions & 0 deletions src/i18n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export function useTranslations(lang: keyof typeof ui) {
};
}

export function isOutdated(lang: keyof typeof ui) {
if ("version" in ui[lang]) {
return (
(ui[lang] as (typeof ui)[typeof lang])["version"] <
ui[defaultLang]["version"]
);
} else {
return true;
}
Comment on lines +15 to +22
Copy link
Contributor

Choose a reason for hiding this comment

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

All translations should contain the same keys....

Suggested change
if ("version" in ui[lang]) {
return (
(ui[lang] as (typeof ui)[typeof lang])["version"] <
ui[defaultLang]["version"]
);
} else {
return true;
}
return (
(ui[lang] as (typeof ui)[typeof lang])["version"] <
ui[defaultLang]["version"]
);

Copy link
Author

Choose a reason for hiding this comment

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

This confuses me - while I can see where you are coming from, the current useTranslations function contains an ui[lang] || ui[defaultLang] statement, which would be redundant if all translations contain the same keys.

}

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