Add grouped locale util, use locale ID
This commit is contained in:
@@ -16,7 +16,7 @@ function initLocaleScript() {
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleString(client, stringName, ...args) {
|
||||
let tempString = getRawLocaleString(stringName, getPlayerLocaleName(client));
|
||||
let tempString = getRawLocaleString(stringName, getPlayerData(client).locale);
|
||||
if(tempString == "") {
|
||||
submitBugReport(client, `(AUTOMATED REPORT) Locale string "${stringName}" is missing for "${getPlayerLocaleName(client)}"`);
|
||||
}
|
||||
@@ -32,19 +32,34 @@ function getLocaleString(client, stringName, ...args) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getGroupedLocaleString(client, stringName, index, ...args) {
|
||||
let tempString = getRawGroupedLocaleString(stringName, getPlayerData(client).locale, index);
|
||||
tempString = replaceColoursInMessage(tempString);
|
||||
|
||||
for(let i = 1; i <= args.length; i++) {
|
||||
tempString = tempString.replace(`{${i}}`, args[i-1]);
|
||||
}
|
||||
|
||||
return tempString;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getRawLocaleString(stringName, localeName) {
|
||||
return getLocaleStrings()[localeName][stringName];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerLocaleName(client) {
|
||||
if(client == null) {
|
||||
return getLocaleNameFromParams(`English`);
|
||||
}
|
||||
function getRawGroupedLocaleString(stringName, localeName, index) {
|
||||
return getLocaleStrings()[localeName][stringName][index];
|
||||
}
|
||||
|
||||
return "english";
|
||||
//return getPlayerData(client).accountData.locale;
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerLocaleName(client) {
|
||||
let localeId = getPlayerData(client).locale;
|
||||
return getLocales()[localeId][0];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -56,7 +71,7 @@ function loadAllLocaleStrings() {
|
||||
for(let i in locales) {
|
||||
let localeData = locales[i];
|
||||
let localeFile = JSON.parse(loadTextFile(`locale/${localeData[1]}.json`));
|
||||
tempLocaleStrings[localeData[1]] = localeFile;
|
||||
tempLocaleStrings[i] = localeFile;
|
||||
}
|
||||
|
||||
return tempLocaleStrings;
|
||||
@@ -70,17 +85,21 @@ function getLocaleStrings() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleNameFromParams(params) {
|
||||
function getLocaleFromParams(params) {
|
||||
let locales = getLocales();
|
||||
if(isNaN(params)) {
|
||||
for(let i in locales) {
|
||||
if(toLowerCase(i).indexOf(toLowerCase(params)) != -1) {
|
||||
return locales[i];
|
||||
if(toLowerCase(locales[i][2]).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if(toLowerCase(locales[i][0]).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -89,4 +108,46 @@ function getLocales() {
|
||||
return getGlobalConfig().locales;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function showLocaleListCommand(command, params, client) {
|
||||
let localeList = getLocales().map(function(x) { return x[0]; });
|
||||
let chunkedList = splitArrayIntoChunks(localeList, 10);
|
||||
|
||||
messagePlayerInfo(client, getLocaleString(client, "HeaderLocaleList"));
|
||||
for(let i in chunkedList) {
|
||||
messagePlayerInfo(client, chunkedList[i].join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setLocaleCommand(command, params, client) {
|
||||
if(areParamsEmpty(params)) {
|
||||
messagePlayerSyntax(client, getCommandSyntaxText(command));
|
||||
return false;
|
||||
}
|
||||
|
||||
let localeId = getLocaleFromParams(params);
|
||||
|
||||
if(!getLocaleData(localeId)) {
|
||||
messagePlayerInfo(client, getLocaleString(client, "InvalidLocale"));
|
||||
return false;
|
||||
}
|
||||
|
||||
getPlayerData(client).accountData.locale = localeId;
|
||||
getPlayerData(client).locale = localeId;
|
||||
messagePlayerSuccess(client, getLocaleString(client, "LocaleChanged1"), getLocaleString(client, "LocaleNativeName"));
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleData(localeId) {
|
||||
if(typeof getLocales()[localeId] != "undefined") {
|
||||
return getLocales()[localeId];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user