Configure languages

The API serves content per language. Every content endpoint is prefixed with a language code (/api/<language>/…) and the /api/languages/ endpoint reports what is available. This guide configures django CMS so those endpoints behave the way you expect.

djangocms-rest does not add language settings of its own — it reads django CMS’s CMS_LANGUAGES. Configuring languages here means configuring django CMS.

Goal

Expose two languages (English and German), make German non-public, and have requests for a missing translation fall back to English.

Steps

  1. Enable Django i18n and declare the languages:

    # settings.py
    from django.utils.translation import gettext_lazy as _
    
    USE_I18N = True
    LANGUAGE_CODE = "en"
    
    LANGUAGES = [
        ("en", _("English")),
        ("de", _("German")),
    ]
    
  2. Configure CMS_LANGUAGES. The per-language keys map directly onto the fields of the /api/languages/ endpoint:

    CMS_LANGUAGES = {
        1: [  # keyed by SITE_ID
            {
                "code": "en",
                "name": _("English"),
                "public": True,
            },
            {
                "code": "de",
                "name": _("German"),
                "public": False,          # hidden from the public API
                "hide_untranslated": True,
            },
        ],
        "default": {
            "fallbacks": ["en"],
            "redirect_on_fallback": True,
            "public": True,
            "hide_untranslated": False,
        },
    }
    

Verify

curl http://localhost:8080/api/languages/

The endpoint lists all configured languages for the current site, each with its public flag — so de appears in the list with "public": false. Use the flag in the frontend to decide which languages to surface.

How it behaves

  • The languages endpoint reports every configured language (public and non-public); it does not hide non-public ones. Public-only filtering happens on the content endpoints.

  • Requesting a non-public or unconfigured language code on a content endpoint returns 404 Not Found (for anonymous users) rather than leaking that the language exists.

  • When a page has no translation for the requested language, django CMS’s fallbacks apply: the API returns the fallback translation. Set hide_untranslated: True to return 404 instead of falling back.

See also