How does the fallback-locale suppose to work with blocks field?

default discord avatar
quornik
9 months ago
1 2

I struggle to work with fallback locale functionality and REST API. From what I observed so far, it does not work as I would expect and I don't know what am I doing wrong.
My collection has the blocks field defiintion as follows:

{
  type:'blocks',
  name: 'blocks',
  label: 'Bloki z treścią',
  localized: true,
  blocks: [
    Richtext,
    Columns,
    GalleryColumns,
    LargePhoto,
  ]
},
  • It does not work for common queries like ?where[slug][equals]=slug-string?locale=en&fallback-locale=pl it only works when I query with /api/model/[itemId]?locale=en&fallback-locale=pl, and with /api/model?locale=en&fallback-locale=pl but this is something I can actually understand why, even if it does create a headache.
  • It does not seem to work for blocks field, even if the one is localized: true and filled with data on locale which supposed to be the fallback one. The fields inside blocks are not localized: true as I figured that - logically - if the wrapping element (blocks field) is localized, that inner elements shouldn't be. It works on the UI - switching locale on admin to empty one, provides me with the blank blocks field, ready to be filled. However, i thought that leaving it as blank, should fill the content from the fallback on API request?

Current packeges version of mine:

  "dependencies": {
    "@payloadcms/plugin-seo": "^1.0.9",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "nodemailer": "^6.8.0",
    "nodemailer-sendgrid": "^1.0.3",
    "payload": "^1.2.0",
    "payload-s3-upload": "^1.1.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }

and config has localization provided as:

localization: {
    locales: [
      'pl',
      'en'
    ],
    defaultLocale: 'pl',
    fallback: true,
  },

How can I force this mechanism to return blocks field with data from fallback locale?

  • discord user avatar
    DanRibbens
    Payload Team
    9 months ago

    Thanks for opening up issue 1695, adding the link here for visibility.

  • default discord avatar
    quornik
    9 months ago

    Oh! I got something!
    The blocks field with localized: true writes itself to the database WITH locales as arrays. Even if the locales are empty arrays, it just does so. Therefore, the mechanism on which fallback-locale searches for empty records in one locale, to fill it with data from the fallback, is tricked to thinking that i've already filled the locale data with something. But it is just empty array.

    So the question is: How to force the blocks field not to write it so? Is it a bug or is it a feature? :)

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.