Skip to content

Commit

Permalink
added etymology field to translation schema, specified required/optio…
Browse files Browse the repository at this point in the history
…nal properties for words
  • Loading branch information
TheOnlyTails committed Nov 30, 2023
1 parent 4f79757 commit 7e0df00
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 26 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/validate_toml.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
from glob import iglob
import tomllib
from jsonschema import validate
from jsonschema import validate, Draft7Validator, ValidationError
import json
import sys

sys.tracebacklimit = 0

if __name__ == "__main__":
for path in iglob("../../**/*.toml", recursive=True):
with open(path, 'rb') as file:
try:
print(f"Checking {file.name}...")
data = tomllib.load(file)

if "translations" in path:
with open("../../schemas/translation.schema.json") as schema:
print(f"Checking translation schema for {file.name}...")
validate(data, json.load(schema))
except tomllib.TOMLDecodeError as e:
print(e)
for path in iglob("../../**/*.toml", recursive=True):
with open(path, "rb") as file:
try:
print(f"Checking {file.name}...")
data = tomllib.load(file)

if "translations" in path:
with open("../../schemas/translation.schema.json") as schema:
print(f"Checking translation schema for {file.name}...")
validate(
instance=data,
schema=json.load(schema),
format_checker=Draft7Validator.FORMAT_CHECKER,
)
except tomllib.TOMLDecodeError as e:
print(e)
58 changes: 45 additions & 13 deletions schemas/translation.schema.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://linku.la/sona/schemas/translation.schema.json",
"title": "sona Translation file",
"description": "Localized metadata for a Toki Pona word",
"type": "object",
"properties": {
"def": {
"description": "The definition of the word",
"type": "string"
"additionalProperties": {
"properties": {
"commentary": {
"description": "Extra information regarding the word",
"type": "string"
},
"def": {
"description": "The definition of the word",
"type": "string"
},
"etymology": {
"description": "Information about the word's origin through other languages",
"items": {
"properties": {
"alt": {
"description": "The \"word\" field transliterated in Latin characters",
"type": "string"
},
"definition": {
"description": "The definition of the word in its origin language",
"type": "string"
},
"language": {
"description": "The word's origin language",
"type": "string"
},
"word": {
"description": "The word written out in its original script",
"type": "string"
}
},
"type": "object",
"required": ["language"],
"additionalProperties": false
},
"type": "array"
},
"sitelen_pona_etymology": {
"description": "The etymology of the word's sitelen pona glyph",
"type": "string"
}
},
"commentary": {
"description": "Extra information regarding the word",
"type": "string"
},
"sitelen_pona_etymology": {
"description": "The etymology of the word's sitelen pona glyph",
"type": "string"
}
"type": "object",
"required": ["def"],
"additionalProperties": false
}
}
13 changes: 13 additions & 0 deletions schemas/translation.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type Translation = {
[word: string]: {
def: string;
commentary: string;
sitelen_pona_etymology: string;
etymology: Array<{
language: string;
word: string;
alt: string;
definition: string;
}>;
};
};

0 comments on commit 7e0df00

Please sign in to comment.