updated lang

This commit is contained in:
2022-02-13 19:51:30 -06:00
parent 343ed640ae
commit ab76d7edbc
2 changed files with 36 additions and 2 deletions

10
dist/lang.js vendored
View File

@@ -47,6 +47,14 @@ var Lang;
throw 'language id does not exist'; throw 'language id does not exist';
} }
Lang.setLang = setLang; Lang.setLang = setLang;
function template(str, args) {
return str.replace(/{\w+}/g, str => {
let key = str.substring(1, str.length - 1);
if (key in args)
return args[key];
return key;
});
}
/** /**
* reads language json * reads language json
* @param id ex: discord.error.noActiveQueue * @param id ex: discord.error.noActiveQueue
@@ -59,7 +67,7 @@ var Lang;
if (key in finding) { if (key in finding) {
let found = finding[key]; let found = finding[key];
if (typeof found === 'string') if (typeof found === 'string')
return found; return template(found, args);
finding = found; finding = found;
} }
else else

View File

@@ -2,10 +2,13 @@ type LangObj = { [keys:string]: LangObj | string }
type LangObjWhold = { [langid:string]: LangObj } type LangObjWhold = { [langid:string]: LangObj }
const LANG: LangObjWhold = { const LANG: LangObjWhold = {
en: { en: {
main: { main: {
login: 'Logged in as {user}' login: 'Logged in as {user}'
}, },
discord: { discord: {
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset', botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
create: 'A queue for teams of {teamsize} has been created', create: 'A queue for teams of {teamsize} has been created',
@@ -13,10 +16,13 @@ const LANG: LangObjWhold = {
join: 'Joined the queue', join: 'Joined the queue',
leave: 'Left the queue' leave: 'Left the queue'
}, },
error: { error: {
main: { main: {
missingToken: 'Missing Discord Token, please enter the bot token into the token file' missingToken: 'Missing Discord Token, please enter the bot token into the token file'
}, },
discord: { discord: {
noQueue: 'There is not an active queue in this channel, type `/open` to create one', noQueue: 'There is not an active queue in this channel, type `/open` to create one',
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}', noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
@@ -25,15 +31,20 @@ const LANG: LangObjWhold = {
notInQueue: 'You aren\'t in the queue', notInQueue: 'You aren\'t in the queue',
notMod: 'Member is not a moderator' notMod: 'Member is not a moderator'
}, },
general: { general: {
noMember: 'Unable to retrieve guild member information, please try again', noMember: 'Unable to retrieve guild member information, please try again',
noChannel: 'Unable to retrieve text channel information, please try again' noChannel: 'Unable to retrieve text channel information, please try again'
}, },
api: { api: {
noUser: 'Unable to find user' noUser: 'Unable to find user'
} }
} }
} }
} }
export namespace Lang { export namespace Lang {
@@ -49,6 +60,21 @@ export namespace Lang {
throw 'language id does not exist'; throw 'language id does not exist';
} }
function template(str: string, args: {[keys: string]: string}): string {
return str.replace(/{\w+}/g, str => {
let key = str.substring(1, str.length-1);
if (key in args)
return args[key];
return key;
});
}
/** /**
* reads language json * reads language json
* @param id ex: discord.error.noActiveQueue * @param id ex: discord.error.noActiveQueue
@@ -67,7 +93,7 @@ export namespace Lang {
let found = finding[key]; let found = finding[key];
if (typeof found === 'string') if (typeof found === 'string')
return found; return template(found, args);
finding = found; finding = found;