From fa47a923edd9c9bbf27c4b47bc124371612fa7ae Mon Sep 17 00:00:00 2001 From: Florian Warzecha Date: Sat, 11 May 2024 20:28:08 +0200 Subject: [PATCH 1/4] feat(i18n): display banner for outdated translations 'Outdated' is recognized by having an explicit version field in each translation file. --- public/locales/dk/translations.json | 1 + public/locales/en/translations.json | 4 ++++ src/components/home/Home.astro | 14 ++++++++++++++ src/components/i18n/Outdated.astro | 14 ++++++++++++++ src/i18n/utils.ts | 8 ++++++++ 5 files changed, 41 insertions(+) create mode 100644 src/components/i18n/Outdated.astro diff --git a/public/locales/dk/translations.json b/public/locales/dk/translations.json index a70a249..a462364 100644 --- a/public/locales/dk/translations.json +++ b/public/locales/dk/translations.json @@ -1,4 +1,5 @@ { + "version": 0, "root.description": "Et alternativ til Nix økosystemet", "header.community": "Community", diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 5ef1825..de8c8f1 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -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", diff --git a/src/components/home/Home.astro b/src/components/home/Home.astro index 6d68b0c..5b4e901 100644 --- a/src/components/home/Home.astro +++ b/src/components/home/Home.astro @@ -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"; ---
+ { + i18nIsOutdated(lang) && ( +
+ +
+ ) + } +
diff --git a/src/components/i18n/Outdated.astro b/src/components/i18n/Outdated.astro new file mode 100644 index 0000000..61936da --- /dev/null +++ b/src/components/i18n/Outdated.astro @@ -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); +--- + +
+

{translation("i18n-outdated.title")}

+

+ {translation("i18n-outdated.description")} +

+
diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index d10e23e..1eb25a7 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -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 }, From 2a3b84d38f60280144bdbcbc31101cd4d8867b74 Mon Sep 17 00:00:00 2001 From: Florian Warzecha Date: Mon, 13 May 2024 22:54:38 +0200 Subject: [PATCH 2/4] fix(i18n/utils): typechecking errors Co-authored-by: ~hedy --- src/i18n/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index 1eb25a7..a2cfbc5 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -13,7 +13,10 @@ 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"]; + return ( + (ui[lang] as (typeof ui)[typeof lang])["version"] < + ui[defaultLang]["version"] + ); } else { return true; } From 0f193b08e5dfe429eab89c7090d85ef1a91c14a8 Mon Sep 17 00:00:00 2001 From: Florian Warzecha Date: Mon, 13 May 2024 23:13:58 +0200 Subject: [PATCH 3/4] fix(i18n): make outdated banner stand out Co-authored-by: ~hedy --- src/components/home/Home.astro | 10 ++-------- src/components/i18n/Outdated.astro | 6 +++++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/home/Home.astro b/src/components/home/Home.astro index 5b4e901..cec26f7 100644 --- a/src/components/home/Home.astro +++ b/src/components/home/Home.astro @@ -12,15 +12,9 @@ import { isOutdated as i18nIsOutdated } from "../../i18n/utils"; ---
- + {i18nIsOutdated(lang) && } - { - i18nIsOutdated(lang) && ( -
- -
- ) - } +
diff --git a/src/components/i18n/Outdated.astro b/src/components/i18n/Outdated.astro index 61936da..11e5a80 100644 --- a/src/components/i18n/Outdated.astro +++ b/src/components/i18n/Outdated.astro @@ -6,7 +6,11 @@ const { lang } = Astro.params as Params; const translation = useTranslations(lang); --- -
+