According to this Voyager issue thedevdojo/voyager#3835, the author says there's no built-in function to translate the Voyager menu items. You need to write a custom function to solve it manually.
I've created a function to translate Voyager menu items for you. So you don't need to write it again.
<?php
function translateMenuItems($menuItems, string $locale)
{
$translatedItems = [];
foreach ($menuItems as $item) {
$translatedItem = $item->translate($locale);
if (isset($item['children'])) {
$translatedItem['children'] = translateMenuItems($item['children'], $locale);
}
array_push($translatedItems, $translatedItem);
}
return $translatedItems;
}
<?php
use TCG\Voyager\Models\Menu;
$locale = 'en'; // https://voyager-docs.devdojo.com/core-concepts/multilanguage
$menuItems = Menu::display("menu-name", '_json'); // Get Voyager menu item with JSON form instead of HTML form
$translatedMenuItems = translateMenuItems($menuItems, $locale);