Skip to content

Commit

Permalink
fix missing translations in non-english edition (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 authored Nov 23, 2024
1 parent b8f560d commit 7779142
Show file tree
Hide file tree
Showing 26 changed files with 430 additions and 122 deletions.
39 changes: 34 additions & 5 deletions 3-tidy-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,33 @@ function handleLine(parsedLine) {

}

/**
* @param {Example} example
* @returns {StandardizedExample}
* */
function standardizeExample(example) {
return {
text: example.text ? example.text.trim() : '',
translation: getTranslationFromExample(example),
};
}

/**
* @param {Example} example
* @returns {string}
* */
function getTranslationFromExample(example) {
if(example.translation) {
return example.translation;
}
switch(targetIso) {
case 'en':
return example.english || example.roman || '';
default:
return '';
}
}

/**
* @param {TidySense[]} sensesWithoutInflectionGlosses
* @returns {GlossTree}
Expand All @@ -215,14 +242,16 @@ function getGlossTree(sensesWithoutInflectionGlosses) {
let { examples = [] } = sense;

examples = examples
.filter(({text, english}) => text && (text.length <= 70 || text.length <= 90 && !english)) // Filter out verbose examples
.filter(example => example.text)
.map(example => standardizeExample(example))
.filter(({text, translation}) => text.length <= 70 || text.length <= 90 && !translation) // Filter out verbose examples
.map((example, index) => ({ ...example, originalIndex: index })) // Step 1: Decorate with original index
.sort(({ english: englishA, originalIndex: indexA }, { english: englishB, originalIndex: indexB }) => {
if (englishA && !englishB) return -1; // English items first
if (!englishA && englishB) return 1; // Non-English items last
.sort(({ translation: translationA, originalIndex: indexA }, { translation: translationB, originalIndex: indexB }) => {
if (translationA && !translationB) return -1; // translation items first
if (!translationA && translationB) return 1; // Non-translation items last
return indexA - indexB; // Step 2: Stable sort by original index if equal
})
.map(({text, english}) => ({text, english})) // Step 3: Pick only properties that will be used
.map(({text, translation}) => ({text, translation})) // Step 3: Pick only properties that will be used
.slice(0, 2);

/** @type {GlossTree|GlossBranch} */
Expand Down
6 changes: 3 additions & 3 deletions 4-make-yomitan.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ function findModifiedTag(tag){
}

/**
* @param {Example[]} examples
* @param {StandardizedExample[]} examples
* @returns {import('types').TermBank.StructuredContent[]}
*/
function getStructuredExamples(examples) {
return examples.map(({text, english}) => {
return examples.map(({text, translation}) => {
return {
"tag": "div",
"data": {
Expand All @@ -138,7 +138,7 @@ function getStructuredExamples(examples) {
"data": {
"content": "example-sentence-b"
},
"content": english
"content": translation
}
]}
}
Expand Down
3 changes: 2 additions & 1 deletion data/test/dict/de/de/term_bank_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down
18 changes: 12 additions & 6 deletions data/test/dict/en/en/term_bank_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -84,7 +85,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -133,7 +135,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -204,7 +207,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -242,7 +246,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -291,7 +296,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down
1 change: 1 addition & 0 deletions data/test/dict/en/es/tag_bank_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
85 changes: 85 additions & 0 deletions data/test/dict/en/es/term_bank_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[
[
"fast",
"",
"",
"adj",
0,
[
{
"type": "structured-content",
"content": [
{
"tag": "div",
"content": [
"Rápido, veloz."
]
}
]
},
{
"type": "structured-content",
"content": [
{
"tag": "div",
"content": [
"Adelantado.",
{
"tag": "div",
"data": {
"content": "extra-info"
},
"content": {
"tag": "div",
"data": {
"content": "example-sentence"
},
"content": [
{
"tag": "div",
"data": {
"content": "example-sentence-a"
},
"content": "Your watch is some minutes fast"
},
{
"tag": "div",
"data": {
"content": "example-sentence-b"
},
"content": "→ Tu reloj va algunos minutos adelantado."
}
]
}
}
]
}
]
},
{
"type": "structured-content",
"content": [
{
"tag": "div",
"content": [
"Firme, fijo, sólido."
]
}
]
},
{
"type": "structured-content",
"content": [
{
"tag": "div",
"content": [
"Cachondo, entregado a los placeres."
]
}
]
}
],
0,
""
]
]
19 changes: 19 additions & 0 deletions data/test/dict/en/es/term_bank_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
[
"faster fastest",
"",
"non-lemma",
"",
0,
[
[
"fast",
[
"comparative"
]
]
],
0,
""
]
]
9 changes: 6 additions & 3 deletions data/test/dict/fr/fr/term_bank_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand All @@ -73,7 +74,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -122,7 +124,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions data/test/dict/ja/en/term_bank_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down Expand Up @@ -579,7 +580,8 @@
"tag": "div",
"data": {
"content": "example-sentence-b"
}
},
"content": ""
}
]
}
Expand Down
1 change: 1 addition & 0 deletions data/test/ipa/en/es/tag_bank_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
19 changes: 19 additions & 0 deletions data/test/ipa/en/es/term_meta_bank_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
[
"fast",
"ipa",
{
"reading": "fast",
"transcriptions": [
{
"ipa": "/fɑːst/",
"tags": []
},
{
"ipa": "/fæst/",
"tags": []
}
]
}
]
]
1 change: 1 addition & 0 deletions data/test/kaikki/en-es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"word": "fast", "pos": "adj", "pos_title": "adjetivo", "lang_code": "en", "lang": "Inglés", "senses": [{"glosses": ["Rápido, veloz."], "sense_index": "1"}, {"glosses": ["Adelantado."], "raw_tags": ["en situaciones relacionadas con el tiempo"], "examples": [{"text": "Your watch is some minutes fast", "translation": "→ Tu reloj va algunos minutos adelantado.", "example_templates": [{"name": "ejemplo", "args": {"1": "Your watch is some minutes fast", "trad": "Tu reloj va algunos minutos adelantado."}, "expansion": ":*Ejemplo:\n::Your watch is some minutes fast→ Tu reloj va algunos minutos adelantado."}]}], "sense_index": "2"}, {"glosses": ["Firme, fijo, sólido."], "sense_index": "3"}, {"glosses": ["Cachondo, entregado a los placeres."], "sense_index": "4"}], "categories": ["EN:Adjetivos", "Inglés"], "sounds": [{"ipa": "/fɑːst/", "raw_tags": ["Australia"]}, {"ipa": "/fæst/", "audio": "en-us-fast.ogg", "ogg_url": "https://commons.wikimedia.org/wiki/Special:FilePath/en-us-fast.ogg", "mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/e/e5/En-us-fast.ogg/En-us-fast.ogg.mp3", "raw_tags": ["Estados Unidos"]}, {"ipa": "/fɑːst/", "raw_tags": ["Nueva Zelanda"]}, {"ipa": "/fɑːst/", "audio": "en-uk-fast.ogg", "ogg_url": "https://commons.wikimedia.org/wiki/Special:FilePath/en-uk-fast.ogg", "mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/6/6a/En-uk-fast.ogg/En-uk-fast.ogg.mp3", "raw_tags": ["Londres", "Received Pronunciation"]}, {"audio": "LL-Q1860 (eng)-Back ache-fast.wav", "wav_url": "https://commons.wikimedia.org/wiki/Special:FilePath/LL-Q1860 (eng)-Back ache-fast.wav", "ogg_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/4/4c/LL-Q1860_(eng)-Back_ache-fast.wav/LL-Q1860_(eng)-Back_ache-fast.wav.ogg", "mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/4/4c/LL-Q1860_(eng)-Back_ache-fast.wav/LL-Q1860_(eng)-Back_ache-fast.wav.mp3", "raw_tags": ["Londres", "Received Pronunciation"]}, {"ipa": "/fæst/", "raw_tags": ["Reino Unido"]}, {"ipa": "/fɑːst/", "raw_tags": ["Sudáfrica"]}], "etymology_text": "Del inglés medio fast, del inglés antiguo fæst.", "etymology_templates": [{"name": "etimología", "args": {"leng": "en", "1": "enm", "2": "fast"}, "expansion": "Del inglés medio fast"}, {"name": "etim", "args": {"leng": "en", "1": "ang", "2": "fæst"}, "expansion": "del inglés antiguo fæst"}], "forms": [{"form": "fast", "tags": ["positive"]}, {"form": "faster fastest", "tags": ["comparative"]}]}
10 changes: 5 additions & 5 deletions data/test/tidy/cs-en-lemmas.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
[
{
"text": "textová zpráva",
"english": "text message"
"translation": "text message"
},
{
"text": "Chcete nechat zprávu?",
"english": "Would you like to leave a message?"
"translation": "Would you like to leave a message?"
}
]
]
Expand All @@ -55,11 +55,11 @@
[
{
"text": "lékařská zpráva",
"english": "medical report"
"translation": "medical report"
},
{
"text": "podat zprávu",
"english": "to file a report"
"translation": "to file a report"
}
]
]
Expand Down Expand Up @@ -99,7 +99,7 @@
[
{
"text": "Zabili ho pro peníze.",
"english": "They killed him for his money."
"translation": "They killed him for his money."
}
]
]
Expand Down
3 changes: 2 additions & 1 deletion data/test/tidy/de-de-lemmas.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"_examples",
[
{
"text": "Der Rock ist nicht totzukriegen."
"text": "Der Rock ist nicht totzukriegen.",
"translation": ""
}
]
]
Expand Down
Loading

0 comments on commit 7779142

Please sign in to comment.