Files
edr-platform/apps/edr-freight-web/backoffice/src/shared/common/localizedName.ts
natib21 e6e44e773b fix ui
2026-07-10 11:25:59 +00:00

22 lines
603 B
TypeScript

import { useCallback } from "react";
import { useTranslation } from "react-i18next";
export type LocalizedText = {
am?: string;
en?: string;
};
export const useLocalizedName = (language?: string) => {
const { i18n } = useTranslation();
const currentLanguage = language || i18n.language;
return useCallback(
(name?: LocalizedText): string => {
if (!name) return "";
const am = name.am?.trim() ?? "";
const en = name.en?.trim() ?? "";
return (currentLanguage.startsWith("am") ? am || en : en || am) || "";
},
[currentLanguage],
);
};