-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils.ts
32 lines (28 loc) · 862 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ui, defaultLang, languages } from "./ui";
import type {
InferGetStaticParamsType,
InferGetStaticPropsType,
GetStaticPaths,
} from "astro";
export function useTranslations(lang: keyof typeof ui) {
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
return ui[lang][key] || ui[defaultLang][key];
};
}
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;
}
}
export const getStaticPaths = (async () => {
return Object.keys(languages).map((name) => ({
params: { lang: name as keyof typeof languages },
}));
}) satisfies GetStaticPaths;
export type Params = InferGetStaticParamsType<typeof getStaticPaths>;
export type Props = InferGetStaticPropsType<typeof getStaticPaths>;