Move deinflection reasons setup to backend (#880)
* Move deinflection reasons setup to backend * Remove async
This commit is contained in:
parent
2bd82353e4
commit
7e31dcca39
@ -186,7 +186,9 @@ class Backend {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
}
|
}
|
||||||
await this._translator.prepare();
|
|
||||||
|
const deinflectionReasions = await this._fetchAsset('/bg/lang/deinflect.json', true);
|
||||||
|
this._translator.prepare(deinflectionReasions);
|
||||||
|
|
||||||
await this._optionsUtil.prepare();
|
await this._optionsUtil.prepare();
|
||||||
this._defaultAnkiFieldTemplates = (await this._fetchAsset('/bg/data/default-anki-field-templates.handlebars')).trim();
|
this._defaultAnkiFieldTemplates = (await this._fetchAsset('/bg/data/default-anki-field-templates.handlebars')).trim();
|
||||||
|
@ -38,11 +38,11 @@ class Translator {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the instance for use. The public API should not be used until
|
* Initializes the instance for use. The public API should not be used until
|
||||||
* this function has been called and await'd.
|
* this function has been called.
|
||||||
|
* @param deinflectionReasons The raw deinflections reasons data that the Deinflector uses.
|
||||||
*/
|
*/
|
||||||
async prepare() {
|
prepare(deinflectionReasons) {
|
||||||
const reasons = await this._fetchJsonAsset('/bg/lang/deinflect.json');
|
this._deinflector = new Deinflector(deinflectionReasons);
|
||||||
this._deinflector = new Deinflector(reasons);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -747,21 +747,6 @@ class Translator {
|
|||||||
return newText;
|
return newText;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _fetchJsonAsset(url) {
|
|
||||||
const response = await fetch(chrome.runtime.getURL(url), {
|
|
||||||
method: 'GET',
|
|
||||||
mode: 'no-cors',
|
|
||||||
cache: 'default',
|
|
||||||
credentials: 'omit',
|
|
||||||
redirect: 'follow',
|
|
||||||
referrerPolicy: 'no-referrer'
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch ${url}: ${response.status}`);
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
_getSecondarySearchDictionaryMap(enabledDictionaryMap) {
|
_getSecondarySearchDictionaryMap(enabledDictionaryMap) {
|
||||||
const secondarySearchDictionaryMap = new Map();
|
const secondarySearchDictionaryMap = new Map();
|
||||||
for (const [title, dictionary] of enabledDictionaryMap.entries()) {
|
for (const [title, dictionary] of enabledDictionaryMap.entries()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user