mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-28 12:37:25 +00:00
feat: add collection
This commit is contained in:
24
frontend/src/utils/debounce.ts
Normal file
24
frontend/src/utils/debounce.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export class Debounce {
|
||||
private timer: number | null = null;
|
||||
private readonly delay: number;
|
||||
|
||||
constructor(delay: number) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
run(callback: () => void) {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
this.timer = setTimeout(() => {
|
||||
callback();
|
||||
}, this.delay);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
}
|
||||
}
|
19
frontend/src/utils/i18n.ts
Normal file
19
frontend/src/utils/i18n.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
function t(data: any, language: string) {
|
||||
return (key: string) => {
|
||||
return data[language]?.["translation"]?.[key] || key;
|
||||
};
|
||||
}
|
||||
|
||||
export const i18nContext = createContext<any>({});
|
||||
|
||||
export function useTranslation() {
|
||||
const data = useContext(i18nContext);
|
||||
const userLang = navigator.language;
|
||||
console.log("Using language:", userLang);
|
||||
|
||||
return {
|
||||
t: t(data, userLang),
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user