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

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

说明与用途

@solisware/electron-menu-i18next 包使用 i18next 自动本地化 Electron 角色式菜单项,同时保持原生行为,减少重复代码。

问题

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