feat: add some stuff

This commit is contained in:
2024-03-28 18:30:52 +01:00
parent 31b24de86c
commit d4128840b9
196 changed files with 3393 additions and 390 deletions

View File

@ -1,13 +1,18 @@
import { defaultLocale } from 'astro-i18n-aut';
import { defaultLocale, getLocale } from 'astro-i18n-aut';
import { ui, defaultLang, showDefaultLang } from './ui';
import type { AstroGlobal } from 'astro';
export function useTranslatedPath(lang: string) {
return function translatePath(path: string, l: string = lang) {
export function useTranslatedPath(astro: AstroGlobal) {
const locale = getLocale(astro.url);
return function translatePath(path: string, l: string = locale) {
return !showDefaultLang && l === defaultLang ? path : `/${l}${path}`.replace(/\/$/g, '');
}
}
export function useTranslations(lang: string) {
export function useTranslations(astro: AstroGlobal) {
const lang = getLocale(astro.url);
return function t(key: keyof typeof ui[typeof defaultLang]) {
return ui[lang as keyof typeof ui][key] || ui[defaultLang][key];
}
@ -20,7 +25,7 @@ export function parseSlug(id: string) {
return [splitPath.join("/"), lang]
}
export function filterCollection<T extends { id: string }>(collection: T[], locale: string) {
export function filterCollection<T extends { id: string }>(collection: T[], locale: string): T[] {
return collection.filter(post => {
const [_, lang] = parseSlug(post?.id);
return lang === locale;