* Upgraded to Next.js 16 * Refactored code to comply with React 19.2 ESLint rules * Refactored some useEffect usages with the new useEffectEvent * Added Identities page and added second step to set up an identity after accepting an invitation * Updated all dependencies * Introduced PNPM catalogs for some frequently updated dependencies * Bugs fixing and improvements
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { readFileSync, readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
export type TranslationData = {
|
|
[key: string]: string | TranslationData;
|
|
};
|
|
|
|
export type Translations = {
|
|
[locale: string]: {
|
|
[namespace: string]: TranslationData;
|
|
};
|
|
};
|
|
|
|
export async function loadTranslations() {
|
|
const localesPath = join(process.cwd(), '../web/public/locales');
|
|
const localesDirents = readdirSync(localesPath, { withFileTypes: true });
|
|
|
|
const locales = localesDirents
|
|
.filter((dirent) => dirent.isDirectory())
|
|
.map((dirent) => dirent.name);
|
|
|
|
const translations: Translations = {};
|
|
|
|
for (const locale of locales) {
|
|
translations[locale] = {};
|
|
|
|
const namespaces = readdirSync(join(localesPath, locale)).filter((file) =>
|
|
file.endsWith('.json'),
|
|
);
|
|
|
|
for (const namespace of namespaces) {
|
|
const namespaceName = namespace.replace('.json', '');
|
|
|
|
try {
|
|
const filePath = join(localesPath, locale, namespace);
|
|
const content = readFileSync(filePath, 'utf8');
|
|
|
|
translations[locale][namespaceName] = JSON.parse(content);
|
|
} catch (error) {
|
|
console.warn(
|
|
`Warning: Translation file not found for locale "${locale}" and namespace "${namespaceName}"`,
|
|
);
|
|
|
|
translations[locale][namespaceName] = {};
|
|
}
|
|
}
|
|
}
|
|
|
|
return translations;
|
|
}
|