Archived
0
0
Fork 0

feat: added translations

This commit is contained in:
Daryl Ronningen 2021-06-29 10:54:17 -05:00
parent f0e6c5c050
commit ddc18ec493
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
8 changed files with 198 additions and 31 deletions

View file

@ -11,6 +11,12 @@
<option name="LINE_SEPARATOR" value="&#10;" /> <option name="LINE_SEPARATOR" value="&#10;" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" /> <option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<option name="SOFT_MARGINS" value="80,120" /> <option name="SOFT_MARGINS" value="80,120" />
<CssCodeStyleSettings>
<option name="HEX_COLOR_UPPER_CASE" value="true" />
<option name="HEX_COLOR_LONG_FORMAT" value="true" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="ENFORCE_QUOTES_ON_FORMAT" value="true" />
</CssCodeStyleSettings>
<DBN-PSQL> <DBN-PSQL>
<case-options enabled="true"> <case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" /> <option name="KEYWORD_CASE" value="lower" />
@ -36,30 +42,24 @@
</formatting-settings> </formatting-settings>
</DBN-SQL> </DBN-SQL>
<HTMLCodeStyleSettings> <HTMLCodeStyleSettings>
<option name="HTML_UNIFORM_INDENT" value="true" />
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" /> <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
</HTMLCodeStyleSettings> </HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<Markdown> <Markdown>
<option name="MAX_LINES_AROUND_HEADER" value="0" /> <option name="MAX_LINES_AROUND_HEADER" value="0" />
<option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" /> <option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" />
<option name="MAX_LINES_BETWEEN_PARAGRAPHS" value="0" /> <option name="MAX_LINES_BETWEEN_PARAGRAPHS" value="0" />
</Markdown> </Markdown>
<ScssCodeStyleSettings>
<option name="HEX_COLOR_UPPER_CASE" value="true" />
<option name="HEX_COLOR_LONG_FORMAT" value="true" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="ENFORCE_QUOTES_ON_FORMAT" value="true" />
</ScssCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0"> <TypeScriptCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="USE_PUBLIC_MODIFIER" value="true" /> <option name="USE_PUBLIC_MODIFIER" value="true" />
<option name="PREFER_AS_TYPE_CAST" value="true" /> <option name="PREFER_AS_TYPE_CAST" value="true" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
<option name="IMPORT_SORT_MODULE_NAME" value="true" /> <option name="IMPORT_SORT_MODULE_NAME" value="true" />
</TypeScriptCodeStyleSettings> </TypeScriptCodeStyleSettings>
<codeStyleSettings language="CSS"> <codeStyleSettings language="CSS">
@ -70,6 +70,18 @@
<option name="USE_TAB_CHARACTER" value="true" /> <option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" /> <option name="SMART_TABS" value="true" />
</indentOptions> </indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<NAME>.*</NAME>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="HTML"> <codeStyleSettings language="HTML">
<indentOptions> <indentOptions>
@ -77,6 +89,7 @@
<option name="CONTINUATION_INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" /> <option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="true" /> <option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="JSON"> <codeStyleSettings language="JSON">
@ -88,11 +101,6 @@
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="JavaScript"> <codeStyleSettings language="JavaScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
<indentOptions> <indentOptions>
<option name="INDENT_SIZE" value="2" /> <option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="2" />
@ -110,12 +118,35 @@
<option name="SMART_TABS" value="true" /> <option name="SMART_TABS" value="true" />
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="SASS">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="SCSS">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<NAME>.*</NAME>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="TypeScript"> <codeStyleSettings language="TypeScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
<indentOptions> <indentOptions>
<option name="INDENT_SIZE" value="2" /> <option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="2" />

View file

@ -43,6 +43,9 @@
"ffmpeg-static": "^4.4.0", "ffmpeg-static": "^4.4.0",
"figlet": "^1.5.0", "figlet": "^1.5.0",
"gradient-string": "^1.2.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", "jsonschema": "^1.4.0",
"luxon": "^1.27.0", "luxon": "^1.27.0",
"module-alias": "^2.2.2", "module-alias": "^2.2.2",
@ -67,6 +70,7 @@
"@types/eslint": "^7.2.13", "@types/eslint": "^7.2.13",
"@types/figlet": "^1.5.1", "@types/figlet": "^1.5.1",
"@types/gradient-string": "^1.1.1", "@types/gradient-string": "^1.1.1",
"@types/i18next-fs-backend": "^1.0.0",
"@types/luxon": "^1.27.0", "@types/luxon": "^1.27.0",
"@types/mocha": "^8.2.2", "@types/mocha": "^8.2.2",
"@types/module-alias": "^2.0.0", "@types/module-alias": "^2.0.0",
@ -83,6 +87,7 @@
"eslint-formatter-pretty": "^4.1.0", "eslint-formatter-pretty": "^4.1.0",
"eslint-plugin-header": "^3.1.1", "eslint-plugin-header": "^3.1.1",
"husky": "^6.0.0", "husky": "^6.0.0",
"i18next-chained-backend": "^3.0.2",
"lint-staged": "^11.0.0", "lint-staged": "^11.0.0",
"mocha": "^9.0.1", "mocha": "^9.0.1",
"nodemon": "^2.0.8", "nodemon": "^2.0.8",

