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

View File

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