import i18n, { DEFAULT_LOCALE } from '@/lang'

export function translateMenuTitle(title, locale) {
  if (!title) return title

  const normalizedTitle = String(title).trim()
  const currentLocale = locale || i18n.locale
  const messages = i18n.getLocaleMessage(currentLocale) || {}
  const defaultMessages = i18n.getLocaleMessage(DEFAULT_LOCALE) || {}
  const menuMessages = messages.menu || {}
  const defaultMenuMessages = defaultMessages.menu || {}

  return menuMessages[normalizedTitle] || defaultMenuMessages[normalizedTitle] || title
}
