turash/bugulma/frontend/lib/class-component-utils.ts
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- Remove nested git repository from bugulma/frontend/.git
- Add all frontend files to main repository tracking
- Convert from separate frontend/backend repos to unified monorepo
- Preserve all frontend code and development history as tracked files
- Eliminate nested repository complexity for simpler development workflow

This creates a proper monorepo structure with frontend and backend
coexisting in the same repository for easier development and deployment.
2025-11-25 06:02:57 +01:00

39 lines
1.1 KiB
TypeScript

/**
* Utilities for class components
* Provides common functionality that class components need
*/
import { en } from '@/locales/en.ts';
/**
* Minimal translation helper for class components
* Since class components can't use hooks, this provides basic translation support
* using English as fallback when full i18n context isn't available
*/
export const classComponentT = (
key: string,
replacements?: { [key: string]: string | number }
): string => {
const path = key.split('.');
let result: unknown = en;
for (const p of path) {
if (result && typeof result === 'object' && p in result) {
result = (result as Record<string, unknown>)[p];
} else {
return key; // Return key if path not found
}
}
if (typeof result === 'string' && replacements) {
let translated = result;
Object.keys(replacements).forEach((placeholder) => {
const regex = new RegExp(`{{${placeholder}}}`, 'g');
translated = translated.replace(regex, String(replacements[placeholder]));
});
return translated;
}
return typeof result === 'string' ? result : key;
};