Use external locale resource funcs
This commit is contained in:
@@ -8,53 +8,32 @@
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleString(stringName, ...args) {
|
||||
if(typeof getServerData().localeStrings[localLocaleId][stringName] == undefined) {
|
||||
return "";
|
||||
return findResourceByName("agrp_locale").exports.getLocaleString(localLocaleId, stringName, args);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
return tempString;
|
||||
function getGroupedLocaleString(stringName, index, ...args) {
|
||||
return findResourceByName("agrp_locale").exports.getGroupedLocaleString(localLocaleId, stringName, index, args);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getAvailableLocaleOptions() {
|
||||
return getServerData().localeOptions.filter(localeOption => localeOption.requiresUnicode == false);
|
||||
return findResourceByName("agrp_locale").exports.getAvailableLocaleOptions();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
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 getLocales() {
|
||||
return findResourceByName("agrp_locale").exports.getLocales();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setLocale(tempLocaleId) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Locale] Setting locale to ${tempLocaleId} (${getServerData().localeOptions[tempLocaleId].englishName})`);
|
||||
let locales = getLocales();
|
||||
logToConsole(LOG_DEBUG, `[VRR.Locale] Setting locale to ${tempLocaleId} (${locales[tempLocaleId].englishName})`);
|
||||
localLocaleId = tempLocaleId;
|
||||
resetGUIStrings();
|
||||
}
|
||||
|
||||
@@ -15,76 +15,42 @@ function initLocaleScript() {
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleString(client, stringName, ...args) {
|
||||
let tempString = getRawLocaleString(stringName, getPlayerData(client).locale);
|
||||
if(tempString == "" || tempString == null || typeof tempString == "undefined") {
|
||||
logToConsole(LOG_WARN, `[VRR.Locale] Locale string missing for ${stringName} on language ${getLocaleData(getPlayerData(client).locale).englishName}`);
|
||||
let localeId = getPlayerData(client).locale;
|
||||
if (!findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName)) {
|
||||
submitBugReport(client, `(AUTOMATED REPORT) Locale string "${stringName}" is missing for "${getPlayerLocaleName(client)}"`);
|
||||
return "";
|
||||
}
|
||||
|
||||
for(let i = 1; i <= args.length; i++) {
|
||||
tempString = tempString.replace(`{${i}}`, args[i-1]);
|
||||
}
|
||||
|
||||
return tempString;
|
||||
return findResourceByName("agrp_locale").exports.getLocaleString(localeId, stringName, args);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLanguageLocaleString(localeId, stringName, ...args) {
|
||||
let tempString = getRawLocaleString(stringName, localeId);
|
||||
if(tempString == "" || tempString == null || typeof tempString == "undefined") {
|
||||
logToConsole(LOG_WARN, `[VRR.Locale] Locale string missing for ${stringName} on language ${getLocaleData(getPlayerData(client).locale).englishName}`);
|
||||
if (!findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName)) {
|
||||
submitBugReport(client, `(AUTOMATED REPORT) Locale string "${stringName}" is missing for "${getPlayerLocaleName(client)}"`);
|
||||
return "";
|
||||
}
|
||||
|
||||
for(let i = 1; i <= args.length; i++) {
|
||||
tempString = tempString.replace(`{${i}}`, args[i-1]);
|
||||
}
|
||||
|
||||
return tempString;
|
||||
return findResourceByName("agrp_locale").exports.getLocaleString(getPlayerData(client).locale, stringName, args);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getGroupedLocaleString(client, stringName, index, ...args) {
|
||||
let tempString = getRawGroupedLocaleString(stringName, getPlayerData(client).locale, index);
|
||||
|
||||
for(let i = 1; i <= args.length; i++) {
|
||||
tempString = tempString.replace(`{${i}}`, args[i-1]);
|
||||
}
|
||||
|
||||
return tempString;
|
||||
return findResourceByName("agrp_locale").exports.getGroupedLocaleString(getPlayerData(client).locale, stringName, index, args);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getRawLocaleString(stringName, localeId) {
|
||||
return getLocaleStrings()[localeId][stringName];
|
||||
|
||||
//if(findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName) == false) {
|
||||
// return "";
|
||||
//}
|
||||
|
||||
//let tempString = findResourceByName("agrp_locale").exports.getRawLocaleString(localeId, stringName);
|
||||
//if(tempString == "" || tempString == null || tempString == undefined) {
|
||||
// return "";
|
||||
//}
|
||||
return findResourceByName("agrp_locale").exports.getRawLocaleString(localeId, stringName);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getRawGroupedLocaleString(stringName, localeId, index) {
|
||||
return getLocaleStrings()[localeId][stringName][index];
|
||||
|
||||
//if(findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName) == false) {
|
||||
// return "";
|
||||
//}
|
||||
|
||||
//let tempString = findResourceByName("agrp_locale").exports.getRawLocaleString(localeId, stringName);
|
||||
//if(tempString == "" || tempString == null || tempString == undefined) {
|
||||
// return "";
|
||||
//}
|
||||
return findResourceByName("agrp_locale").exports.getRawGroupedLocaleString(localeId, stringName, index);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -96,48 +62,14 @@ function getPlayerLocaleName(client) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadAllLocaleStrings() {
|
||||
let tempLocaleStrings = {};
|
||||
|
||||
let locales = getGlobalConfig().locale.locales;
|
||||
for(let i in locales) {
|
||||
let localeData = locales[i];
|
||||
let localeFile = JSON.parse(loadTextFile(`locale/${localeData.stringsFile}`));
|
||||
tempLocaleStrings[i] = localeFile;
|
||||
}
|
||||
|
||||
return tempLocaleStrings;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleStrings() {
|
||||
return getServerData().localeStrings;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleFromParams(params) {
|
||||
let locales = getLocales();
|
||||
if(isNaN(params)) {
|
||||
for(let i in locales) {
|
||||
if(toLowerCase(locales[i].isoCode).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if(toLowerCase(locales[i].englishName).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return findResourceByName("agrp_locale").exports.getLocaleFromParams(params);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocales() {
|
||||
return getGlobalConfig().locale.locales;
|
||||
return findResourceByName("agrp_locale").exports.getLocales();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user