Skip to content
Tobia Di Pisa edited this page Dec 20, 2016 · 26 revisions

The ckanext-multilang CKAN's extension provides a way to localize your CKAN's title and description contents for: Dataset, Resources, Organizations, Groups and Tags. This extension creates some new DB tables for this purpose containing localized contents in base of the configured CKAN's locales in configuration (the production.ini file). So, accessing the CKAN's GUI in 'en', for example, the user can create a new Dataset and automatically new localized records for that language will be created in the multilang tables. In the same way, changing the GUI's language, from the CKAN's language dropdown, the user will be able to edit again the same Dataset in order to specify 'title' and 'description' of the Dataset for the new selected language. In this way Dataset's title and description will automatically changed simply switching the language from the CKAN's dropdonw.

The ckanext-multilang provides also an harvester built on top of the ckanext-spatial extension, and inherits all of its functionalities.

Features

Some extra functionalities are added, such as:

  • Title and Description of: Dataset, Resources, Tags, Organizations and Group can be localized simply editing or creating a new of these elements from the CKAN's Admin GUI.
  • The ckanext-multilang provides also an harvester built on the ckanext-spatial extension, and inherits all of its functionalities. With this harvester, localized content for Dataset in CKAN can be retrieved form metadata that contains the gmd:PT_FreeText XML element.

For example the XML fragment below:

        <gmd:PT_FreeText>
          <gmd:textGroup>
            <gmd:LocalisedCharacterString locale="#GER">Autonome Provinz Bozen</gmd:LocalisedCharacterString>
          </gmd:textGroup>
        </gmd:PT_FreeText>

provides a localized text for the GERMAN locale. The 'locale' xml attribute must respect the following sintax: {# + 'locale string'}.

A mapping between CKAN and the harvested locales must be provided from the harvest configuration in order to respect CKAN's strings locales.

Configuration

Provide to the harvester the harvesting URL, which will be the same as the CSW endpoint: e.g.:

http://yourdomainname/yourservice/csw

Below a sample configuration to use for the multilanguage purpose:

{
	"ckan_locales_mapping":{
		"ita": "it",
		"eng": "en"
	},
    "organisation_mapping": [
            {"key": "pab-foreste" ,"value": "Ufficio 32.3 - Ufficio Pianificazione forestale"}
    ]
}
  • ckan_locales_mapping: defines the mapping between metadata locale (value of the locale XML attribute) and the related locale in CKAN.

  • organisation_mapping: when you want to harvest by an organization, defines the mapping between the existing organization in CKAN (the 'key' defines the name of the organization) and the metadata 'organizationName' (with role 'owner')

  • More available configuration properties can be found in the ckanext-geonetwork WIKI

Usage of the multilang extension

The harvest functionalities explained in the 'Features' section automatically localize records inside the CKAN's database for Dataset's title and abstract only if the gmd:PT_FreeText is available for metadata with the gmd:LocalisedCharacterString element properly configured. So, at the end of an harvest procedure, the user can see the localized dataset title and abstract simply switching language from the CKAN language selector dropdown.

Then for existing or new added Datasets, Organizations, Resources or Groups, the user can set the localized text, for title and abstract, directly editing the related edit GUI section. In this case the language selected from the canonical language selector dropdown, determines which language will be stored into the multilang DB tables.

This means that multilang functionalities will be available only for configured locales in CKAN configuration (ckan.locales_offered in your production.ini file).

Develop with the Multilang extension

Dataset Harvesting

A proper harvester built on the ckanext-spatial extension provides a way to harvest localized contents parsing the 'gmd:PT_FreeTex' metadata element.

The Harvester class definition is at the following path:

ckanext-multilang/ckanext/multilang/harvesters/multilang.py

Main topics are:

ISOTextGroup : The harvester define an 'ISOTextGroup' DOM element with the aim to parse the 'gmd:PT_FreeTex' child elements and to allow the possibility to easly retrieve localized contents from metadata.

get_package_dict : This mothod overrides the std method of the superclass (CSWHarvester) defining an internal dict with localized contents.

after_import_stage : This method is invoked at the end of a dataset import stage. For each package persisted by CKAN a new record will be persisted in the 'package_multilang' table defined in the multilang model.

Solr Indexing

A 'before_index' defined for the plugin class allows the extension to automatically generate Solr indexes during the harvest operation or each time a Solr reindex is launched from command line.

Model

The ckanext-multilang model is composed by four new table created durign the first installation of the extension:

  • package_multilang : For each package stored in CKAN (the package table) we have two records for each language configured that contains the translated text (one for title and one for the package's abstract).

  • group_multilang : For each group/organization stored in CKAN (the group table) we have two records for each language configured that contains the translated text (one for title and one for the abstract). The group_multilang table will be populated each time the user creates or updates a group/organization from the Admin GUI.

  • resource_multilang : For each dataset's resource stored in CKAN (the resource table) we have two records for each language configured that contains the translated text (one for title and one for the abstract). The resource_multilang table will be populated each time the user creates or updates a resource from the Admin GUI.

  • tag_multilang : For each dataset's tag stored in CKAN we have corresponding records for each language that contains the translated text of the tag. This localized text can be specified in the Dataset edit form or created during the harvest procedure.

Controllers

The ckanext-multilang extension implements the IPackageController to manage the most part of the hooks methods and then manage also the localized information.

Some other behaviors are currently managed by overriding the CKAN's package controller. Only the needed methods of this controllers are been overridden by the ckanext-multilang extension, with the aim to dynamically manage dicts returned to the templates and then show localized contents into the CKAN's GUI.