Files
ArchiTools/src/core/i18n/i18n-provider.tsx
T
Marius Tarau 4c46e8bcdd Initial commit: ArchiTools modular dashboard platform
Complete Next.js 16 application with 13 fully implemented modules:
Email Signature, Word XML Generator, Registratura, Dashboard,
Tag Manager, IT Inventory, Address Book, Password Vault,
Mini Utilities, Prompt Generator, Digital Signatures,
Word Templates, and AI Chat.

Includes core platform systems (module registry, feature flags,
storage abstraction, i18n, theming, auth stub, tagging),
16 technical documentation files, Docker deployment config,
and legacy HTML tool reference.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 12:50:25 +02:00

48 lines
1.1 KiB
TypeScript

'use client';
import { createContext, useContext, useCallback } from 'react';
import { ro } from './locales/ro';
import type { Labels } from './types';
interface I18nContextValue {
labels: Labels;
t: (key: string) => string;
}
const I18nContext = createContext<I18nContextValue | null>(null);
interface I18nProviderProps {
children: React.ReactNode;
}
export function I18nProvider({ children }: I18nProviderProps) {
const labels = ro;
const t = useCallback(
(key: string): string => {
const [namespace, ...rest] = key.split('.');
const labelKey = rest.join('.');
if (!namespace || !labelKey) return key;
return labels[namespace]?.[labelKey] ?? key;
},
[labels]
);
return (
<I18nContext.Provider value={{ labels, t }}>
{children}
</I18nContext.Provider>
);
}
export function useI18n(): I18nContextValue {
const ctx = useContext(I18nContext);
if (!ctx) throw new Error('useI18n must be used within I18nProvider');
return ctx;
}
export function useLabel(key: string): string {
const { t } = useI18n();
return t(key);
}