HUGE REFACTOR / CLEANUP

if there is a issue it's probably something in here that was changed
This commit is contained in:
2021-09-28 20:19:44 +00:00
parent 51eddfede9
commit d0afdd9855
238 changed files with 3127 additions and 8614 deletions

View File

@@ -1,5 +1,3 @@
/* ZZeslint-disable */
//AyaNova Translation related utilities
export default {
////////////////////////////////
// Update the local cache
@@ -12,32 +10,12 @@ export default {
if (editedTranslation) {
//iterate the keys that are cached and set them from whatever is in editedTranslation for that key
//de-lodash
// window.$gz. _.forOwn(window.$gz.store.state.translationText, function(
// cacheval,
// cachekey
// ) {
// //find match
// //de-lodash
// // let display = window.$gz. _.find(editedTranslation.translationItems, {
// // key: cachekey
// // }).display;
// let display = editedTranslation.translationItems.find(
// z => z.key == cachekey
// ).display;
// window.$gz.store.commit("setTranslationText", {
// key: cachekey,
// value: display
// });
// });
for (const [key, value] of Object.entries(
window.$gz.store.state.translationText
)) {
let display = editedTranslation.translationItems.find(z => z.key == key)
.display;
const display = editedTranslation.translationItems.find(
z => z.key == key
).display;
window.$gz.store.commit("setTranslationText", {
key: key,
@@ -46,22 +24,15 @@ export default {
}
} else {
//gather up the keys that are cached and fetch the latest and then replace them
let needIt = [];
//de-lodash
// window.$gz. _.forOwn(window.$gz.store.state.translationText, function(
// cacheval,
// cachekey
// ) {
// needIt.push(cachekey);
// });
const needIt = [];
Object.keys(window.$gz.store.state.translationText).forEach(z => {
needIt.push(z);
});
//fetch these keys
let transData = await window.$gz.api.upsert("translation/subset", needIt);
const transData = await window.$gz.api.upsert(
"translation/subset",
needIt
);
transData.data.forEach(function commitFetchedTranslationItemToStore(
item
) {
@@ -89,7 +60,7 @@ export default {
//step 1: build an array of keys that we don't have already
//Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen
//for example datatables have dynamic column names so they need to fetch on demand
let needIt = [];
const needIt = [];
for (let i = 0; i < keys.length; i++) {
if (
!window.$gz.util.has(window.$gz.store.state.translationText, keys[i])
@@ -323,21 +294,19 @@ export default {
// (fetch and cache any missing strings)
async translateStringWithMultipleKeysAsync(s) {
let ret = s;
let found = s.match(/LT:[\w]*/gm);
const found = s.match(/LT:[\w]*/gm);
if (found == null) {
return ret;
}
//clean up the keys for fetching
let keysToCache = found.map(z => z.replace("LT:", ""));
const keysToCache = found.map(z => z.replace("LT:", ""));
//cache / fetch any that are not already present
//(async () => {
await this.cacheTranslations(keysToCache);
// })();
//replace
found.forEach(z => {
let translated = this.get(z.replace("LT:", ""));
const translated = this.get(z.replace("LT:", ""));
//replace all
ret = ret.split(z).join(translated);
});
@@ -352,13 +321,13 @@ export default {
//this is the sync version to be used in non async capable code
translateStringWithMultipleKeys(s) {
let ret = s;
let found = s.match(/LT:[\w]*/gm);
const found = s.match(/LT:[\w]*/gm);
if (found == null) {
return ret;
}
//replace
found.forEach(z => {
let translated = this.get(z.replace("LT:", ""));
const translated = this.get(z.replace("LT:", ""));
//replace all
ret = ret.split(z).join(translated);
});