Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add source and target language dictionary metadata #891

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ext/data/schemas/dictionary-index-schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"$id": "dictionaryIndex",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"isoLanguageCode": {
"type": "string",
"description": "ISO language code (ISO 639-1 where possible, ISO 639-3 otherwise).",
"pattern": "^(aa|ab|ae|af|ak|am|an|ar|as|av|ay|az|az|ba|be|bg|bh|bi|bm|bn|bo|br|bs|ca|ce|ch|co|cr|cs|cu|cv|cy|da|de|dv|dz|ee|el|en|eo|es|et|eu|fa|ff|fi|fj|fo|fr|fy|ga|gd|gl|gn|grc|gu|gv|ha|he|hi|ho|hr|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|io|is|it|iu|ja|jv|ka|kg|ki|kj|kk|kl|km|kn|ko|kr|ks|ku|kv|kw|ky|la|lb|lg|li|ln|lo|lt|lu|lv|mg|mh|mi|mk|ml|mn|mr|ms|mt|my|na|nb|nd|ne|ng|nl|nn|no|nr|nv|ny|oc|oj|om|or|os|pa|pi|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sc|sd|se|sg|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sv|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|ty|ug|uk|ur|uz|ve|vi|vo|wa|wo|xh|yi|yo|za|zh|zu)$"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be an enum, but i suppose it's fine either way

}
},
"type": "object",
"description": "Index file containing information about the data contained in the dictionary.",
"required": [
Expand Down Expand Up @@ -47,6 +54,14 @@
"type": "string",
"description": "Attribution information for the dictionary data."
},
"sourceLanguage": {
"$ref": "#/definitions/isoLanguageCode",
"description": "Language of the terms in the dictionary."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iso format or does that not matter?

Copy link
Member Author

@StefanVukovic99 StefanVukovic99 May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered a pattern like ^[a-z]{2,3}(-[A-Z]{2})?$, but I haven't been able to find a perfect one.
Or we could do a simple pattern with all our currently supported languages like en|de|fa|fi..., but that's another thing to tweak every time a new language is added.
Or use this https://gist.github.com/konsorten-michael/094f898c3a2847c642a920f7c6f4f575

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the gist? People can submit issues if something else comes up. If we want to support all languages handlebars i feel it's important to enforce all the same languages use the same string for source language

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll throw the gist in, just wanna note that it contains ISO 639-1 codes, we might need to add to that over time for languages that are only in 639-2 or 3, e.g. we have grc as an option in the dropdown.

},
"targetLanguage": {
"$ref": "#/definitions/isoLanguageCode",
"description": "Main language of the definitions in the dictionary."
jamesmaa marked this conversation as resolved.
Show resolved Hide resolved
},
"frequencyMode": {
"type": "string",
"enum": ["occurrence-based", "rank-based"]
Expand Down
4 changes: 3 additions & 1 deletion ext/js/dictionary/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ export class DictionaryImporter {
counts
};

const {author, url, description, attribution, frequencyMode} = index;
const {author, url, description, attribution, frequencyMode, sourceLanguage, targetLanguage} = index;
if (typeof author === 'string') { summary.author = author; }
if (typeof url === 'string') { summary.url = url; }
if (typeof description === 'string') { summary.description = description; }
if (typeof attribution === 'string') { summary.attribution = attribution; }
if (typeof frequencyMode === 'string') { summary.frequencyMode = frequencyMode; }
if (typeof sourceLanguage === 'string') { summary.sourceLanguage = sourceLanguage; }
if (typeof targetLanguage === 'string') { summary.targetLanguage = targetLanguage; }

return summary;
}
Expand Down
6 changes: 4 additions & 2 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ class DictionaryEntry {
* @returns {boolean}
*/
_setupDetails(detailsTable) {
/** @type {[label: string, key: 'author'|'url'|'description'|'attribution'][]} */
/** @type {[label: string, key: 'author'|'url'|'description'|'attribution'|'sourceLanguage'|'targetLanguage'][]} */
const targets = [
['Author', 'author'],
['URL', 'url'],
['Description', 'description'],
['Attribution', 'attribution']
['Attribution', 'attribution'],
['Source Language', 'sourceLanguage'],
['Target Language', 'targetLanguage']
];

const dictionaryInfo = this._dictionaryInfo;
Expand Down
2 changes: 2 additions & 0 deletions types/ext/dictionary-data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type Index = {
url?: string;
description?: string;
attribution?: string;
sourceLanguage?: string;
targetLanguage?: string;
frequencyMode?: 'occurrence-based' | 'rank-based';
tagMeta?: IndexTagMeta;
};
Expand Down
2 changes: 2 additions & 0 deletions types/ext/dictionary-importer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export type Summary = {
url?: string;
description?: string;
attribution?: string;
sourceLanguage?: string;
targetLanguage?: string;
frequencyMode?: 'occurrence-based' | 'rank-based';
};

Expand Down