diff --git a/dist/lang.js b/dist/lang.js index ed531a8..007adbf 100644 --- a/dist/lang.js +++ b/dist/lang.js @@ -47,6 +47,14 @@ var Lang; throw 'language id does not exist'; } 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 * @param id ex: discord.error.noActiveQueue @@ -59,7 +67,7 @@ var Lang; if (key in finding) { let found = finding[key]; if (typeof found === 'string') - return found; + return template(found, args); finding = found; } else diff --git a/src/lang.ts b/src/lang.ts index c7a5282..291f902 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -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;