diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 4812db2..ab0303d 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -11,6 +11,12 @@
+
+
+
+
+
+
@@ -36,30 +42,24 @@
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
@@ -70,6 +70,18 @@
+
+
+
+
+
@@ -77,6 +89,7 @@
+
@@ -88,11 +101,6 @@
-
-
-
-
-
@@ -110,12 +118,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
diff --git a/package.json b/package.json
index 4547c17..6732ec5 100644
--- a/package.json
+++ b/package.json
@@ -43,6 +43,9 @@
"ffmpeg-static": "^4.4.0",
"figlet": "^1.5.0",
"gradient-string": "^1.2.0",
+ "i18next": "^20.3.2",
+ "i18next-fluent": "^1.0.1",
+ "i18next-fs-backend": "^1.1.1",
"jsonschema": "^1.4.0",
"luxon": "^1.27.0",
"module-alias": "^2.2.2",
@@ -67,6 +70,7 @@
"@types/eslint": "^7.2.13",
"@types/figlet": "^1.5.1",
"@types/gradient-string": "^1.1.1",
+ "@types/i18next-fs-backend": "^1.0.0",
"@types/luxon": "^1.27.0",
"@types/mocha": "^8.2.2",
"@types/module-alias": "^2.0.0",
@@ -83,6 +87,7 @@
"eslint-formatter-pretty": "^4.1.0",
"eslint-plugin-header": "^3.1.1",
"husky": "^6.0.0",
+ "i18next-chained-backend": "^3.0.2",
"lint-staged": "^11.0.0",
"mocha": "^9.0.1",
"nodemon": "^2.0.8",
diff --git a/src/commands/utils/vm.ts b/src/commands/utils/vm.ts
index dfae999..7c61d93 100644
--- a/src/commands/utils/vm.ts
+++ b/src/commands/utils/vm.ts
@@ -15,6 +15,7 @@
* along with ArgonBot. If not, see .
*/
import Command from '@structures/command';
+import i18next from 'i18next';
import { transpile } from 'typescript';
import { NodeVM } from 'vm2';
@@ -32,7 +33,7 @@ export class vm extends Command {
switch(vmLang.toLowerCase()) {
case 'js':
case 'javascript':
- await message.reply('Computing JavaScript code... Please wait!');
+ await message.reply(i18next.t('commands:vm.computing', { language: 'JavaScript' }));
try {
let returnVal: string;
@@ -43,12 +44,12 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) {
- await message.reply(`An error has occurred while executing JavaScript code!\n\`\`\`\n${err.message}\n\`\`\``);
+ await message.reply(i18next.t('commands:vm.error', { error: err.message }));
}
break;
case 'ts':
case 'typescript':
- await message.reply('Computing TypeScript code... Please wait!');
+ await message.reply(i18next.t('commands:vm.computing', { language: 'TypeScript' }));
try {
const jsCode = transpile(code);
@@ -61,11 +62,11 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) {
- await message.reply(`An error has occurred while executing TypeScript code!\n\`\`\`\n${err.message}\n\`\`\``);
+ await message.reply(i18next.t('commands:vm.error', { error: err.message }));
}
break;
default:
- await message.reply('Unknown Language given!');
+ await message.reply(i18next.t('commands:vm.unknown'));
}
}
}
diff --git a/src/index.ts b/src/index.ts
index ad3eaa4..ce783e6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -26,6 +26,12 @@ import config from 'config';
import { Client, Collection } from 'discord.js';
import figlet from 'figlet';
import gradient from 'gradient-string';
+import i18next from 'i18next';
+import Backend from 'i18next-chained-backend';
+import FSBackend from 'i18next-fs-backend';
+// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+// @ts-ignore
+import Fluent from 'i18next-fluent';
import { Validator } from 'jsonschema';
import { DateTime } from 'luxon';
import path from 'path';
@@ -108,6 +114,27 @@ client.on('message', async (msg) => {
});
client.on('ready', async () => {
+ info('Loading translations...', ELoggingScope.Startup);
+
+ await i18next.use(Fluent).use(Backend).init({
+ lng: 'en-US',
+ ns: ['common', 'commands'],
+ defaultNS: 'common',
+ fallbackNS: 'common',
+ fallbackLng: 'en-US',
+ supportedLngs: ['en-US'],
+ backend: {
+ backends: [FSBackend],
+ backendOptions: [
+ {
+ loadPath: `${process.cwd()}/translations/{{lng}}/{{ns}}.json`,
+ },
+ ],
+ },
+ });
+
+ info('Finished loading translations.', ELoggingScope.Startup);
+
info('Loading commands...', ELoggingScope.Startup);
try {
diff --git a/translations/en-US/commands.json b/translations/en-US/commands.json
new file mode 100644
index 0000000..72b0b8e
--- /dev/null
+++ b/translations/en-US/commands.json
@@ -0,0 +1,7 @@
+{
+ "vm": {
+ "computing": "Computing { $language } code... Please wait!",
+ "error": "An error has occurred while executing JavaScript code!\n```\n{{ $error }}\n```",
+ "unknown": "Unknown language given!"
+ }
+}
diff --git a/translations/en-US/common.json b/translations/en-US/common.json
new file mode 100644
index 0000000..e69de29
diff --git a/tsconfig.json b/tsconfig.json
index bfb3393..98493a2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -45,11 +45,10 @@
"listEmittedFiles": false,
"listFiles": false,
"newLine": "lf",
- "noEmitOnError": true,
+ "noEmitOnError": false,
"preserveConstEnums": true,
"resolveJsonModule": true,
"traceResolution": false,
- "sourceMap": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
diff --git a/yarn.lock b/yarn.lock
index 5b76024..d21ee29 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -234,6 +234,15 @@ __metadata:
languageName: node
linkType: hard
+"@babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.14.0":
+ version: 7.14.6
+ resolution: "@babel/runtime@npm:7.14.6"
+ dependencies:
+ regenerator-runtime: ^0.13.4
+ checksum: 927ffed7871f2ed29f967a8dad7a72aa10662f93b6735a89d664a161fa4dc2074b8947ca159a8a0a49cec9a71c8de473d7c2b22d3de0ee4d7dd06d24a7f98018
+ languageName: node
+ linkType: hard
+
"@babel/template@npm:^7.14.5":
version: 7.14.5
resolution: "@babel/template@npm:7.14.5"
@@ -866,6 +875,15 @@ __metadata:
languageName: node
linkType: hard
+"@types/i18next-fs-backend@npm:^1.0.0":
+ version: 1.0.0
+ resolution: "@types/i18next-fs-backend@npm:1.0.0"
+ dependencies:
+ i18next: ^19.7.0
+ checksum: eeda011d4013ae26f98385dc2efc44c64a8b8382fe94ab9f833f0026ca670b345ac21fa1f9b4471b95c3916c137cba8b66002d17742c226ecc70f12a4190c3c2
+ languageName: node
+ linkType: hard
+
"@types/json-schema@npm:*, @types/json-schema@npm:^7.0.7":
version: 7.0.7
resolution: "@types/json-schema@npm:7.0.7"
@@ -1551,6 +1569,7 @@ __metadata:
"@types/eslint": ^7.2.13
"@types/figlet": ^1.5.1
"@types/gradient-string": ^1.1.1
+ "@types/i18next-fs-backend": ^1.0.0
"@types/luxon": ^1.27.0
"@types/mocha": ^8.2.2
"@types/module-alias": ^2.0.0
@@ -1575,6 +1594,10 @@ __metadata:
figlet: ^1.5.0
gradient-string: ^1.2.0
husky: ^6.0.0
+ i18next: ^20.3.2
+ i18next-chained-backend: ^3.0.2
+ i18next-fluent: ^1.0.1
+ i18next-fs-backend: ^1.1.1
jsonschema: ^1.4.0
lint-staged: ^11.0.0
luxon: ^1.27.0
@@ -3448,6 +3471,29 @@ __metadata:
languageName: node
linkType: hard
+"fluent-syntax@npm:0.8.1":
+ version: 0.8.1
+ resolution: "fluent-syntax@npm:0.8.1"
+ checksum: eab782c499bb5f65879e6c86558b7df3020271ebe6905ae051e50a4975ab2352be8325931d7303da29d33dd92c1bc1b74016717957999423a02919b0da7c3f78
+ languageName: node
+ linkType: hard
+
+"fluent@npm:^0.8.0":
+ version: 0.8.1
+ resolution: "fluent@npm:0.8.1"
+ checksum: 708c2aecbe96f522289be3eca9bc6e4b345fde9d46bad0f5912f233a71f15c1e67dd236a157ff95bfac064e980286d58ef88d7ab29d2fa718d2fa4711986e24f
+ languageName: node
+ linkType: hard
+
+"fluent_conv@npm:^1.1.1":
+ version: 1.1.1
+ resolution: "fluent_conv@npm:1.1.1"
+ dependencies:
+ fluent-syntax: 0.8.1
+ checksum: 2261ad4e71c0d9921a26f4de73633eded093fb5105a1cae2a422c556765bb5239149b6751a6b5119d9c9d73db1807ad0cb41837c7b8180c7832a405a76702aa7
+ languageName: node
+ linkType: hard
+
"foreground-child@npm:^2.0.0":
version: 2.0.0
resolution: "foreground-child@npm:2.0.0"
@@ -4028,6 +4074,50 @@ __metadata:
languageName: node
linkType: hard
+"i18next-chained-backend@npm:^3.0.2":
+ version: 3.0.2
+ resolution: "i18next-chained-backend@npm:3.0.2"
+ dependencies:
+ "@babel/runtime": ^7.14.0
+ checksum: 658820f9790691cedea54d19f3c923b8c42b71bf7daf6b3f8b6b32dd4ddd7e36ce4128241f5fa813a4eb5e3502b1c725c15c7b8f2847590fc5fb1829e9e779a6
+ languageName: node
+ linkType: hard
+
+"i18next-fluent@npm:^1.0.1":
+ version: 1.0.1
+ resolution: "i18next-fluent@npm:1.0.1"
+ dependencies:
+ fluent: ^0.8.0
+ fluent_conv: ^1.1.1
+ checksum: 99cf88edecbbc0f4748f457b04db1ef1ebe6b7da837ae0faceac30e07fec51ab98a3344c95cf89e98250e8931a9997b5252bcab10feb373460fb0aa56844ccfa
+ languageName: node
+ linkType: hard
+
+"i18next-fs-backend@npm:^1.1.1":
+ version: 1.1.1
+ resolution: "i18next-fs-backend@npm:1.1.1"
+ checksum: a7516b7c2cc176453897dea1cb0f78aee0a8bf6d77ee5ecde08698b7bde42cb02b8d48667f0c6fc663680400af94d20dbff2fbb5b07d7ca66a0980a7e75c1458
+ languageName: node
+ linkType: hard
+
+"i18next@npm:^19.7.0":
+ version: 19.9.2
+ resolution: "i18next@npm:19.9.2"
+ dependencies:
+ "@babel/runtime": ^7.12.0
+ checksum: a24207707eacb28488975f8921d843bc35b86f2a48504cb82eaf620e1aacddbda8d53a4dc600543a708ba49bc45e61072a753f250e89fad2c1932259190ef81a
+ languageName: node
+ linkType: hard
+
+"i18next@npm:^20.3.2":
+ version: 20.3.2
+ resolution: "i18next@npm:20.3.2"
+ dependencies:
+ "@babel/runtime": ^7.12.0
+ checksum: 71867418c1d3e477b453daa0696999fe80a4b2c6d37b27fff073645a5e06b36b6adbf02bff738e288e523add10bb6b16dd72e0c13f3d6a2a3733836dcdbcd5ec
+ languageName: node
+ linkType: hard
+
"iconv-lite@npm:^0.6.2":
version: 0.6.3
resolution: "iconv-lite@npm:0.6.3"
@@ -6412,6 +6502,13 @@ __metadata:
languageName: node
linkType: hard
+"regenerator-runtime@npm:^0.13.4":
+ version: 0.13.8
+ resolution: "regenerator-runtime@npm:0.13.8"
+ checksum: 5f89699ab578301e3f47fe323d2a9e19ed4b7302481b37ce96843602be3a5cb1e5b66a07c1500e69d4710c1dd6fa3b3f3e56d188ef56df4c17a744d853ac36ed
+ languageName: node
+ linkType: hard
+
"regexpp@npm:^3.1.0":
version: 3.2.0
resolution: "regexpp@npm:3.2.0"