Skip to main content

Multilingual support for OARepo

Project description

OARepo multilingual data model

image image image image

Multilingual string data model for OARepo.

Instalation

    pip install oarepo-multilingual

Usage

The library provides multilingual type for json schema with marshmallow validation and deserialization and elastic search mapping. Multilingual is type which allows you to add multilingual strings in your json schema in format "en":"something, "en-us":"something else".

JSON Schema

Add this package to your dependencies and use it via $ref in json schema as "[server]/schemas/multilingual-v2.0.0.json#/definitions/multilingual".

Usage example

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "title": {
            "$ref": "https://localhost:5000/schemas/multilingual-v2.0.0.json#/definitions/multilingual"
      }
  }
}
{
  "type": "object",
  "properties": {
    "title": {
            "en": "something",
            "en-us": "something else"
      }
  }
}

Marshmallow

For data validation and deserialization.

If marshmallow validation is performed within application context, languages are validated against SUPPORTED_LANGUAGES config. If the validation is performed outside app context, the keys are not checked against a list of languages but a generic validation is performed - keys must be in ISO 639-1 or language-region format from RFC 5646.

Usage example

    class MD(marshmallow.Schema):
         title = MultilingualStringSchemaV2()

    data = {
        'title':
            {
            "en": "something",
            "en-us": "something else",
            }
        }

    MD().load(data)

Supported languages validation

You can specified supported languages in your application configuration in SUPPORTED_LANGUAGES . Then only these languages are allowed as multilingual string. You must specified your languages in format "en" or "en-us".

Usage example

app.config.update(SUPPORTED_LANGUAGES = ["cs", "en"])

Elastic search mapping

Defince type of your multilingual string as multilingual

Usage example

{
  "mappings": {
    "properties": {
    "title":
      {"type": "multilingual"}
    }
  }
}

Changes

Version 2.0.0 (released 2020-08-21)

  • Initial public release.

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_multilingual-2.0.1a1.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file oarepo_multilingual-2.0.1a1.tar.gz.

File metadata

  • Download URL: oarepo_multilingual-2.0.1a1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.18rc1

File hashes

Hashes for oarepo_multilingual-2.0.1a1.tar.gz
Algorithm Hash digest
SHA256 d6622ad1a65b80394fa19100200ad2000e89d98ed15b7071e630baec2d310435
MD5 9d9054462dd87ba93dc4454490cecea4
BLAKE2b-256 9c3a5254a9cf6013bc10cdd1cdedb018ca6b065956a443a43ef0b98851037c41

See more details on using hashes here.

Supported by

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