انتقل إلى المحتوى
For the complete DHIS2 documentation index, see llms.txt.

I18n

Locales

DHIS2 supports translations both for the user interface and for database content.

UI locales

You can retrieve the available locales for the user interface through the following resource with a GET request. XML and JSON resource representations are supported.

/api/33/locales/ui

Database content locales

You can retrieve and create locales for the database content with GET and POST requests through the dbLocales resource. XML and JSON resource representations are supported. To POST data, there are two required parameters: country and language.

/api/locales/dbLocales?country=US&language=en

Translations

DHIS2 allows for translations of database content. If a metadata is translatable, then it will have a translations property.

That means you can retrieve and update translations using metadata class resources such as api/dataElements, api/organisationUnits, api/dataSets, etc.

Get translations

You can get translations for a metadata object such as DataElement by sending a GET request to api/dataElements/{dataElementUID}

The response contains full details of the DataElement which also includes the translations property as below

{
  "id": "fbfJHSPpUQD",
  "href": "https://play.dhis2.org/dev/api/29/dataElements/fbfJHSPpUQD",
  "created": "2010-02-05T10:58:43.646",
  "name": "ANC 1st visit",
  "shortName": "ANC 1st visit",
  "translations": 
  [
    {
      "property": "SHORT_NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    },
    {
      "property": "NAME",
      "locale": "fr",
      "value": "Soin prénatal 1"
    },
    {
      "property": "NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    }
  ]
}
You can also get only the translations property of an object by sending a GET request to api/dataElements/{dataElementUID}/translations
{
  "translations": 
  [
    {
      "property": "SHORT_NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    },
    {
      "property": "NAME",
      "locale": "fr",
      "value": "Soin prénatal 1"
    },
    {
      "property": "NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    }
  ]
}

Create/Update translations

You can create translations by sending a PUT request with same JSON format to api/dataElements/{dataElementUID}/translations

{
  "translations": 
  [
    {
      "property": "SHORT_NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    },
    {
      "property": "NAME",
      "locale": "fr",
      "value": "Soin prénatal 1"
    },
    {
      "property": "DESCRIPTION",
      "locale": "fr",
      "value": "description in french"
    },
    {
      "property": "FORM_NAME",
      "locale": "fr",
      "value": "name in french"
    }
  ]
}

Alternatively, you can also just update the object with payload including the translations property.

Send PUT request to api/dataElements/{dataElementUID} with full object payload as below:

{
  "id": "fbfJHSPpUQD",
  "created": "2010-02-05T10:58:43.646",
  "name": "ANC 1st visit",
  "shortName": "ANC 1st visit",
  "translations": 
  [
    {
      "property": "SHORT_NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    },
    {
      "property": "NAME",
      "locale": "fr",
      "value": "Soin prénatal 1"
    },
    {
      "property": "NAME",
      "locale": "en_GB",
      "value": "ANC 1st visit"
    }
  ]
}

The status code will be 204 No Content if the data value was successfully saved or updated, or 409 Conflict if there was a validation error (e.g. more than one SHORT_NAME for the same locale).

The common properties which support translations are listed in the table below.

Property names
Property name Description
name Object name
shortName Object short name
description Object description

The classes which support translations are listed in the table below.

Class names
Class name Description Other translatable Properties
DataElementCategoryOption Category option
DataElementCategory Category
DataElementCategoryCombo Category combination
DataElement عنصر البيانات
DataElementGroup Data element group
DataElementGroupSet Data element group set
Indicator Indicator numeratorDescription, denominatorDescription
IndicatorType Indicator type
IndicatorGroup Indicator group
IndicatorGroupSet Indicator group set
OrganisationUnit الوحدة التنظيمية
OrganisationUnitGroup Organisation unit group
OrganisationUnitGroupSet Organisation unit group set
DataSet Data set
القسم Data set section
ValidationRule Validation rule instruction
ValidationRuleGroup Validation rule group
Program Program enrollmentDateLabel, incidentDateLabel
ProgramStage Program stage executionDateLabel, dueDateLabel
TrackedEntityAttribute Tracked entity attribute
TrackedEntity Tracked entity
RelationshipType Relationship type for tracked entity instances fromToName, toFromName
OptionSet Option set
Attribute Attribute for metadata
ProgramNotificationTemplate Program Notification template subjectTemplate, messageTemplate
ValidationNotificationTemplate Validation Notification template subjectTemplate, messageTemplate
DataSetNotificationTemplate DataSet Notification template subjectTemplate, messageTemplate
Visualization Visualization title, subtitle, rangeAxisLabel, baseLineLabel, targetLineLabel, domainAxisLabel
ProgramRuleAction Program Rule Actions content
Predictor Predictor Name, ShortName, Description, Generator Description
ValidationRule ValidationRule Name, Description, Instruction, Leftside expression, Rightside expression

Internationalization

In order to retrieve key-value pairs for translated strings you can use the i18n resource.

/api/33/i18n

The endpoint is located at /api/i18n and the request format is a simple array of the key-value pairs:

[
  "access_denied",
  "uploading_data_notification"
]

The request must be of type POST and use application/json as content-type. An example using curl, assuming the request data is saved as a file keys.json:

curl -d @keys.json "play.dhis2.org/demo/api/33/i18n" -X POST
  -H "Content-Type: application/json" -u admin:district

The result will look like this:

{
  "access_denied":"Access denied",
  "uploading_data_notification":"Uploading locally stored data to the server"
}