export const txTagSafeTranslation = ({
  data,
  langs,
}: {
  data: Record<string, any>;
  langs: string[];
}) => {
  const tempObj = { ...data };
  const convertIfNeeded = (targetObj: any) => {
    Object.keys(targetObj).forEach((key) => {
      let newKey: string | undefined;
      if (key.includes('.')) {
        newKey = key.replace(/\./g, '_');
        targetObj[newKey] = targetObj[key];
        delete targetObj[key];
      }
      const targetKey = newKey || key;
      if (
        typeof targetObj[targetKey] === 'object' &&
        targetObj[targetKey] !== null
      ) {
        targetObj[targetKey] = convertIfNeeded(targetObj[targetKey]);
      }
    });
    return targetObj;
  };
  langs.forEach((lang) => {
    tempObj[lang] = convertIfNeeded({ ...data[lang] });
  });
  return tempObj;
};
