Skip to content

Commit

Permalink
added utility function to fill empty translations, so e.g. if there i…
Browse files Browse the repository at this point in the history
…s a Czech translation of a gridset, where some of the Czech translations are incorrectly stored as English content language (accessible via console)
  • Loading branch information
klues committed Aug 19, 2024
1 parent 6fda2ab commit 6face46
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/js/service/data/dataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,35 @@ function saveGlobalGridId(globalGridId) {

window.setGlobalGridId = saveGlobalGridId;

/**
* move translation from fallbackLang to lang, if translation of lang is empty
* @param langCode
* @param fallbackLangCode
* @returns {Promise<void>}
*/
async function fillEmptyTranslations(langCode, fallbackLangCode) {
if (langCode?.length !== 2 && fallbackLangCode?.length !== 2) {
console.log('invalid params');
return;
}
let allGrids = await dataService.getGrids(true, false);
let originalJSON = JSON.stringify(allGrids);
for (let grid of allGrids) {
grid.label[langCode] = grid.label[langCode] || grid.label[fallbackLangCode];
for (let element of grid.gridElements) {
element.label[langCode] = element.label[langCode] || element.label[fallbackLangCode];
}
}
if (originalJSON !== JSON.stringify(allGrids)) {
await dataService.saveGrids(allGrids);
console.log('updated all grids!');
} else {
console.log('nothing updated.');
}
}

window.fillEmptyTranslations = fillEmptyTranslations;

$(document).on(constants.EVENT_DB_INITIAL_SYNC_COMPLETE, () => {
dataService.cacheAllImages();
});
Expand Down

0 comments on commit 6face46

Please sign in to comment.