Files
raven-client/ayanova/src/api/translation.js
2020-04-21 23:55:10 +00:00

205 lines
4.9 KiB
JavaScript

/* ZZeslint-disable */
//AyaNova Translation related utilities
export default {
get(key) {
//no translation for Wiki
if (key == "Wiki") {
return "Wiki";
}
if (!window.$gz._.has(window.$gz.store.state.translationText, key)) {
return "??" + key;
}
return window.$gz.store.state.translationText[key];
},
fetch(keys) {
return new Promise(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._.has(window.$gz.store.state.translationText, keys[i])
) {
needIt.push(keys[i]);
}
}
if (needIt.length == 0) {
resolve();
return;
}
//step 2: get it
fetch(
window.$gz.api.APIUrl("translation/subset"),
window.$gz.api.fetchPostOptions(needIt)
)
.then(window.$gz.api.status)
.then(window.$gz.api.json)
// eslint-disable-next-line
.then((response) => {
window.$gz._.forEach(
response.data,
function commitFetchedLTItemToStore(item) {
window.$gz.store.commit("addTranslationText", item);
}
);
resolve();
});
});
},
//Keys that will always be required for any AyaNova work for any user
coreKeys: [
//main nav options
"Home",
"Dashboard",
"Schedule",
"MemoList",
"UserSettings",
"SetLoginPassword",
"NotifySubscriptionList",
"UserPreferences",
"Service",
"ClientList",
"HeadOfficeList",
"WorkorderServiceList",
"WorkorderServiceTemplate",
"WorkorderQuoteList",
"WorkorderQuoteTemplate",
"WorkorderPreventiveMaintenanceList",
"WorkorderPreventiveMaintenanceTemplate",
"UnitList",
"UnitModels",
"ContractList",
"ClientServiceRequestList",
"LoanItemList",
"PartList",
"PartByWarehouseInventoryList",
"WorkorderItemPartRequestList",
"InventoryPurchaseOrders",
"InventoryPurchaseOrderReceipts",
"InventoryPartInventoryAdjustments",
"WidgetList",
"VendorList",
"AdministrationGlobalSettings",
"HelpLicense",
"UserList",
"Translation",
"ReportList",
"ReminderList",
"Inventory",
"Accounting",
"Administration",
"Operations",
"Attachments",
"Review",
"History",
"Statistics",
"Backup",
"ServerState",
"ServerJobs",
"ServerLog",
"ServerMetrics",
"NotificationSettings",
"HelpAboutAyaNova",
"MenuHelp",
"More",
"Logout",
"Active",
"New",
"Cancel",
"Close",
"Save",
"Delete",
"OK",
"Open",
"Print",
"Report",
"WikiPage",
"Duplicate",
"RecordHistory",
"Search",
"TypeToSearchOrAdd",
"NoData",
"ErrorFieldLengthExceeded",
"ErrorStartDateAfterEndDate",
"ErrorRequiredFieldEmpty",
"ErrorFieldValueNotInteger",
"ErrorFieldValueNotDecimal",
"ErrorAPI2000",
"ErrorAPI2001",
"ErrorAPI2002",
"ErrorAPI2003",
"ErrorAPI2004",
"ErrorAPI2005",
"ErrorAPI2010",
"ErrorAPI2020",
"ErrorAPI2030",
"ErrorAPI2200",
"ErrorAPI2201",
"ErrorAPI2202",
"ErrorAPI2203",
"ErrorAPI2204",
"ErrorAPI2205",
"ErrorAPI2206",
"ErrorAPI2207",
"ErrorAPI2208",
"ErrorAPI2209",
"ErrorServerUnresponsive",
"ErrorUserNotAuthenticated",
"ErrorUserNotAuthorized",
"ErrorNoMatch",
"ErrorPickListQueryInvalid",
"DeletePrompt",
"AreYouSureUnsavedChanges",
"Leave",
"Tags",
"Customize",
"ObjectCustomFieldCustomGrid",
"RowsPerPage",
"PageOfPageText",
"Loading",
"DataListView",
"FilterUnsaved",
"Heading",
"Table",
"InsertLink",
"LinkUrl",
"LinkText",
"InsertImage",
"ImageUrl",
"ImageDescription",
"AttachFile",
"AttachmentNotes"
],
////////////////////////////////////////////////////////
// Take in a string that contains one or more
//translation keys between square brackets
//translate each and return the string translated
//
translateString(s) {
let ret = s;
let pattern = /\[(.*?)\]/g;
let match;
while ((match = pattern.exec(s)) != null) {
let foundMatch = match[0];
let tKey = match[1];
let newValue = this.get(tKey);
ret = ret.replace(foundMatch, newValue);
}
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");
}
};