Skip to content

Commit

Permalink
use existing and custom css to color some tags (#91)
Browse files Browse the repository at this point in the history
* mvp

* mvp

* use existing name and archaism colors

* update tests
  • Loading branch information
StefanVukovic99 authored Jun 28, 2024
1 parent 6912c84 commit e522777
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!tag_bank_ipa.json
!parts_of_speech.json
!multiword_inflections.json
!tag_styles.json
!tag_order.json
!languages.json
!package*.json
Expand All @@ -13,6 +14,7 @@
!data/test/ipa/**/*.json

*.zip
data/**/*.css

*.txt
!instructions.txt
Expand Down
26 changes: 26 additions & 0 deletions 4-make-yomitan.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const ipaTags = [...targetLanguageIpaTags, ...languageIpaTags];
const partsOfSpeech = loadJsonArray(`data/language/target-language-tags/${target_iso}/parts_of_speech.json`);

const multiwordInflections = loadJsonArray(`data/language/${source_iso}/${target_iso}/multiword_inflections.json`);
const tagStylesFile = `data/language/target-language-tags/${target_iso}/tag_styles.json`;
const tagStyles = existsSync(tagStylesFile) ? JSON.parse(readFileSync(tagStylesFile)) : {};

const tagModifiers = [
['chiefly', 'chief'],
Expand Down Expand Up @@ -263,9 +265,18 @@ let lastTermBankIndex = 0;

writeIndex('dict');
writeTags('dict');
const dictTagStyles = getTagStyles('dict');
if(dictTagStyles){
writeStyles('dict', dictTagStyles);
}
lastTermBankIndex = writeBanks('dict', ymtLemmas, lastTermBankIndex);
writeIndex('ipa');
writeTags('ipa');
const ipaTagStyles = getTagStyles('ipa');
if(ipaTagStyles){
writeStyles('ipa', ipaTagStyles);
}

writeBanks('ipa', ymtIpa);
}

Expand Down Expand Up @@ -427,6 +438,21 @@ function writeTags(folder) {
writeFileSync(`${writeFolder}/${folder}/tag_bank_1.json`, JSON.stringify(Object.values(ymtTags[folder])));
}

function writeStyles(folder, tagStyles){
writeFileSync(`${writeFolder}/${folder}/styles.css`, tagStyles);
}

function getTagStyles(folder){
let styles = "";
for (const fullTag of Object.values(ymtTags[folder])) {
const tag = fullTag[0];
if (tagStyles[tag]) {
styles += tagStyles[tag] + '\n';
}
}
return styles;
}

function writeIndex(folder) {
writeFileSync(`${writeFolder}/${folder}/index.json`, JSON.stringify({
...indexJson,
Expand Down
6 changes: 4 additions & 2 deletions auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ for target_lang in "${languages[@]}"; do
fi

export temp_folder="data/temp"
temp_dict_folder="$temp_folder/dict"
temp_ipa_folder="$temp_folder/ipa"
dict_file="${DICT_NAME}-$source_iso-$target_iso.zip"
ipa_file="${DICT_NAME}-$source_iso-$target_iso-ipa.zip"

Expand All @@ -163,8 +165,8 @@ for target_lang in "${languages[@]}"; do
echo "Creating Yomitan dict and IPA files"
if node --max-old-space-size="$max_memory_mb" 4-make-yomitan.js; then
echo "Zipping Yomitan files"
zip -qj "$dict_file" $temp_folder/dict/index.json $temp_folder/dict/tag_bank_1.json $temp_folder/dict/term_bank_*.json
zip -qj "$ipa_file" $temp_folder/ipa/index.json $temp_folder/ipa/tag_bank_1.json $temp_folder/ipa/term_meta_bank_*.json
zip -qj "$dict_file" $temp_dict_folder/index.json $temp_dict_folder/styles.css $temp_dict_folder/tag_bank_1.json $temp_dict_folder/term_bank_*.json
zip -qj "$ipa_file" $temp_ipa_folder/index.json $temp_ipa_folder/tag_bank_1.json $temp_ipa_folder/term_meta_bank_*.json
else
echo "Error: Yomitan generation script failed."
fi
Expand Down
8 changes: 4 additions & 4 deletions data/language/target-language-tags/en/tag_bank_term.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
],
[
"name",
"partOfSpeech",
"name",
-1,
"name",
1
Expand Down Expand Up @@ -491,7 +491,7 @@
],
[
"arch",
"",
"archaism",
4,
"archaic",
-4
Expand Down Expand Up @@ -561,14 +561,14 @@
],
[
"dated",
"",
"archaism",
0,
"dated",
0
],
[
"obs",
"",
"archaism",
0,
"obsolete",
0
Expand Down
5 changes: 5 additions & 0 deletions data/language/target-language-tags/en/tag_styles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"masc": ".tag[data-details='masculine'] .tag-label{background-color: blue;}",
"fem": ".tag[data-details='feminine'] .tag-label{background-color: red;}",
"neut": ".tag[data-details='neuter'] .tag-label{background-color: green;}"
}
4 changes: 2 additions & 2 deletions data/test/dict/de/en/tag_bank_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
],
[
"arch",
"",
"archaism",
4,
"archaic",
-4
],
[
"obs",
"",
"archaism",
0,
"obsolete",
0
Expand Down

0 comments on commit e522777

Please sign in to comment.