HELP with Importing Translations

@Markus, @magl, @stephocay, @Eric_Munyambabazi

In DHIS2 2.29 and above:

  1. Does anyone know what is the proper json format for importing translations through the Import/Export app?

OR

  1. Can someone lay out the steps of importing translations through the Web API? PLEASE DO NOT SEND ME TO THE DHIS2 GUIDE. I have been there and I have tried several options. I used postman to run POST https://myURL/api/26/translations and the below json format for several data elements. No success. I tried working with one data element only, removing the square brackets, using single quotes, etc. Still nothing. Thoughts?
    [
    {
    “objectId”: “F10ZOcwHvTv”,
    “className”: “DataElement”,
    “locale”: “fr”,
    “property”: “name”,
    “value”: "Otra modalidad "
    },
    {
    “objectId”: “GXiQ39JZKxU”,
    “className”: “DataElement”,
    “locale”: “fr”,
    “property”: “name”,
    “value”: "Otra modalidad (describa) "
    },
    {
    “objectId”: “mIJDiYz94qV”,
    “className”: “DataElement”,
    “locale”: “fr”,
    “property”: “name”,
    “value”: “Número de donantes”
    }
    ]

Georgi

1 Like

Hello all,

I figured out the import of translations for all objects through the Import/Export app, using a json format. Here are the steps for the those interested:

  1. Translate manually the details of your desired object (data element, option, TE attribute, etc.). Then export the object in json format through Metadata export of the Import/Export app. This will give you the proper json format of the object details, along with the translation code. Save this original metadata export for later.

  2. Use a json to csv converter to convert into a more user friendly format and follow the example of you translated object in step 1 to populate the translation properties, locale and values for the rest of your objects. This is a good converter to use: https://www.convertcsv.com/json-to-csv.htm

  3. Convert your csv/excel back to json using this converter https://www.convertcsv.com/csv-to-json.htm

  4. Observe the differences between the converted file in Step 3 and your original metadata export in Step 1, as the csv to json converter will not produce the exact json format needed for DHIS2 import. Some of the things to look for:

a) Make sure that in your work csv file, there are no empty fields in the middle of your data. For example, if there are empty descriptions of data elements just replace them with “N/A” or you will get an error at importing your json.

b) When you export your original metadata in Step 1, it will begin with this:
{“system”:{“id”:“49184e0e-2471-4265-a9d4-95c3f4f75eeb”,“rev”:“ae5b691”,“version”:“2.29”,“date”:“2020-03-30T09:26:55.738”},“dataElements”:[

This code will be missing in the converted json file in Step 3, so add it in the beginning AND add this bracket } at the end of the file to complete it.

c) There might be some fileds at the end of your csv that do not have any values, like userGroupAccesses, dataElementGroups, attributeValues if you work with data elements metadata. In the converted json file in Step 3, these empty fields will be coded as “userGroupAccesses”: “”. Replace the “” (space and double quotes) with [].

d) Generally, if you get errors at import observe the original metadata you exported in Step 1 and the one you produced in Step 3 and try to find any major differences, such as missing metadata object or format differences, fix them and try importing back.

Below are example of json formats for different objects that work for translations in two languages:

1. Data elements
{“system”:{“id”:“49184e0e-2471-4265-a9d4-95c3f4f75eeb”,“rev”:“ae5b691”,“version”:“2.29”,“date”:“2020-03-30T09:26:55.738”},“dataElements”:[
{
“code”: “geo_lev_01”,
“lastUpdated”: “2020-03-29T08:18:24.700”,
“id”: “xwhEtKWb87i”,
“created”: “2020-03-17T09:56:07.337”,
“name”: “1st level: states, cities, regions, other”,
“shortName”: “1st level: states, cities, regions, other”,
“aggregationType”: “NONE”,
“domainType”: “TRACKER”,
“publicAccess”: “rw------”,
“description”: “N/A”,
“valueType”: “LONG_TEXT”,
“formName”: “1st level: states, cities, regions, other”,
“zeroIsSignificant”: false,
“categoryCombo”: {
“id”: “bjDvmb4bfuf”
},
“lastUpdatedBy”: {
“id”: “zkApVOpQQNd”
},
“user”: {
“id”: “zkApVOpQQNd”
},
“translations”: [
{
“property”: “NAME”,
“locale”: “es”,
“value”: “1er nivel: estados, ciudades, regiones, otros”
},
{
“property”: “SHORT_NAME”,
“locale”: “es”,
“value”: “1er nivel: estados, ciudades, regiones, otros”
},
{
“property”: “FORM_NAME”,
“locale”: “es”,
“value”: “1er nivel: estados, ciudades, regiones, otros”
},
{
“property”: “DESCRIPTION”,
“locale”: “es”,
“value”: “N/A”
},
{
“property”: “NAME”,
“locale”: “fr”,
“value”: “1er niveau : États, villes, régions, autres”
},
{
“property”: “SHORT_NAME”,
“locale”: “fr”,
“value”: “1er niveau : États, villes, régions, autres”
},
{
“property”: “FORM_NAME”,
“locale”: “fr”,
“value”: “1er niveau : États, villes, régions, autres”
},
{
“property”: “DESCRIPTION”,
“locale”: “fr”,
“value”: “N/A”
}
],
“optionSet”: {
“id”:[]
},
“userGroupAccesses”:[],
“dataElementGroups”:[],
“attributeValues”:[],
“userAccesses”:[],
“legendSets”:[],
“aggregationLevels”:[]
}
]
}

