Multilingual support for OARepo
Project description
OARepo multilingual data model
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for oarepo_multilingual-2.0.1a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dfd312418c8f0c2deb028c7d8c0464dccf1ae8261cf4cb7bfcd64ed88c666a9 |
|
MD5 | e1402b43c877aea0c53bac6849a2051f |
|
BLAKE2b-256 | 59255a6dc1c2eb271a295c3556155f700406730385a186d2efd41b38a7fef887 |
Hashes for oarepo_multilingual-2.0.1a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69dde35dac262ef7a2ddfc1951ff0f6df0f3c3c5d9080d2c160bd7a1a89a7985 |
|
MD5 | 2717f3c4cff6e7a297d87aca631fa50d |
|
BLAKE2b-256 | d3487621ae8c49cfa2a52b9a9e39001d69f33798dcf9fb62e7478f8dba6b3a32 |