Fix a lot of client locale stuff

This commit is contained in:
Vortrex
2022-05-15 04:16:57 -05:00
parent c33d67cdf2
commit 050c190237

View File

@@ -8,11 +8,15 @@
// ===========================================================================
function getLocaleString(stringName, ...args) {
if(typeof getServerData().localeStrings[stringName] == undefined) {
if(typeof getServerData().localeStrings[localLocaleId][stringName] == undefined) {
return "";
}
let tempString = getServerData().localeStrings[stringName];
let tempString = getServerData().localeStrings[localLocaleId][stringName];
if(tempString == "" || tempString == null || tempString == undefined) {
return "";
}
for(let i = 1; i <= args.length; i++) {
tempString = tempString.replace(`{${i}}`, args[i-1]);
@@ -23,18 +27,36 @@ function getLocaleString(stringName, ...args) {
// ===========================================================================
function receiveLocaleStringFromServer(stringName, stringValue) {
logToConsole(LOG_INFO, `[VRR.Locale]: Received locale string "${stringName}" from server (${stringValue})`);
getServerData().localeStrings[stringName] = stringValue;
function getAvailableLocaleOptions() {
return getServerData().localeOptions.filter(localeOption => localeOption.requiresUnicode == false);
}
// ===========================================================================
function receiveLocaleStringsFromServer(strings) {
for(let i in strings) {
let stringName = strings[i][0];
getServerData().localeStrings[stringName] = strings[i][1];
function loadLocaleConfig() {
let configFile = loadTextFile("config/client/locale.json");
getServerData().localeOptions = JSON.parse(configFile);
}
// ===========================================================================
function loadAllLocaleStrings() {
let localeOptions = getServerData().localeOptions;
for(let i in localeOptions) {
logToConsole(LOG_INFO, `[VRR.Locale] Loading locale strings for ${localeOptions[i].englishName} (${i})`);
let localeFile = loadTextFile(`locale/${localeOptions[i].stringsFile}`);
let localeData = JSON.parse(localeFile);
getServerData().localeStrings[i] = localeData;
}
}
// ===========================================================================
function setLocale(tempLocaleId) {
logToConsole(LOG_DEBUG, `[VRR.Locale] Setting locale to ${tempLocaleId} (${getServerData().localeOptions[tempLocaleId].englishName})`);
localLocaleId = tempLocaleId;
resetGUIStrings();
}
// ===========================================================================