metaobjectDefinition with Translated Response

Hello everyone,
I have the following query in the Shopify Graphiql App:

uery MyQuery {
  metaobjectDefinitions(first: 250) {
    nodes {
      id
      standardTemplate {
        name
        type
      }
    }
  }
}

Depending on which language I have defined as the user, I receive either the German or English version under standardTemplate.

However, I cannot find an entry in the request to define which language should be returned in my own app.

I couldn’t find anything in the documents for the headers that could explain this either.

Unfortunately, nothing happens with the following header either:

{
  "Accept-Language": "de"
}

You can use the translatable resource api to get the original content and what locale it is in and the translations available

If you are using the storefront api, you can use the directives to get the content in a specific language

It’s not directly related but I’ve got more background on managing translated content here

Yes, that is correct, but why is the query treated differently?

If you could somehow use it as an accept language, you could save yourself further queries.

Sorry I don’t quite understand the question. why is the query treated differently?
GraphQL doesn’t interact with the headers generally as its not a REST API and so has different protocols for doing things

Exactly, that’s what I thought too. Is this handled differently by the ‘Shopify GraphiQL App’?

Here is the response from the query above when I have my account language in German in Shopify:

{
  "data": {
    "metaobjectDefinitions": {
      "nodes": [
        {
          "id": "gid://shopify/MetaobjectDefinition/5088969052",
          "standardTemplate": {
            "name": "Größe",
            "type": "shopify--size"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5089263964",
          "standardTemplate": {
            "name": "Farbe",
            "type": "shopify--color-pattern"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5089853788",
          "standardTemplate": {
            "name": "Zielgeschlecht",
            "type": "shopify--target-gender"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5092409692",
          "standardTemplate": {
            "name": "Schuhgröße",
            "type": "shopify--shoe-size"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5101486428",
          "standardTemplate": {
            "name": "Altersgruppe",
            "type": "shopify--age-group"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5101519196",
          "standardTemplate": {
            "name": "Stoff",
            "type": "shopify--fabric"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5117411676",
          "standardTemplate": {
            "name": "Ausschnitt",
            "type": "shopify--neckline"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/9227665756",
          "standardTemplate": {
            "name": "Zubehörgröße",
            "type": "shopify--accessory-size"
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 24,
      "actualQueryCost": 12,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1988,
        "restoreRate": 100
      }
    }
  }
}

The names of the standard template are output in German.

If I now change the account language to English and make the same query again, I get this response:

{
  "data": {
    "metaobjectDefinitions": {
      "nodes": [
        {
          "id": "gid://shopify/MetaobjectDefinition/5088969052",
          "standardTemplate": {
            "name": "Size",
            "type": "shopify--size"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5089263964",
          "standardTemplate": {
            "name": "Color",
            "type": "shopify--color-pattern"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5089853788",
          "standardTemplate": {
            "name": "Target gender",
            "type": "shopify--target-gender"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5092409692",
          "standardTemplate": {
            "name": "Shoe size",
            "type": "shopify--shoe-size"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5099422044",
          "standardTemplate": {
            "name": "Material",
            "type": "shopify--material"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5101486428",
          "standardTemplate": {
            "name": "Age group",
            "type": "shopify--age-group"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5101519196",
          "standardTemplate": {
            "name": "Fabric",
            "type": "shopify--fabric"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/5117411676",
          "standardTemplate": {
            "name": "Neckline",
            "type": "shopify--neckline"
          }
        },
        {
          "id": "gid://shopify/MetaobjectDefinition/9227665756",
          "standardTemplate": {
            "name": "Accessory size",
            "type": "shopify--accessory-size"
          }
        }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 24,
      "actualQueryCost": 12,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1988,
        "restoreRate": 100
      }
    }
  }
}

Now the names of the standard template are displayed in English.

The question here is why the app ‘translates’ and displays the names depending on the language setting.

Even if I change this to French, it is displayed in French, although I have not activated the language in the online shop.

The app must know which language I have selected and pass it somewhere during the query.

I hope you understand it a little better now.

When you say “account language” what do you mean? The default language of the store? :thinking:

The main language of the store is German and English is also available.

However, the change I mean is under your own Shopify account:
Top right on the store / Manage account

Depending on which “own” language I have selected there, the result in the GraphQL app is then also adapted.

Here, for example, I can also select French in my account and the query returns the names in French, even though I have never entered them (I can’t speak the language either :smiley: )

If you use the directives with queries that we discussed, do you get the content back in the language that you want?
Otherwise we’re debugging the iGraphQL app :joy:

Unfortunately, I cannot retrieve a translation of the name from the metaobjectDefinitions.

I also cannot find a way to retrieve the metaobjectDefinitions via the storefront.

I am not interested in the individual metaobjects or metafields where I can retrieve the translation.

It’s about the metaobjectDefinition of the standard Shopify product attributes and their names (example metaobject type - shopify–age-group)

What you’re seeing here is a standard localization feature. Standard Metaobject definition templates are Shopify-defined fixtures with backing translations in all major languages. When you load the record, it is contextualized to your localization context. This will not happen with user-defined Metaobject definitions.

1 Like