feat: lang
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import { enUS, fr } from 'date-fns/locale';
|
||||
|
||||
|
||||
export function relativeTime(date: Date): string {
|
||||
return formatDistanceToNow(date, {addSuffix: true, includeSeconds: false});
|
||||
export function relativeTime(date: Date, locale: string): string {
|
||||
return formatDistanceToNow(date, {addSuffix: true, includeSeconds: false, locale: locale === 'fr' ? fr : enUS});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { getCookie, setCookie } from "./cookies";
|
||||
|
||||
export function getLang() {
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
const paramsLang = params.get("lang");
|
||||
if (paramsLang !== null) {
|
||||
setCookie("lang", paramsLang);
|
||||
return paramsLang;
|
||||
}
|
||||
return getCookie("lang", "en");
|
||||
}
|
||||
Reference in New Issue
Block a user