Kontent.ai
Copyright © 2023 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Documentation
  • API reference
  • Product updates
Kontent.ai Learn
  • Plan
  • Set up
  • Model
  • Develop
  • Create

Ways to get localized content

Is this page helpful?
Complete and continue
  • Sign in
    • JavaScript
      JavaScript
    • TypeScript
      TypeScript
    • .NET
      .NET
    • Java
      Java
    • PHP
      PHP
    • Ruby
      Ruby
    • REST
      REST
    • GraphQL
      GraphQL
    Jan Cerman
    12 minutes
    If you plan to display culture-specific content, your app needs to know how to retrieve content in specific languages.Depending on what you know about your content, there are a few ways to go about this.

    Languages and localization

    Each language in your Kontent.ai project is uniquely identified by its codename. The codename can be any string,  such as English, en-US, or en-GB.

    Get content in a specific language

    To get localized content from your project, specify the language using the language's codename. For example, to get an article named About Us in Spanish, specify the item's codename and the language's codename.

    Get items by localized URL slug

    Depending on how you implement routing in your app, you might want to request content items by their URL slugs. If all you know about the content item is its URL slug, you need to request all items and filter them by the URL slug. This approach scales for both small and enterprise projects. To retrieve a localized content item by its URL slug, you need to do two things when making the API call:
    • Specify the language using the language’s codename, such as es-ES for Spanish.
    • Filter by the URL slug element’s value.
    If the specified query doesn’t match any content items, the Delivery API returns an empty response.

    Ignoring language fallbacks

    If you need to ensure you get content in only the specified language, you can filter out the content items that are in another language than specified. This effectively bypasses any language fallbacks. For example, this is how you retrieve content items translated into Spanish without any fallbacks.
    The following table shows what content the API returns for specific combinations of language-related filters. The example assumes a project with the default language set as English en-US and the second language set as Spanish es-ES, which falls back to the default language.
    • language=es-ES – Specifies the codename of the requested language.
    • system.language=es-ES – Filters content items by their language.
    language parameter valuesystem.language parameter valueBehavior
    es-ES<not set>The API returns content items in Spanish. If an item is not translated to Spanish, the API returns the English (en-us) version of the items as fallback.
    es-ESes-ESThe API returns only content items in Spanish. If an item is not translated to Spanish, the API doesn't return it.
    es-ESen-USThe API returns only content items in English provided they don't have content in Spanish. If an item is translated to Spanish, it is not returned.
    What's next?
    Filter content to get what you need
    The Delivery API provides several filters to help you refine your requests based on your requirements. To choose the right one, think about what you know about the content you want to get. There’s a filter for every use case.Find a scenario relevant to you and adjust the code samples to get the content you need.
    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification
    • Quickstart
    • Get content
    • Get localized content
    • Use the right filters
    • cURL
    • cURL
    • cURL
    Your default languageEvery project comes with a single default language that cannot be removed. When you request content without specifying a language, Delivery API returns content in the default language.
    What if the item doesn't exist in the specified language?The Delivery API checks the fallbacks of the specified language. If the content exists in the fallback language set for the requested language, you get the content item's content in the fallback language.
    curl --request GET \
      --url 'https://deliver.kontent.ai/8d20758c-d74c-4f59-ae04-ee928c0816b7/items/about_us?language=es-ES' \
      --header 'content-type: application/json'
    curl --request GET \
      --url 'https://deliver.kontent.ai/8d20758c-d74c-4f59-ae04-ee928c0816b7/items?language=es-ES&system.type=article&elements.url_pattern=acerda-de-nosotros' \
      --header 'content-type: application/json'
    curl --request GET \
      --url 'https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?language=es-ES&system.language=es-ES' \
      --header 'content-type: application/json'
  • Languages and localization
  • Get content in a specific language
  • Get items by localized URL slug
  • Ignoring language fallbacks