Localizing content

Localizing content

Prepr offers the Localization API that enables you to publish content in multiple locales. You can add locales to your project by navigating to the environment settings.

When fetching item collections and single-item types, you can specify a locale as an argument in your query. If no locale is specified, the default locale is used.

Please note, the locales argument cascades, meaning that all linked content items will resolve with the specified locale.

Check out our localization docs for more details.

Fallback locales

On all collections the locales argument can be given to set fallback locale(s). The argument is processed from left to right.

In this example, if there is no version for the de-DE locale, the en-US locale will be returned.

query {
  Page( locales : ["de-DE", "en-US"] ) {
    items {
        _id,
        title
    }
  }
}

Fetching all locales

All content items are generated with a _localizations field that contains all available locales for that content item. Make sure to add the same fields to the top level of the query, since the _localizations field will only return the values of items that are also specified outside the _localizations field.

query {
  Page {
    items {
        _id,
        _slug
        title
        _localizations {
            _id
            _slug
            title
        }
    }
  }
}

Fetching locale by HTTP header

You can add the Prepr-Locale header to your request to override the default locale.

'Prepr-Locale' : 'en-US'

Was this article helpful?

We’d love to learn from your feedback