Skip to content
Tobia Di Pisa edited this page Sep 28, 2015 · 26 revisions

The ckanext-multilang CKAN's extension provides a way to localize your CKAN's title and description contents for: Dataset, Resources, Organizations and Groups. 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 the ckanext-spatial extension, and inherits all of its functionalities. Currently an hooked branch of the stable ckanext-spatial extension is used in order to allow an after import stage functionality (used for the ckanext-multilang persistence):

https://github.com/geosolutions-it/ckanext-spatial/tree/stable_official_after_imp_st

Features

Some extra functionalities are added, such as:

  • Title and Description of: Dataset, Resources, 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

You will have to 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"
	}
}

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 titles and abstracts 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 titles and abstracts, directly editing this in the usual 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_order and 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 by CKAN. A customizzation of the stable ckanext-spatial allows the multilang harvester to override the super's method and perform persistance operations. 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 teh 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 three 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.

Controllers

In order to be able to provide localized contents into the CKAN's GUI, some CKAN's Controllers has been overridden (see the plugin class that define a 'before_map' which allows the controllers override). These controllers are the following:

  • Package Controller
  • Group Controller
  • Organization Controller
  • User Controller

Only the needed methods of these controllers has 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 by retrieving localized stored records form the multilang tables.

Clone this wiki locally