357 lines
9.0 KiB
JavaScript
357 lines
9.0 KiB
JavaScript
/* ZZeslint-disable */
|
|
//AyaNova Translation related utilities
|
|
export default {
|
|
////////////////////////////////
|
|
// Update the local cache
|
|
//
|
|
//
|
|
async updateCache(editedTranslation) {
|
|
//This function is only called if there is a requirement to refresh the local cache
|
|
//either they just changed translations and saved it in user settings
|
|
//or they just edited a translation and saved it in translation editor and it's also their own local translation
|
|
|
|
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;
|
|
|
|
window.$gz.store.commit("setTranslationText", {
|
|
key: key,
|
|
value: display
|
|
});
|
|
}
|
|
} 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);
|
|
// });
|
|
|
|
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);
|
|
transData.data.forEach(function commitFetchedTranslationItemToStore(
|
|
item
|
|
) {
|
|
window.$gz.store.commit("setTranslationText", item);
|
|
});
|
|
}
|
|
},
|
|
get(key) {
|
|
if (!key) {
|
|
return "??NO_TRANSLATION_KEY";
|
|
}
|
|
//no translation for Wiki
|
|
if (key == "Wiki") {
|
|
return "Wiki";
|
|
}
|
|
if (!window.$gz.util.has(window.$gz.store.state.translationText, key)) {
|
|
return "??" + key;
|
|
}
|
|
return window.$gz.store.state.translationText[key];
|
|
},
|
|
async cacheTranslations(keys, forceTranslationId) {
|
|
return new Promise(async function fetchTranslationKeysFromServer(resolve) {
|
|
//
|
|
//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 = [];
|
|
for (let i = 0; i < keys.length; i++) {
|
|
if (
|
|
!window.$gz.util.has(window.$gz.store.state.translationText, keys[i])
|
|
) {
|
|
needIt.push(keys[i]);
|
|
}
|
|
}
|
|
|
|
if (needIt.length == 0) {
|
|
return resolve();
|
|
}
|
|
|
|
//step 2: get it
|
|
let transData = null;
|
|
|
|
if (forceTranslationId) {
|
|
transData = await window.$gz.api.upsert(
|
|
`translation/subset/${forceTranslationId}`,
|
|
needIt
|
|
);
|
|
} else {
|
|
transData = await window.$gz.api.upsert("translation/subset", needIt);
|
|
}
|
|
|
|
transData.data.forEach(function commitFetchedTranslationItemToStore(
|
|
item
|
|
) {
|
|
window.$gz.store.commit("setTranslationText", item);
|
|
});
|
|
return resolve();
|
|
});
|
|
},
|
|
//Keys that will always be required for any AyaNova work for any user
|
|
coreKeys: [
|
|
//main nav options
|
|
"Evaluate",
|
|
"Home",
|
|
"Dashboard",
|
|
"Schedule",
|
|
"MemoList",
|
|
"ReviewList",
|
|
"UserSettings",
|
|
"SetLoginPassword",
|
|
"NotifySubscriptionList",
|
|
"UserPreferences",
|
|
"Service",
|
|
"CustomerList",
|
|
"HeadOfficeList",
|
|
"Contacts",
|
|
"WorkOrderList",
|
|
"WorkOrderServiceTemplate",
|
|
"QuoteList",
|
|
"WorkOrderQuoteTemplate",
|
|
"PMList",
|
|
"PMTemplate",
|
|
"UnitList",
|
|
"UnitModels",
|
|
"ContractList",
|
|
"ProjectList",
|
|
"CustomerServiceRequestList",
|
|
"LoanUnitList",
|
|
"PartList",
|
|
"PartAssemblyList",
|
|
"PartInventoryList",
|
|
"WorkOrderItemPartRequestList",
|
|
"InventoryPurchaseOrders",
|
|
"InventoryPurchaseOrderReceipts",
|
|
"PartInventoryTransactionList",
|
|
"PartWarehouseList",
|
|
"WidgetList",
|
|
"VendorList",
|
|
"AdministrationGlobalSettings",
|
|
"HelpLicense",
|
|
"UserList",
|
|
"Translation",
|
|
"TranslationList",
|
|
"ReportList",
|
|
"ReminderList",
|
|
"Inventory",
|
|
"Accounting",
|
|
"TaxCodeList",
|
|
"ServiceRateList",
|
|
"TravelRateList",
|
|
"ServiceBankList",
|
|
"Administration",
|
|
"Operations",
|
|
"Attachments",
|
|
"Review",
|
|
"Extensions",
|
|
"History",
|
|
"Statistics",
|
|
"Backup",
|
|
"ServerState",
|
|
"ServerJobs",
|
|
"ServerLog",
|
|
"ServerMetrics",
|
|
"ServerProfiler",
|
|
"NotificationSettings",
|
|
"ViewServerConfiguration",
|
|
"HelpAboutAyaNova",
|
|
"MenuHelp",
|
|
"More",
|
|
"Logout",
|
|
"Active",
|
|
"Copy",
|
|
"New",
|
|
"Cancel",
|
|
"Close",
|
|
"Save",
|
|
"Delete",
|
|
"Add",
|
|
"Replace",
|
|
"Remove",
|
|
"OK",
|
|
"Open",
|
|
"Print",
|
|
"Report",
|
|
"Refresh",
|
|
"Sort",
|
|
"WikiPage",
|
|
"Duplicate",
|
|
"RecordHistory",
|
|
"Search",
|
|
"TypeToSearchOrAdd",
|
|
"SelectedItems",
|
|
"AllItemsInList",
|
|
"NoData",
|
|
"Errors",
|
|
"ErrorFieldLengthExceeded",
|
|
"ErrorStartDateAfterEndDate",
|
|
"ErrorRequiredFieldEmpty",
|
|
"ErrorFieldValueNotInteger",
|
|
"ErrorFieldValueNotDecimal",
|
|
"ErrorAPI2000",
|
|
"ErrorAPI2001",
|
|
"ErrorAPI2002",
|
|
"ErrorAPI2003",
|
|
"ErrorAPI2004",
|
|
"ErrorAPI2005",
|
|
"ErrorAPI2010",
|
|
"ErrorAPI2020",
|
|
"ErrorAPI2030",
|
|
"ErrorAPI2200",
|
|
"ErrorAPI2201",
|
|
"ErrorAPI2202",
|
|
"ErrorAPI2203",
|
|
"ErrorAPI2204",
|
|
"ErrorAPI2205",
|
|
"ErrorAPI2206",
|
|
"ErrorAPI2207",
|
|
"ErrorAPI2208",
|
|
"ErrorAPI2209",
|
|
"ErrorAPI2210",
|
|
"ErrorServerUnresponsive",
|
|
"ErrorUserNotAuthenticated",
|
|
"ErrorUserNotAuthorized",
|
|
"ErrorNoMatch",
|
|
"ErrorPickListQueryInvalid",
|
|
"ErrorSecurityUserCapacity",
|
|
"ErrorDBForeignKeyViolation",
|
|
"DeletePrompt",
|
|
"AreYouSureUnsavedChanges",
|
|
"Leave",
|
|
"Tags",
|
|
"Tag",
|
|
"Customize",
|
|
"ObjectCustomFieldCustomGrid",
|
|
"RowsPerPage",
|
|
"PageOfPageText",
|
|
"Loading",
|
|
"Filter",
|
|
"FilterUnsaved",
|
|
"Heading",
|
|
"Table",
|
|
"InsertLink",
|
|
"LinkUrl",
|
|
"LinkText",
|
|
"InsertImage",
|
|
"ImageUrl",
|
|
"ImageDescription",
|
|
"AttachFile",
|
|
"AttachmentNotes",
|
|
"Upload",
|
|
"AttachmentFileName",
|
|
"FileAttachment",
|
|
"MaintenanceExpired",
|
|
"MaintenanceExpiredNote",
|
|
"Import",
|
|
"Export",
|
|
"TimeSpanDays",
|
|
"TimeSpanHours",
|
|
"TimeSpanMinutes",
|
|
"TimeSpanSeconds",
|
|
"DirectNotification",
|
|
"UpdateAvailable",
|
|
"DropFilesHere",
|
|
"First",
|
|
"Backward",
|
|
"Forward",
|
|
"Last",
|
|
"GeoCapture",
|
|
"GeoView",
|
|
"CopyToClipboard",
|
|
"AyaType",
|
|
"Now"
|
|
],
|
|
|
|
////////////////////////////////////////////////////////
|
|
// Take in a string that contains one or more
|
|
//translation keys that start with LT:
|
|
//translate each and replace and return the string translated
|
|
// (fetch and cache any missing strings)
|
|
async translateStringWithMultipleKeysAsync(s) {
|
|
let ret = s;
|
|
let 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:", ""));
|
|
//cache / fetch any that are not already present
|
|
//(async () => {
|
|
await this.cacheTranslations(keysToCache);
|
|
// })();
|
|
|
|
//replace
|
|
found.forEach(z => {
|
|
let translated = this.get(z.replace("LT:", ""));
|
|
//replace all
|
|
ret = ret.split(z).join(translated);
|
|
});
|
|
|
|
return ret;
|
|
},
|
|
////////////////////////////////////////////////////////
|
|
// Take in a string that contains one or more
|
|
//translation keys that start with LT:
|
|
//translate each and replace and return the string translated
|
|
// (DOES NOT fetch and cache any missing strings, they must exist)
|
|
//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);
|
|
if (found == null) {
|
|
return ret;
|
|
}
|
|
//replace
|
|
found.forEach(z => {
|
|
let translated = this.get(z.replace("LT:", ""));
|
|
//replace all
|
|
ret = ret.split(z).join(translated);
|
|
});
|
|
return ret;
|
|
},
|
|
|
|
////////////////////////////////////////////////////////
|
|
// dynamically set the vuetify language elements from
|
|
// users translated text
|
|
// Keeping vuetify using en locale and just adjusting on top of that
|
|
//
|
|
setVuetifyDefaultLanguageElements(vm) {
|
|
vm.$vuetify.lang.locales.en.close = this.get("OK");
|
|
}
|
|
};
|