Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Query a specific locale

How to query a specific locale in Optimizely Graph.

Optimizely Graph lets you retrieve content in specific languages using locale-aware GraphQL queries. This ensures users receive content in their preferred language and enables fallback behavior when translations are unavailable.

Optimizely Graph supports multiple ways to query localized content. The following are the most common patterns:

Query a single locale

Use this approach when you want to retrieve content in one specific language. It is ideal for scenarios where the user’s language preference is known, and a fallback is not required. The following query fetches English-language articles and is limited to 10 results:

query GetContentInEnglish {
  ArticlePage(locale: [en], limit: 10) {
    items {
      Name
      TeaserText
      StartPublish
      RelativePath
      Language {
        Name
        DisplayName
      }
    }
  }
}

Query multiple languages

Use this method when you want to retrieve content in more than one language. This is helpful for language switchers or when displaying content in multiple locales side by side.

query ContentInMultipleLanguages($locales: [Locales!]!) {
  ArticlePage(
    locale: $locales
    limit: 20
    orderBy: { StartPublish: DESC }
  ) {
    items {
      Name
      TeaserText
      StartPublish
      RelativePath
      Language {
        Name
        DisplayName
      }
    }
  }
}

The following are some example variables:

{
  "locales": ["en", "sv"]
}

Query with user-preferred locale and fallback (CMS13 and SaaS CMS)

Optimizely Graph supports automatic fallback to a configured language when content is not available in the requested locale (CMS13 and SaaS CMS). This is useful when you want to prioritize a user’s preferred language but still show content if a translation is missing.

If English is unavailable for a given item, Optimizely Graph automatically falls back to the next configured language in your CMS settings. In the following example, the query requests English content:

query LocalizedContent($locales: [Locales!]!) {
  ArticlePage(
    locale: $locales
    orderBy: { StartPublish: DESC }
  ) {
    items {
      Name
      TeaserText
      StartPublish
      RelativePath
      Language {
        Name
        DisplayName
      }
    }
  }
}

The following are some example variables:

{
  "locales": ["en"]
}