Retrieve localizations of deep objects

System Information
  • Strapi Version: 4.3.4

We are developing a documentation site with Strapi which should be able to be viewed in two different languages, but as we are adding content to the Strapi side, no all of it is already localised in both languages, so I’m trying to handle retrieve of content in all the locales using the populate=localizations option, but I’m struggling to make it work when retrieving content with deep object.

I have a single-type object called Home with the following schema:

{
  "kind": "singleType",
  "collectionName": "homes",
  "info": {
    "singularName": "home",
    "pluralName": "homes",
    "displayName": "Home",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {
    "i18n": {
      "localized": true
    }
  },
  "attributes": {
    "title": {
      "type": "string",
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "required": true
    },
    "content": {
      "type": "richtext",
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      },
      "required": true
    },
    "homeColumns": {
      "type": "component",
      "repeatable": true,
      "component": "home.column",
      "max": 2,
      "pluginOptions": {
        "i18n": {
          "localized": true
        }
      }
    }
  }
}

When retrieving data via REST API like this http://admin.localhost:8080/api/home?populate=*, what I get is:

{
   "data":{
      "id":1,
      "attributes":{
         "title":"Magma",
         "content":"**Magma** è un Design System adattabile basato su linee guida, componenti e strumenti che supportano le migliori pratiche di progettazione della UI. Il suo scopo è semplificare la collaborazione tra designer e sviluppatori e aiutare i team a creare rapidamente splendidi prodotti.",
         "createdAt":"2022-07-29T14:18:26.492Z",
         "updatedAt":"2022-09-08T07:39:41.049Z",
         "publishedAt":"2022-07-29T16:54:51.406Z",
         "locale":"it",
         "homeColumns":[
            {
               "id":3,
               "title":"Un prodotto per creare prodotti",
               "content":"Un Design System è un prodotto a tutti gli effetti, creato per dare consistenza ai nostri prodotti e assicurarci che l'utente possa beneficiare delle convenzioni di design e UX che offre.\n\nQuesto approccio permette di sviluppare applicazioni scalabili riconducibili ad un ecosistema di prodotti appartenenti al brand Maggioli, ma con un livello di flessibilità in grado di dare spazio di manovra sulla sua configurazione, sia a livello visivo che di UX."
            },
            {
               "id":4,
               "title":"Competenze condivise",
               "content":"Per pubblicare un prodotto che rappresenti la nostra identità, Magma usa il modello di contribuzione del software open source, ma circoscritto a Maggioli.\n\nChiunque può contribuire e portare la propria esperienza, definire una regola, mettere in discussione qualcosa che è già stato deciso, segnalare un problema o chiedere di aggiungere una funzionalità specifica.\n\nMagma converge la conoscenza di dominio di chiunque vuole prenderne parte."
            }
         ],
         "localizations":{
            "data":[
               {
                  "id":2,
                  "attributes":{
                     "title":"Magma Design System",
                     "content":"**Magma** is an adaptable Design System based on guidelines, components and tools that support UI design best practices. Its purpose is to simplify collaboration between designers and developers and to help teams quickly create beautiful products.",
                     "createdAt":"2022-08-18T13:34:10.871Z",
                     "updatedAt":"2022-09-08T09:47:46.431Z",
                     "publishedAt":"2022-08-18T13:38:44.224Z",
                     "locale":"en"
                  }
               }
            ]
         }
      }
   },
   "meta":{
      
   }
}

As you can see, in the localizations property the data of the first level are retrieved, but I couldn’t find a way to include the homeColumns data too.

Anyone can suggest how to include the homeColumns version of the other locale in the localizations property using REST API? Or is it something I can accomplish only by writing custom code?

I also tried something like home?populate[0]=homeColumns,localizations&populate[1]=homeColumns.localizations thinking it would add the localizations property in the homeColumns array, but with no success (still new to all this Strapi environment :slight_smile: )

2 Likes

In case this is still relevant or for future readers:
you were quite close with your attempt. the query in your request should look like this:

populate[0]=homeColumns,localizations&populate[1]=localizations.homeColumns

Anyway, this is just a way of workaround. This would be a great feature, if the strapi-populate-deep plugin would support population of localization by default. I miss that too.