2. Program Stage sections
{“system”:{“id”:“49184e0e-2471-4265-a9d4-95c3f4f75eeb”,“rev”:“ae5b691”,“version”:“2.29”,“date”:“2020-03-30T11:03:14.219”},“programStageSections”:[
{
“created”: “2020-02-11T11:18:01.009”,
“lastUpdated”: “2020-03-30T06:41:26.317”,
“name”: “ACTUAL TOTAL PARTICIPANTS (for projects that have ended in this FY)”,
“id”: “uZOBUbwlXgZ”,
“sortOrder”: 19,
“lastUpdatedBy”: {
“id”: “zkApVOpQQNd”
},
“programStage”: {
“id”: “k5vUtGga5yY”
},
“programIndicators”:[],
“translations”: [
{
“property”: “NAME”,
“locale”: “es”,
“value”: "PARTICIPANTES TOTALES REALES (si el proyecto ha terminado este AF) "
},
{
“property”: “NAME”,
“locale”: “fr”,
“value”: “TOTAL RÉEL DES PARTICIPANTS (si le projet a été finalisé au cours de cet exercice fiscal)”
}
],
“dataElements”: [
{
“id”: “qkw0nEMKMJl”
},
{
“id”: “dGAkmmLOvBG”
},
{
“id”: “jFosVs0cGOD”
},
{
“id”: “YQEUQvFmCQj”
},
{
“id”: “RSxkUpFT4GA”
},
{
“id”: “QTyBcOJK9es”
},
{
“id”: “YGT6bYHn7jW”
},
{
“id”:[]
},
{
“id”:[]
},
{
“id”:[]
},
{
“id”:[]
},
{
“id”:[]
},
{
“id”:[]
}
]
}
]
}

3. Options
{“system”:{“id”:“49184e0e-2471-4265-a9d4-95c3f4f75eeb”,“rev”:“ae5b691”,“version”:“2.29”,“date”:“2020-03-31T09:18:34.780”},“options”:[
{
“code”: “0. Harmful”,
“created”: “2020-03-31T09:16:48.469”,
“lastUpdated”: “2020-03-31T09:16:48.512”,
“name”: “0. Harmful”,
“id”: “hVmW0Q2FjOn”,
“sortOrder”: 1,
“optionSet”: {
“id”: “kTiTAh4Zq3D”
},
“attributeValues”:[],
“translations”: [
{
“property”: “NAME”,
“locale”: “es”,
“value”: “0. Nocivo”
},
{
“property”: “NAME”,
“locale”: “fr”,
“value”: “0. Nocif”
}
]
}
]
}

4. Tracked entity attributes

{“system”:{“id”:“49184e0e-2471-4265-a9d4-95c3f4f75eeb”,“rev”:“ae5b691”,“version”:“2.29”,“date”:“2020-03-31T10:53:39.626”},“trackedEntityAttributes”:[
{
“code”: “Contact 1 Email”,
“lastUpdated”: “2020-02-10T17:06:33.958”,
“id”: “RrGR4WnEE6X”,
“created”: “2020-02-10T17:06:33.958”,
“name”: “Contact #1 Email”,
“shortName”: “Contact 1 Email”,
“aggregationType”: “COUNT”,
“programScope”: false,
“displayInListNoProgram”: false,
“publicAccess”: “rw------”,
“generated”: false,
“displayOnVisitSchedule”: false,
“valueType”: “EMAIL”,
“orgunitScope”: false,
“confidential”: false,
“unique”: false,
“inherit”: false,
“lastUpdatedBy”: {
“id”: “KHsE5DD09bF”
},
“user”: {
“id”: “KHsE5DD09bF”
},
“description”: “N/A”,
“translations”: [
{
“property”: “NAME”,
“locale”: “es”,
“value”: “Contacto #2 Cargo/Rol”
},
{
“property”: “SHORT_NAME”,
“locale”: “es”,
“value”: “Contacto #2 Cargo/Rol”
},
{
“property”: “NAME”,
“locale”: “fr”,
“value”: “Coordonnées #2 Position”
},
{
“property”: “SHORT_NAME”,
“locale”: “fr”,
“value”: “Coordonnées #2 Position”
}
],
“userGroupAccesses”:[],
“attributeValues”:[],
“userAccesses”:[],
“legendSets”:[]
}
]
}

@stephocay @Knut_Staring @Markus share and use as you find appropriate.

2 Likes

Hi Georgi, appreciate your documenation here; i found this while looking up why I might be having issues with a specific translation push for programStageSections. Your solution above made me realize that I had translated SHORT_NAME and FORM_NAME for these, but not (oddly, I know) NAME. Turns out import/export will let you update the FORM_NAME of a programStageSection, but its the NAME that actually appears on the form. Anyway—Thanks for your documentation!!! Helped me quite a bit.