Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Controlling Localization Switcher visibility in Payload Admin UI (per role / per collection)

default discord avatar
kento105 months ago
2

Hey everyone 👋


I’m using Payload CMS with localization enabled. After enabling it, the locale switcher appears globally in the admin UI, which is expected.



However, my admin panel is role-based:


service-provider → offers collection


client → orders collection


admin → pages collection with page builder



My goal is to have partial localization in the admin UI:

Localization only for the pages collection


Locale switcher visible only to admins (or only when viewing specific collections)



I couldn’t find any config option for controlling the Localization Switcher in admin.components or custom root components.



Questions:

Is there an official way to control or disable the default locale switcher?


Can it be scoped per role or per collection?


Would the best approach be hiding the default switcher and injecting a custom one only on the Pages collection view?



Any guidance or best practices would be appreciated 🙏

  • default discord avatar
    _elmgren5 months ago

    Currently Payload doesn't have a built-in way to conditionally show/hide the locale switcher



    Isn't [filtering available locales](

    https://payloadcms.com/docs/configuration/localization#filter-available-options

    ) sufficient?



    To hide it completely I'd suggest a new prop in the config to the Payload team.



    A workaround I can think of would be to add some simple css in

    custom.scss

    to hide it. For example:


    .payload-localizer-wrapper[data-user-role="service-provider"] .localizer,
    .payload-localizer-wrapper[data-user-role="client"] .localizer {
      display: none;
    }


    And then create a JSX component, maybe a provider and inject the

    data-user-role

    attribute on the body.



    export const LocalizerControlProvider = ({ children }) => {
      const { user } = useAuth()
      
      return (
        <div className="payload-localizer-wrapper" data-user-role={user?.role}>
          {children}
        </div>
      )
    }


    Add this via

    admin.components.providers

    in your config.



    Just some pseudo code, you can change the data attributes and values accordingly, for example extract what collection the user currently is visiting and updating accordingly

  • default discord avatar
    kento104 months ago

    Thank you! that’s exactly what I needed 🙏


    I hadn’t thought about using a data attribute + CSS, but that’s actually a really elegant approach.


    With this workaround, the localization problem is completely solved for my use case. Thanks a lot for the idea and the clear explanation!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.