Skip to content

Commit ebec513

Browse files
committed
feat(i18n): display banner for outdated translations
'Outdated' is recognized by having an explicit version field in each translation file.
1 parent e43d8bd commit ebec513

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

public/locales/dk/translations.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"version": 0,
23
"root.description": "Et alternativ til Nix økosystemet",
34

45
"header.community": "Community",

public/locales/en/translations.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"version": 0,
3+
"i18n-outdated.title": "Outdated Translation",
4+
"i18n-outdated.description": "This translation has not been updated to the latest version yet.",
5+
26
"root.description": "An alternative to the Nix ecosystem",
37

48
"header.community": "Community",

src/components/home/Home.astro

+10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ import Hero from "./Hero.astro";
33
import Values from "./Values.astro";
44
import Goals from "./Goals.astro";
55
import Roadmap from "./Roadmap.astro";
6+
import I18nOutdated from "../i18n/Outdated.astro";
7+
8+
const { lang } = Astro.params as Params;
9+
import { isOutdated as i18nIsOutdated } from "../../i18n/utils";
610
---
711

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

15+
{ i18nIsOutdated(lang) &&
16+
<div class="prose prose-invert py-16 px-4 max-w-4xl">
17+
<I18nOutdated />
18+
</div>
19+
}
20+
1121
<div class="prose prose-invert py-16 px-4 max-w-4xl">
1222
<Values />
1323
<Goals />

src/components/i18n/Outdated.astro

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
import { useTranslations } from "../../i18n/utils";
3+
import type { Params } from "../../i18n/utils";
4+
5+
const { lang } = Astro.params as Params;
6+
const translation = useTranslations(lang);
7+
---
8+
9+
<section id="i18n-outdated">
10+
<h2>{translation("i18n-outdated.title")}</h2>
11+
<p class="description">
12+
{translation("i18n-outdated.description")}
13+
</p>
14+
</section>

src/i18n/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export function useTranslations(lang: keyof typeof ui) {
1111
};
1212
}
1313

14+
export function isOutdated(lang: keyof typeof ui) {
15+
if ("version" in ui[lang]) {
16+
return ui[lang]["version"] < ui[defaultLang]["version"];
17+
} else {
18+
return true;
19+
}
20+
}
21+
1422
export const getStaticPaths = (async () => {
1523
return Object.keys(languages).map((name) => ({
1624
params: { lang: name as keyof typeof languages },

0 commit comments

Comments
 (0)