feat(i18n): display banner for outdated translations

'Outdated' is recognized by having an explicit
version field in each translation file.
This commit is contained in:
Florian Warzecha 2024-05-11 20:28:08 +02:00
parent e43d8bd2d6
commit fa47a923ed
Signed by: liketechnik
GPG key ID: 4BE8C7D97F910C60
5 changed files with 41 additions and 0 deletions

View file

@ -1,4 +1,5 @@
{
"version": 0,
"root.description": "Et alternativ til Nix økosystemet",
"header.community": "Community",

View file

@ -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",

View file

@ -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>
)
}
<div class="prose prose-invert py-16 px-4 max-w-4xl">
<Values />
<Goals />

View file

@ -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>

View file

@ -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 },