|
- "use client";
-
- import { useTranslation } from "react-i18next";
- import type { TFunction } from "i18next";
- import type { ReportDefinition, ReportField } from "@/config/reportConfig";
-
- export function useReportLabels() {
- const { t } = useTranslation("report");
-
- const reportTitle = (report: Pick<ReportDefinition, "id" | "title">) =>
- t(`reports.${report.id}.title`, { defaultValue: report.title });
-
- const fieldLabel = (
- reportId: string,
- field: Pick<ReportField, "name" | "label">,
- ) =>
- t(`reports.${reportId}.fields.${field.name}`, {
- defaultValue: field.label,
- });
-
- const optionLabel = (
- reportId: string,
- fieldName: string,
- opt: { label: string; value: string },
- ) =>
- t(
- [
- `reports.${reportId}.options.${fieldName}.${opt.value}`,
- `options.${opt.value}`,
- ],
- { defaultValue: opt.label },
- );
-
- const categoryTitle = (id: string, fallback: string) =>
- t(`categories.${id}`, { defaultValue: fallback });
-
- return { t, reportTitle, fieldLabel, optionLabel, categoryTitle };
- }
-
- export function reportExcelT(
- t: TFunction | undefined,
- key: string,
- fallback: string,
- ): string {
- if (!t) return fallback;
- return String(t(key, { defaultValue: fallback }));
- }
|