diff --git a/.github/workflows/validate_toml.py b/.github/workflows/validate_toml.py index 13cf79b6c8..2fe3344c82 100644 --- a/.github/workflows/validate_toml.py +++ b/.github/workflows/validate_toml.py @@ -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) \ No newline at end of file + 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) diff --git a/schemas/translation.schema.json b/schemas/translation.schema.json index 6874bc8e32..c36fffcc4a 100644 --- a/schemas/translation.schema.json +++ b/schemas/translation.schema.json @@ -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 } } diff --git a/schemas/translation.schema.ts b/schemas/translation.schema.ts new file mode 100644 index 0000000000..0da95bc3e7 --- /dev/null +++ b/schemas/translation.schema.ts @@ -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; + }>; + }; +};