Skip to main content

No project description provided

Project description

OARepo Model Builder Multilingual

plugin for the oarepo-model-builder module that adds support for multilingual data types

Usage

Within this plugin, two data types are added: multilingual and i18nstr. They can be added to the data model using type: multilingual or type: i18nstr. Values containing language tags must be in IETF format. The structure of both data types can be changed using the multilingual field

i18nStr

An object that contains the language of the item and the actual value of the item.

Example

Model

"abstract": {"type": "i18nStr"}

Generated JsonSchema

 "abstract": {
    "type": "object",
    "properties": {
        "lang": {
        "type": "string"
        },
        "value": {
        "type": "string"
        }
    }
  }

Multilingual

Array of i18nStr objects.

Example

Model

"abstract": {"type": "multilingual"}

Generated Schema

 "abstract": {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "lang": {
            "type": "string"
            },
            "value": {
            "type": "string"
            }
        }
    }
}

Usage of i18nStr within another object

i18nstr can be added to another object using "use": "i18n".

Example

Supported languages:

Supported languages are defined in the object in the structure: "supported language tag": {object containing additional information} within the field supported-langs in model settings. Supported languages definition is used to specify the languages to be indexed in elasticsearch and opensearch, respectively. All supplied data for the supported language will be inserted into the mapping definition.

Example

Model
"model": {"properties": {"a": {"type": "multilingual"}}
          "settings": {"supported-langs": {
            "cs": {
                "text": {
                    "analyzer": "czech",
                },
                "sort": {
                    "type": "icu_collation_keyword"
                },
                "keyword": {
                    "test": "test"
                }
            },
            "en": {
                "text": {
                    "analyzer": "en"
                },
                "sort": {
                    "type": "icu_collation_keyword"
                }
            }}}}
Generated Schema
"mappings": {
        "properties": {
            "a": {
                "type": "object",
                "properties": {
                    "lang": {
                        "type": "keyword"
                    },
                    "value": {
                        "type": "text"
                    }
                }
            },
            "a_cs": {
                "type": "text",
                "analyzer": "czech",
                "sort": {
                    "type": "icu_collation_keyword",
                    "index": false,
                    "language": "cs"
                },
                "fields": {
                    "keyword": {
                        "test": "test",
                        "type": "keyword"
                    }
                }
            },
            "a_en": {
                "type": "text",
                "analyzer": "en",
                "sort": {
                    "type": "icu_collation_keyword",
                    "index": false,
                    "language": "en"
                },
                "fields": {
                    "keyword": {
                        "type": "keyword"
                    }
                }
            }
}

The change of the name of a language or value field

The name of the field for the language value and the name of the field for the value of the item itself can be changed using the multilingual field and the value-field and lang-field fields. It is not required to rename both fields.

Example:

Model
"b":{"type": "i18nStr", "multilingual":{"lang-field": "language", "value-field": "val"}}
Generated Schema
class BSchema(ma.Schema, ):
    """BSchema schema."""
    
    language = ma_fields.String()
    
    val = ma_fields.String()
    
class TestSchema(ma.Schema, ):
    """TestSchema schema."""
    
    b = ma_fields.Nested(lambda: BSchema())

Indexing another data type using supported languages

If supported languages are defined, indexing for these languages can be added to data types other than multilingual and i18nStr. For this purpose you need to add to the field: 'multilingual': {'i18n': True}

Example:

Model:
"model": {"properties": {"a": {"type": "fulltext", "multilingual": {"i18n": true}}}
        "settings": {"supported-langs": {"cs": {}, "en": {}}}}
Schema:
{"mappings":
{"properties":{
  "a":{"type":"text"},
  "a_cs":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":50}}},
  "a_en":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":50}}}}}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oarepo-model-builder-multilingual-2.0.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file oarepo-model-builder-multilingual-2.0.2.tar.gz.

File metadata

File hashes

Hashes for oarepo-model-builder-multilingual-2.0.2.tar.gz
Algorithm Hash digest
SHA256 29cea1ea12824c9e7b29c867b83c55e8b16bad4e2fce7020d78559132e65fce9
MD5 2e2b1f1b395309f6f8a2133df63fe611
BLAKE2b-256 2a44077141339972ba79155c82f6f3c19a9a8d8d9038e72b307d08e39a74373e

See more details on using hashes here.

File details

Details for the file oarepo_model_builder_multilingual-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for oarepo_model_builder_multilingual-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2207f7b18e8a6ca6c48a00329e1a6d7b619c4b97f4fa5461080af0873acfb1a
MD5 81445cb6ad970a78e3b2207fea138e3e
BLAKE2b-256 c0822e2d398d41da199ba2342ebc8ca115a78d8c1af89dae7474efebd5801034

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page