Search code examples
reactjsadmin-on-restreact-admin

No translation for MenuItemLink's primaryText in react-admin


I'm using a custom user menu and the primarytext is not translated as expected. No problems with the others components.

const MyUserMenu = props => 
    <UserMenu {...props}>
        <MenuItemLink
            to="/configuration"
            primaryText="labels.configuration"
            leftIcon={<SettingsIcon />}
        />
    </UserMenu>

Solution

  • You'll have to explicitly translate it as the MenuItemLink component is not currently responsible for translations (might be a good feature request btw).

    import { translate, UserMenu, MenuItemLink, translate } from 'react-admin';
    
    const MyUserMenu = translate(({ translate, ...props }) => 
        <UserMenu {...props}>
            <MenuItemLink
                to="/configuration"
                primaryText={translate("labels.configuration")}
                leftIcon={<SettingsIcon />}
            />
        </UserMenu>