Skip to content

Commit

Permalink
Alias for pronunciation dict
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Jul 30, 2024
1 parent 550ab45 commit 9cb30eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ext/js/dictionary/dictionary-data-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,21 @@ export function getGroupedPronunciations(dictionaryEntry) {

const allTerms = new Set();
const allReadings = new Set();
const aliasMap = new Map();
for (const {term, reading} of headwords) {
allTerms.add(term);
allReadings.add(reading);
}

/** @type {Map<string, import('dictionary-data-util').GroupedPronunciationInternal[]>} */
const groupedPronunciationsMap = new Map();
for (const {headwordIndex, dictionary, pronunciations} of termPronunciations) {
for (const {headwordIndex, dictionary, dictionaryAlias, pronunciations} of termPronunciations) {
const {term, reading} = headwords[headwordIndex];
let dictionaryGroupedPronunciationList = groupedPronunciationsMap.get(dictionary);
if (typeof dictionaryGroupedPronunciationList === 'undefined') {
dictionaryGroupedPronunciationList = [];
groupedPronunciationsMap.set(dictionary, dictionaryGroupedPronunciationList);
aliasMap.set(dictionary, dictionaryAlias);
}
for (const pronunciation of pronunciations) {
let groupedPronunciation = findExistingGroupedPronunciation(reading, pronunciation, dictionaryGroupedPronunciationList);
Expand All @@ -181,6 +183,7 @@ export function getGroupedPronunciations(dictionaryEntry) {
for (const [dictionary, dictionaryGroupedPronunciationList] of groupedPronunciationsMap.entries()) {
/** @type {import('dictionary-data-util').GroupedPronunciation[]} */
const pronunciations2 = [];
const dictionaryAlias = aliasMap.get(dictionary) ?? dictionary;

Check failure on line 186 in ext/js/dictionary/dictionary-data-util.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Unsafe assignment of an `any` value
for (const groupedPronunciation of dictionaryGroupedPronunciationList) {
const {pronunciation, terms, reading} = groupedPronunciation;
const exclusiveTerms = !areSetsEqual(terms, allTerms) ? getSetIntersection(terms, allTerms) : [];
Expand All @@ -197,7 +200,7 @@ export function getGroupedPronunciations(dictionaryEntry) {
});
}

results2.push({dictionary, pronunciations: pronunciations2});
results2.push({dictionary, dictionaryAlias, pronunciations: pronunciations2});

Check failure on line 203 in ext/js/dictionary/dictionary-data-util.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Unsafe assignment of an `any` value
}
return results2;
}
Expand Down
5 changes: 3 additions & 2 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,15 @@ export class DisplayGenerator {
* @returns {HTMLElement}
*/
_createGroupedPronunciation(details) {
const {dictionary, pronunciations} = details;
const {dictionary, dictionaryAlias, pronunciations} = details;

const node = this._instantiate('pronunciation-group');
node.dataset.dictionary = dictionary;
node.dataset.pronunciationsMulti = 'true';
node.dataset.pronunciationsCount = `${pronunciations.length}`;

const n1 = this._querySelector(node, '.pronunciation-group-tag-list');
const tag = this._createTag(this._createTagData(dictionary, 'pronunciation-dictionary'));
const tag = this._createTag(this._createTagData(dictionaryAlias, 'pronunciation-dictionary'));
n1.appendChild(tag);

let hasTags = false;
Expand All @@ -686,6 +686,7 @@ export class DisplayGenerator {
n.dataset.hasTags = `${hasTags}`;
this._appendMultiple(n, this._createPronunciation.bind(this), pronunciations);

tag.dataset.details = dictionary;
return node;
}

Expand Down
1 change: 1 addition & 0 deletions types/ext/dictionary-data-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type GroupedPronunciation = {

export type DictionaryGroupedPronunciations = {
dictionary: string;
dictionaryAlias: string;
pronunciations: GroupedPronunciation[];
};

Expand Down

0 comments on commit 9cb30eb

Please sign in to comment.