Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Multilingual support for django-rest-framework

Project Description


Adding translation support to django-rest-framework.

This package adds support for TranslatableModels from django-parler to django-rest-framework.


pip install django-parler-rest


  • First make sure you have django-parler installed and configured.
  • Use the serializers as demonstrated below to expose the translations.

First configure a model, following the django-parler documentation:

from django.db import models
from parler.models import TranslatableModel, TranslatedFields

class Country(TranslatableModel):
    Country database model.

    country_code = models.CharField(_("Country code"), unique=True, db_index=True)

    translations = TranslatedFields(
        name = models.CharField(_("Name"), max_length=200)
        url = models.URLField(_("Webpage"), max_length=200, blank=True)

    class Meta:
        verbose_name = _("Country")
        verbose_name_plural = _("Countries")

    def __unicode__(self):

The model translations can be exposed as a seperate serializer:

from rest_framework import serializers
from parler_rest.serializers import TranslatableModelSerializer, TranslatedFieldsField
from .models import Country   # Example model

class CountrySerializer(TranslatableModelSerializer):
    translations = TranslatedFieldsField(shared_model=Country)

    class Meta:
        model = Country
        fields = ('id', 'country_code', 'translations')

This will expose the fields as a separate dictionary in the JSON output:

    "id": 528,
    "country_code": "NL",
    "translations": {
        "nl": {
            "name": "Nederland",
            "url": ""
        "en": {
            "name": "Netherlands",
            "url": ""
        "de" {
            "name": "Niederlande",
            "url": ""


This module is designed to be generic. In case there is anything you didn’t like about it, or think it’s not flexible enough, please let us know. We’d love to improve it!

If you have any other valuable contribution, suggestion or idea, please let us know as well because we will look into it. Pull requests are welcome too. :-)

Running tests

Tests are run with py.test:

python test  # install dependencies and run tests with coverage

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(9.6 kB) Copy SHA256 Hash SHA256
py2 Wheel Jun 17, 2016
(9.6 kB) Copy SHA256 Hash SHA256
py2.py3 Wheel Jun 17, 2016
(12.2 kB) Copy SHA256 Hash SHA256
Source Jun 17, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting