Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Localizing Electron Menus with i18next—Why I Built electron-menu-i18next

Описание и применение

Пакет @solisware/electron-menu-i18next автоматически локализует элементы меню Electron, используя i18next, сохраняя при этом нативное поведение ролей.

Задача

Electron’s role-based native menu items don’t integrate directly with an i18next instance running in the main process, making it hard to provide translated labels while preserving native behavior.

Результат

The package eliminates repetitive code for translating Electron menu roles, provides English fallbacks, respects explicit labels, and handles platform differences, enabling developers to localize menus with minimal effort.

Рабочий процесс

  • Define an Electron menu template using role properties only.
  • Pass the template and the i18next translation function to localizeMenuTemplate().
  • The package recursively replaces role-based items with translated labels, using built-in English fallbacks and respecting explicit labels.
  • Electron builds the native menu from the localized template.
  • When the application language changes, rebuild the menu at the application level using the same process.
  • The menu now displays translated labels while maintaining native role behavior.

Доказательства

Electron’s role-based native menu items don’t integrate directly with an i18next instance running in the main process

Источник

The idea is deliberately simple. Give it an Electron menu template and your existing i18next translation function, and it localizes role-based menu items before Electron builds the native menu.

Источник

One was handling fallback. I didn't think somebody should need a perfectly complete translation file before using the package, so it includes built-in English labels for Electron roles.

Источник

  • Дата записи: 2026-10-03T23:41:21.531Z