Allow translations directly in extra file

QoL feature so you don't need to switch files for the small extra sets
Closes #164
This commit is contained in:
DominikDoom
2023-04-21 10:32:52 +02:00
parent d1357cddc1
commit dcc6602056
2 changed files with 15 additions and 11 deletions

View File

@@ -93,6 +93,10 @@ async function loadTags(c) {
if (c.extra.extraFile && c.extra.extraFile !== "None") {
try {
extras = await loadCSV(`${tagBasePath}/${c.extra.extraFile}`);
// Add translations to the main translation map for extra tags that have them
extras.forEach(e => {
if (e[4]) translations.set(e[0], e[4]);
});
} catch (e) {
console.error("Error loading extra file: " + e);
return;
@@ -174,16 +178,16 @@ async function syncOptions() {
newCFG.alias.searchByAlias = true; // if only show translation, enable search by translation is necessary
}
// Reload tags if the tag file changed
if (!CFG || newCFG.tagFile !== CFG.tagFile || newCFG.extra.extraFile !== CFG.extra.extraFile) {
allTags = [];
await loadTags(newCFG);
}
// Reload translations if the translation file changed
if (!CFG || newCFG.translation.translationFile !== CFG.translation.translationFile) {
translations.clear();
await loadTranslations(newCFG);
}
// Reload tags if the tag file changed (after translations so extra tag translations get re-added)
if (!CFG || newCFG.tagFile !== CFG.tagFile || newCFG.extra.extraFile !== CFG.extra.extraFile) {
allTags = [];
await loadTags(newCFG);
}
// Update CSS if maxResults changed
if (CFG && newCFG.maxResults !== CFG.maxResults) {

View File

@@ -1,6 +1,6 @@
masterpiece,5,Quality tag,
best_quality,5,Quality tag,
high_quality,5,Quality tag,
normal_quality,5,Quality tag,
low_quality,5,Quality tag,
worst_quality,5,Quality tag,
masterpiece,5,Quality tag,,
best_quality,5,Quality tag,,
high_quality,5,Quality tag,,
normal_quality,5,Quality tag,,
low_quality,5,Quality tag,,
worst_quality,5,Quality tag,,
1 masterpiece 5 Quality tag
2 best_quality 5 Quality tag
3 high_quality 5 Quality tag
4 normal_quality 5 Quality tag
5 low_quality 5 Quality tag
6 worst_quality 5 Quality tag