FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

48 строки
1.2 KiB

  1. "use client";
  2. import { useTranslation } from "react-i18next";
  3. import type { TFunction } from "i18next";
  4. import type { ReportDefinition, ReportField } from "@/config/reportConfig";
  5. export function useReportLabels() {
  6. const { t } = useTranslation("report");
  7. const reportTitle = (report: Pick<ReportDefinition, "id" | "title">) =>
  8. t(`reports.${report.id}.title`, { defaultValue: report.title });
  9. const fieldLabel = (
  10. reportId: string,
  11. field: Pick<ReportField, "name" | "label">,
  12. ) =>
  13. t(`reports.${reportId}.fields.${field.name}`, {
  14. defaultValue: field.label,
  15. });
  16. const optionLabel = (
  17. reportId: string,
  18. fieldName: string,
  19. opt: { label: string; value: string },
  20. ) =>
  21. t(
  22. [
  23. `reports.${reportId}.options.${fieldName}.${opt.value}`,
  24. `options.${opt.value}`,
  25. ],
  26. { defaultValue: opt.label },
  27. );
  28. const categoryTitle = (id: string, fallback: string) =>
  29. t(`categories.${id}`, { defaultValue: fallback });
  30. return { t, reportTitle, fieldLabel, optionLabel, categoryTitle };
  31. }
  32. export function reportExcelT(
  33. t: TFunction | undefined,
  34. key: string,
  35. fallback: string,
  36. ): string {
  37. if (!t) return fallback;
  38. return String(t(key, { defaultValue: fallback }));
  39. }