Plugin dev: cannot retrieve active locale for the record in itemFormSidebarPanels context

Hi Dato,

I’m working on a basic sidebar panel plugin that should react depending on the active locale the user is editing.
Actually, I would like to create buttons depending on the active locale.

Regarding the documentation, the locale value should be available via ctx.locale but console.logging it gives me a undefined response:

itemFormSidebarPanels(model: ItemType, ctx: ItemFormSidebarPanelsCtx) {
		console.log('locale', ctx.locale)
...
}

Maybe I’m doing something wrong … Could you please tell me if I can retrieve this value ?
The related question, if it’s a yes, is this value reactive, meaning, when the user switch to another locale, is the value changing ?

Thanks for your help. :pray:

Best

OK …

I can retrieve the value into

renderItemFormSidebarPanel(
        sidebarPanelId,
        ctx: RenderItemFormSidebarPanelCtx,
    ) {
        console.log('locale', ctx.locale);

Let me see if I can achieve what I need :slight_smile:

Hi there,

My plugin is almost finished :slight_smile: !
Thanks to your help on Slack, I could find the solution.
ctx.locale was available in renderItemFormSidebarPanel method, not in itemFormSidebarPanels.

Anyway, got a last question.
Is there a way to get itemStatus for the current locale?
As far as I could see, ctx.itemStatus returns a string where possible values are new | draft | updated | published.
Let imagine I have 2 locales for a record, the 1st one is published, the second is not. How could I get the per-locale itemStatus ?

Thanks for your help.

PS: My plugin is quite simple, it’s a sidebar links, but … localized sidebar links, meaning that you can declare in the config, per model-record, depending on the locale of the record, allowing you for example to declare different published or draft URL depending of the record locale.

@ghislain.flandin,

Our UI doesn’t do the best job of communicating this (sorry), but in DatoCMS, localizations are applied to specific fields, but publication status is tied to records. If you have a record with a “title” field in English & Italian, for example:

  • If you add a English title and save and publish it, the record status will be published
  • You add an Italian title and hit save. The record status is updated, and this applies to the whole record, not just any one field or locale.
  • You then publish the changes and the whole record becomes published.

If you need more fine-grained diffing than that, you’ll unfortunately have to use the CMA to retrieve and compare the versions: https://www.datocms.com/docs/content-management-api/resources/item-version

Thank you @roger for your reply.

Actually, I don’t need it at field level, but at locale level.
what I want to achieve is to print a “View Live version” button only if the record is published … but in the current local.
itemStatus property does not allow that.

Could be an improvement for future release :wink:

Best.

Yes, sorry, that’s not easy to do right now without a manual diffing. In our current model, you can edit several fields across several locales and save it all as one version. The publication status is record-level, not field-level.

You can make a feature request for it here, but it would be a pretty huge backward-incompatible change, so it would be difficult to implement :frowning: