-
Notifications
You must be signed in to change notification settings - Fork 3
Multilingual CKAN
Some background info on how CKAN portals like opendata.swiss are set up for multilingual support here. See also the wiki page on Language support in the ckan-embed plugin and issue #9.
The following explanation from @metaodi about how opendata.swiss is set up:
As always for multilingual setups, there are two things to distinguish:
-
Multilingual frontend (i.e. have all the static text/labels in multiple languages and the user chooses their favourite display language).
-
Multilingual backend (i.e. being able to enter content in multiple languages and display this content based on the user-selected language)
For 1. We use the classic (in Python) pot/po file approach to extract all the strings and translate them. CKAN has a ITranslation interface to make the integration with the CKAN translations seamless (see itranslation interface). The source for opendata.swiss is here.
For 2. We had to get a little creative. Since we used WordPress as the GUI for the backend we didn't have to worry about that aspect. But we had to make sure that we can save and read multilingual data in CKAN.
We used the ckanext-scheming and ckanext-fluent extensions to create a custom schema. When you define a schema you can define input and output validators, those are used to transform a value before it's written to the database (input) or after it's read from the database before it's displayed (output). All multilingual fields are stored as JSON with language-specific keys
{"de": "....", "fr": "..." ...}
That's basically it. If we write to CKAN we serialize the dict to JSON and if we read we do it vice-versa and transfirm the JSON string back to a dict. And that's how you can access the data with the CKAN API. With our approach we stayed close to the CKAN standard way of defining your own schema.