Skip to content

ckan/ckanext-fluent

Repository files navigation

ckanext-fluent

This extension provides a way to store and return multilingual fields in CKAN datasets, resources, organizations and groups.

The ckanext-scheming extension is required for this extension to work.

Installation

git clone https://github.com/ckan/ckanext-fluent.git
cd ckanext-fluent
python setup.py develop
pip install -r requirements.txt

Add the fluent plugin to your ckan.plugins configuration settings and use ckanext-scheming or a custom form plugin to use the provided validators to store multilingual text in extra fields.

The easiest way to use fluent multilingual text fields is with ckanext-scheming. Add ckanext.fluent:presets.json to your scheming.presets configuration settings:

scheming.presets = ckanext.scheming:presets.json
                   ckanext.fluent:presets.json

An example schema is may be used with the scheming_datasets plugin and this schema setting:

scheming.dataset_schemas=ckanext.fluent:fluent_scheming.yaml

This example schema registers a new fluent-test dataset type. Visit /fluent-test/new on your ckan site to create a new dataset with this schema.

fluent_text fields

A fluent multilingual text field in a scheming schema:

{
  "field_name": "books",
  "preset": "fluent_text",
  "label": {
    "en": "Books",
    "fr": "Livres"
  },
  "form_languages": ["en", "fr"]
}

This new extra field "books" will appear as multiple fields in the dataset form, one for each language specified in form_languages.

Example of fluent_text form snippet

When the dataset is accessed from the API the language values appear and are updated as an object, eg.:

{
  "...": "...",
  "books": {
    "en": "Franklin",
    "fr": "Benjamin"
  },
  "...": "..."
}

fluent_tags fields

Example multilingual tag field:

{
  "field_name": "keywords",
  "label": {
    "en": "Keywords",
    "fr": "Mots-clés",
  },
  "preset": "fluent_tags"
}

Note: this preset is not supported for use on the core tags field.

This new extra field "keywords" will appear as multiple fields in the dataset form, one for each language specified in form_languages.

Example of fluent_tags form snippet

When the dataset is accessed from the API the language values appear and are updated as an object with list values, eg.:

{
  "...": "...",
  "keywords": {
    "en": ["what"],
    "fr": ["quoi"]
  },
  "...": "..."
}

fluent_core_translated fields

Fluent should not be directly used on ckan core fields such as title and notes. To use fluent to translate core fields, you should use a field with the _translated suffix appended to the core field name (e.g. title_translated) and use the fluent_core_translated preset. By doing so, the translated version of the field is stored in the field with the _translated suffix while the core field displays the value for the site's default language.

{
  "field_name": "title_translated",
  "preset": "fluent_core_translated",
  "label": {
    "en": "Franklin",
    "fr": "Benjamin"
  }
}

About

Multilingual fields for CKAN

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
COPYING
Unknown
COPYING.fr

Stars

Watchers

Forks

Packages

No packages published