Repository: electron/electron
File: shell/browser/ui/cocoa/electron_menu_controller.mm (Objective-C++)

Code before:
                        withItems:(NSArray*)items {
  NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:service.menuItemTitle
                                                action:@selector(performShare:)
                                         keyEquivalent:@""];
  [item setTarget:self];
  [item setImage:service.image];
  [item setRepresentedObject:@{@"service" : service, @"items" : items}];
  return item;
}

- (NSMenuItem*)makeMenuItemForIndex:(NSInteger)index
                          fromModel:(electron::ElectronMenuModel*)model {
  std::u16string label16 = model->GetLabelAt(index);
  auto rawSecondaryLabel = model->GetSecondaryLabelAt(index);
  NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);

  NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
                                                action:@selector(itemSelected:)
                                         keyEquivalent:@""];

  if (!rawSecondaryLabel.empty()) {
    NSString* secondary_label =
        l10n_util::FixUpWindowsStyleLabel(rawSecondaryLabel);
    if (@available(macOS 14.4, *)) {
      item.subtitle = secondary_label;
    }
  }

  // If the menu item has an icon, set it.
  ui::ImageModel icon = model->GetIconAt(index);
  if (icon.IsImage())
    [item setImage:icon.GetImage().ToNSImage()];

  std::u16string toolTip = model->GetToolTipAt(index);
  [item setToolTip:base::SysUTF16ToNSString(toolTip)];

  std::u16string role = model->GetRoleAt(index);
  electron::ElectronMenuModel::ItemType type = model->GetTypeAt(index);

  if (role == u"services") {
    std::u16string title = u"Services";
    NSString* sub_label = l10n_util::FixUpWindowsStyleLabel(title);

    [item setTarget:nil];
    [item setAction:nil];
    NSMenu* submenu = [[NSMenu alloc] initWithTitle:sub_label];
    [item setSubmenu:submenu];
    [NSApp setServicesMenu:submenu];
  } else if (role == u"sharemenu") {
    SharingItem sharing_item;
    model->GetSharingItemAt(index, &sharing_item);

Review comment (suggestion):
Minor nit to avoid l10n when not needed

```suggestion
     if (@available(macOS 14.4, *)) {
      NSString* secondary_label =
          l10n_util::FixUpWindowsStyleLabel(rawSecondaryLabel);
      item.subtitle = secondary_label;
    }
```

Code after:
                        withItems:(NSArray*)items {
  NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:service.menuItemTitle
                                                action:@selector(performShare:)
                                         keyEquivalent:@""];
  [item setTarget:self];
  [item setImage:service.image];
  [item setRepresentedObject:@{@"service" : service, @"items" : items}];
  return item;
}

- (NSMenuItem*)makeMenuItemForIndex:(NSInteger)index
                          fromModel:(electron::ElectronMenuModel*)model {
  std::u16string label16 = model->GetLabelAt(index);
  auto rawSecondaryLabel = model->GetSecondaryLabelAt(index);
  NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);

  NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
                                                action:@selector(itemSelected:)
                                         keyEquivalent:@""];

  if (!rawSecondaryLabel.empty()) {
    if (@available(macOS 14.4, *)) {
      NSString* secondary_label =
          l10n_util::FixUpWindowsStyleLabel(rawSecondaryLabel);
      item.subtitle = secondary_label;
    }
  }

  // If the menu item has an icon, set it.
  ui::ImageModel icon = model->GetIconAt(index);
  if (icon.IsImage())
    [item setImage:icon.GetImage().ToNSImage()];

  std::u16string toolTip = model->GetToolTipAt(index);
  [item setToolTip:base::SysUTF16ToNSString(toolTip)];

  std::u16string role = model->GetRoleAt(index);
  electron::ElectronMenuModel::ItemType type = model->GetTypeAt(index);

  if (role == u"services") {
    std::u16string title = u"Services";
    NSString* sub_label = l10n_util::FixUpWindowsStyleLabel(title);

    [item setTarget:nil];
    [item setAction:nil];
    NSMenu* submenu = [[NSMenu alloc] initWithTitle:sub_label];
    [item setSubmenu:submenu];
    [NSApp setServicesMenu:submenu];
  } else if (role == u"sharemenu") {
    SharingItem sharing_item;
    model->GetSharingItemAt(index, &sharing_item);