mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import type {
|
|
ApplicationStatus,
|
|
DocumentStatus,
|
|
LicenseStatus,
|
|
LicenseType,
|
|
RequestType,
|
|
} from '../types/license.types';
|
|
|
|
/**
|
|
* Resolves domain enum values to localized labels and formats dates in the
|
|
* active language. Keeps component markup free of `t(\`enum.${v}\`)` noise.
|
|
*/
|
|
export function useLicenseLabels() {
|
|
const { t, i18n } = useTranslation();
|
|
const locale = i18n.language === 'am' ? 'am-ET' : 'en-GB';
|
|
|
|
const formatDate = (iso: string) =>
|
|
new Date(iso).toLocaleDateString(locale, {
|
|
year: 'numeric',
|
|
month: 'short',
|
|
day: 'numeric',
|
|
});
|
|
|
|
return {
|
|
licenseType: (v: LicenseType) => t(`licenseType.${v}`),
|
|
subjectLabel: (v: LicenseType) => t(`subjectLabel.${v}`),
|
|
requestType: (v: RequestType) => t(`requestType.${v}`),
|
|
applicationStatus: (v: ApplicationStatus) => t(`applicationStatus.${v}`),
|
|
licenseStatus: (v: LicenseStatus) => t(`licenseStatus.${v}`),
|
|
documentStatus: (v: DocumentStatus) => t(`documentStatus.${v}`),
|
|
doc: (name: string) => t(`documents.${name}`, { defaultValue: name }),
|
|
formatDate,
|
|
};
|
|
}
|