View file

@ -15,6 +15,7 @@
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>. * along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/ */
import Command from '@structures/command'; import Command from '@structures/command';
import i18next from 'i18next';
import { transpile } from 'typescript'; import { transpile } from 'typescript';
import { NodeVM } from 'vm2'; import { NodeVM } from 'vm2';
@ -32,7 +33,7 @@ export class vm extends Command {
switch(vmLang.toLowerCase()) { switch(vmLang.toLowerCase()) {
case 'js': case 'js':
case 'javascript': case 'javascript':
await message.reply('Computing JavaScript code... Please wait!'); await message.reply(i18next.t('commands:vm.computing', { language: 'JavaScript' }));
try { try {
let returnVal: string; let returnVal: string;
@ -43,12 +44,12 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``); await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) { } 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; break;
case 'ts': case 'ts':
case 'typescript': case 'typescript':
await message.reply('Computing TypeScript code... Please wait!'); await message.reply(i18next.t('commands:vm.computing', { language: 'TypeScript' }));
try { try {
const jsCode = transpile(code); const jsCode = transpile(code);
@ -61,11 +62,11 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``); await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) { } 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; break;
default: default:
await message.reply('Unknown Language given!'); await message.reply(i18next.t('commands:vm.unknown'));
} }
} }
} }

View file

@ -26,6 +26,12 @@ import config from 'config';
import { Client, Collection } from 'discord.js'; import { Client, Collection } from 'discord.js';
import figlet from 'figlet'; import figlet from 'figlet';
import gradient from 'gradient-string'; 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 { Validator } from 'jsonschema';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import path from 'path'; import path from 'path';
@ -108,6 +114,27 @@ client.on('message', async (msg) => {
}); });
client.on('ready', async () => { 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); info('Loading commands...', ELoggingScope.Startup);
try { try {

View file

@ -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!"
}
}

View file

View file

@ -45,11 +45,10 @@
"listEmittedFiles": false, "listEmittedFiles": false,
"listFiles": false, "listFiles": false,
"newLine": "lf", "newLine": "lf",
"noEmitOnError": true, "noEmitOnError": false,
"preserveConstEnums": true, "preserveConstEnums": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"traceResolution": false, "traceResolution": false,
"sourceMap": true,
"inlineSourceMap": true, "inlineSourceMap": true,
"inlineSources": true, "inlineSources": true,
"baseUrl": ".", "baseUrl": ".",

View file

@ -234,6 +234,15 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "@babel/template@npm:^7.14.5":
version: 7.14.5 version: 7.14.5
resolution: "@babel/template@npm:7.14.5" resolution: "@babel/template@npm:7.14.5"
@ -866,6 +875,15 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "@types/json-schema@npm:*, @types/json-schema@npm:^7.0.7":
version: 7.0.7 version: 7.0.7
resolution: "@types/json-schema@npm:7.0.7" resolution: "@types/json-schema@npm:7.0.7"
@ -1551,6 +1569,7 @@ __metadata:
"@types/eslint": ^7.2.13 "@types/eslint": ^7.2.13
"@types/figlet": ^1.5.1 "@types/figlet": ^1.5.1
"@types/gradient-string": ^1.1.1 "@types/gradient-string": ^1.1.1
"@types/i18next-fs-backend": ^1.0.0
"@types/luxon": ^1.27.0 "@types/luxon": ^1.27.0
"@types/mocha": ^8.2.2 "@types/mocha": ^8.2.2
"@types/module-alias": ^2.0.0 "@types/module-alias": ^2.0.0
@ -1575,6 +1594,10 @@ __metadata:
figlet: ^1.5.0 figlet: ^1.5.0
gradient-string: ^1.2.0 gradient-string: ^1.2.0
husky: ^6.0.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 jsonschema: ^1.4.0
lint-staged: ^11.0.0 lint-staged: ^11.0.0
luxon: ^1.27.0 luxon: ^1.27.0
@ -3448,6 +3471,29 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "foreground-child@npm:^2.0.0":
version: 2.0.0 version: 2.0.0
resolution: "foreground-child@npm:2.0.0" resolution: "foreground-child@npm:2.0.0"
@ -4028,6 +4074,50 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "iconv-lite@npm:^0.6.2":
version: 0.6.3 version: 0.6.3
resolution: "iconv-lite@npm:0.6.3" resolution: "iconv-lite@npm:0.6.3"
@ -6412,6 +6502,13 @@ __metadata:
languageName: node languageName: node
linkType: hard 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": "regexpp@npm:^3.1.0":
version: 3.2.0 version: 3.2.0
resolution: "regexpp@npm:3.2.0" resolution: "regexpp@npm:3.2.0"