Cadasta / cadasta-qgis-plugin

[DEPRECATED] QGIS plugin to create, edit, upload and download Cadasta projects
GNU General Public License v3.0
4 stars 7 forks source link

Translated labels and values available in QGIS #263

Open SteadyCadence opened 6 years ago

SteadyCadence commented 6 years ago

The questionnaire supports many languages with the XLS Form's label features.

At the moment, the only data that is being pulled and pushed with the QGIS plugin is the "name" columns, which are forced to be Roman characters.

The QGIS plugin should be able to display the multiple languages (of the fields and values) that are stored in Cadasta.

Example project:

https://platform-staging.cadasta.org/api/v1/organizations/example/projects/example_proj/spatial/?format=json

{
    "count": 1,
    "next": "https://platform-staging.cadasta.org/api/v1/organizations/example/projects/example_proj/spatial/?format=json",
    "previous": null,
    "results": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Polygon",
                    "coordinates": []
                },
                "properties": {
                    "id": "1234",
                    "type": "farm",
                    "attributes": {
                        "type_of_ground": "soil"
                    }
                }
            }
        ]
    }
}

https://platform-staging.cadasta.org/api/v1/organizations/example/projects/example_proj/spatial/?format=json

{
    "id": "09876543",
    "filename": "asdfasdfasdf",
    "title": "Example",
    "id_string": "example",
    "xls_form": "https://s3-us-west-2.amazonaws.com/bucket-name/xls-forms/example.xlsx",
    "version": 2017012121593362,
    "questions": [],
    "question_groups": [
        {
            "id": "1234123412341234",
            "name": "location_attributes",
            "type": "group",
            "questions": [
                {
                    "id": "686868686868",
                    "name": "type_of_ground",
                    "label": {
                        "my": "မြေအမျိုးအစား",
                        "en": "Type of Ground"
                    },
                    "type": "S1",
                    "required": true,
                    "constraint": null,
                    "default": "soil",
                    "hint": null,
                    "relevant": null,
                    "label_xlat": {
                        "my": "မြေအမျိုးအစား",
                        "en": "Type of Ground"
                    },
                    "index": 1,
                    "gps_accuracy": null,
                    "options": [
                        {
                            "id": "uuw9n2zj6drptkk4xvnbf6ua",
                            "name": "soil",
                            "label": {
                                "my": "မြေဆီလွှာ",
                                "en": "Soil"
                            },
                            "index": 1,
                            "label_xlat": {
                                "my": "မြေဆီလွှာ",
                                "en": "Soil"
                            }
                        },
                        {
                            "id": "m59fmkpnh6e32bb5j4fptjts",
                            "name": "sand",
                            "label": {
                                "my": "သဲ",
                                "en": "Sand"
                            },
                            "index": 2,
                            "label_xlat": {
                                "my": "သဲ",
                                "en": "Sand"
                            }
                        },
                        {
                            "id": "mjqurmpru3fq6xc6gars2wmu",
                            "name": "silt",
                            "label": {
                                "my": "နုန်း",
                                "en": "Silt"
                            },
                            "index": 3,
                            "label_xlat": {
                                "my": "နုန်း",
                                "en": "Silt"
                            }
                        },
                        {
                            "id": "iba2gux9uxdndepa4t9zvhdh",
                            "name": "sandstone",
                            "label": {
                                "my": "သဲကျောက်",
                                "en": "Sandstone"
                            },
                            "index": 4,
                            "label_xlat": {
                                "my": "သဲကျောက်",
                                "en": "Sandstone"
                            }
                        },
                        {
                            "id": "zyre39436i69bzsrp5cbjpm8",
                            "name": "other",
                            "label": {
                                "my": "အခြား",
                                "en": "Other"
                            },
                            "index": 5,
                            "label_xlat": {
                                "my": "အခြား",
                                "en": "Other"
                            }
                        }
                    ]
                }
            ],
            "question_groups": [],
            "label_xlat": {},
            "relevant": null,
            "index": 11,
            "label": {}
        },
    ],
    "md5_hash": "asdfasdfasdf"
}

The questionnaire has a location_attributes question group defined, with a single question: type_of_ground. The location record from the spatial/ endpoint contains an attribute where type_of_ground: 'soil'. Currently, we this data would appear in QGIS' data table under a column titled type_of_ground and with a value of 'soil'. This makes it difficult for non-english speakers to understand the data. You can see that translation labels for both the question (type_of_ground) and the question options (in this case, soil) are available in English (en) and Myanmar (my). It should be possible to view this data in its converted form.

alukach commented 6 years ago

Some thoughts and concerns about solutions:

  1. I think it's best to do this on QGIS' side. Translation on the API side sounds nice at first blush, however I'm uncertain if there is any guarantee that labels don't conflict between questions (there may be). This would mean that the JSON response could have an object with repeating keys, which I don't believe is valid JSON.
  2. With whatever solution we come up with, it should be considered that people may want to edit/update their Cadasta data with the QGIS plugin. This means that if a user chose to display their data in my language, then updates that data, if we were to support data entry in the translated language we would need to translate the data back to the system values before sending it to our servers.
  3. It appears that QGIS supports columns having an alias property that is designed to offer a more readable title. It may be useful for us to put the translated labels for questions in this location, allowing us to preserve the system's name value.
  4. I considered that it may be easier to display a column for every attribute in every language. However, this then becomes awkward in the scenario of users editing data, as many columns would represent the same data. It would be difficult to determine which were the source of truth. I recommend staying away from this approach.

I recommend that we allow a user to enter in a preferred language. If data is available in that language, convert it to that language. Else, keep it as system values. We don't really have a select set of "supported languages" per questionnaire, so rendering a list of used languages would require us to iterate through all questions and options and question groups and create a set of used languages. This does not guarantee that we would have translations for every value (afaik). Additionally, we would probably want to translate the language abbreviations to their long-form, translated versions (eg. en -> English).