Skip to content

Commit

Permalink
added language translations
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Jun 1, 2023
1 parent 2c0fece commit 3c2c9f2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/commands/admin/set-channel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "node:path";
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType } from "discord.js";
import { QuickDB } from "quick.db";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
Expand All @@ -14,12 +15,14 @@ const db = new QuickDB({
export default {
data: new SlashCommandBuilder()
.setName("set-channel")
.setDescription("Sets the couting channel.")
.setDescription(translations.set_channel.desc)
.setDescriptionLocalizations(translations.set_channel.translations)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption((option) =>
option.setName("channel")
.setDescription("Channel name")
.setDescription(translations.set_channel.options.channel.desc)
.setDescriptionLocalizations(translations.set_channel.options.channel.translations)
.setRequired(true)),

/**
Expand Down
16 changes: 12 additions & 4 deletions src/commands/admin/set-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "node:path";
import fs from "node:fs";
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { QuickDB } from "quick.db";
import translations from "../../../locales/commands/translations.js";

// ========================= //
// = Copyright (c) NullDev = //
Expand All @@ -11,10 +12,15 @@ const db = new QuickDB({
filePath: path.resolve("./data/guild_data.sqlite"),
});

/**
* Get all available languages
*
* @return {Array<{ name: string, value: string }>}
*/
const getLanguages = function(){
const languages = fs.readdirSync(path.resolve("./locales"));

return languages.map((lang) => ({
return languages.filter((lang) => lang.endsWith(".json")).map((lang) => ({
name: lang.split("_")[0],
value: lang.split(".")[0],
}));
Expand All @@ -23,12 +29,14 @@ const getLanguages = function(){
export default {
data: new SlashCommandBuilder()
.setName("set-language")
.setDescription("Sets the server language for the bot.")
.setDescription(translations.set_language.desc)
.setDescriptionLocalizations(translations.set_language.translations)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption((option) =>
option.setName("language")
.setDescription("Server language")
.setDescription(translations.set_language.options.language.desc)
.setDescriptionLocalizations(translations.set_language.options.language.translations)
.setRequired(true)
.addChoices(...getLanguages())),

Expand Down
9 changes: 6 additions & 3 deletions src/commands/admin/set-timeout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "node:path";
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { QuickDB } from "quick.db";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
Expand All @@ -14,12 +15,14 @@ const db = new QuickDB({
export default {
data: new SlashCommandBuilder()
.setName("set-timeout")
.setDescription("Configure a timeout for losers")
.setDescription(translations.set_timeout.desc)
.setDescriptionLocalizations(translations.set_timeout.translations)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addIntegerOption((option) =>
option.setName("timeout")
.setDescription("Timeout in minutes or 0 to disable")
.setDescription(translations.set_timeout.options.timeout.desc)
.setDescriptionLocalizations(translations.set_timeout.options.timeout.translations)
.setRequired(true)),

/**
Expand Down
9 changes: 6 additions & 3 deletions src/commands/admin/toggle-arithmetic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "node:path";
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { QuickDB } from "quick.db";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
Expand All @@ -14,12 +15,14 @@ const db = new QuickDB({
export default {
data: new SlashCommandBuilder()
.setName("toggle-arithmetic")
.setDescription("Arithmetic expressions enabled?")
.setDescription(translations.toggle_arithmetic.desc)
.setDescriptionLocalizations(translations.toggle_arithmetic.translations)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addBooleanOption((option) =>
option.setName("enabled")
.setDescription("Enable arithmetic expressions")
.setDescription(translations.toggle_arithmetic.options.enabled.desc)
.setDescriptionLocalizations(translations.toggle_arithmetic.options.enabled.translations)
.setRequired(true)),

/**
Expand Down
4 changes: 3 additions & 1 deletion src/commands/user/info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os from "node:os";
import { SlashCommandBuilder } from "discord.js";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
Expand All @@ -9,7 +10,8 @@ import __ from "../../service/i18n.js";
export default {
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Shows Info about this bot.")
.setDescription(translations.info.desc)
.setDescriptionLocalizations(translations.info.translations)
.setDMPermission(false),
/**
* @param {import("discord.js").CommandInteraction} interaction
Expand Down
7 changes: 5 additions & 2 deletions src/commands/user/stats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "node:path";
import { SlashCommandBuilder } from "discord.js";
import { QuickDB } from "quick.db";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
Expand All @@ -14,11 +15,13 @@ const db = new QuickDB({
export default {
data: new SlashCommandBuilder()
.setName("stats")
.setDescription("Shows your or another users stats.")
.setDescription(translations.stats.desc)
.setDescriptionLocalizations(translations.stats.translations)
.setDMPermission(false)
.addUserOption((option) =>
option.setName("user")
.setDescription("The user to show stats for")
.setDescription(translations.stats.options.user.desc)
.setDescriptionLocalizations(translations.stats.options.user.translations)
.setRequired(false)),
/**
* @param {import("discord.js").CommandInteraction} interaction
Expand Down
15 changes: 10 additions & 5 deletions src/commands/user/top.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from "node:path";
import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder } from "discord.js";
import { QuickDB } from "quick.db";
import __ from "../../service/i18n.js";
import generateImage from "../../service/topImageGenerator.js";
import translations from "../../../locales/commands/translations.js";
import __ from "../../service/i18n.js";

// ========================= //
// = Copyright (c) NullDev = //
Expand All @@ -15,17 +16,21 @@ const db = new QuickDB({
export default {
data: new SlashCommandBuilder()
.setName("top")
.setDescription("Shows the top 10 users with most points.")
.setDescription(translations.top.desc)
.setDescriptionLocalizations(translations.top.translations)
.setDMPermission(false)
.addStringOption((option) =>
option.setName("sort")
.setDescription("Sort by")
.setDescription(translations.top.options.sort.desc)
.setDescriptionLocalizations(translations.top.options.sort.translations)
.setRequired(false)
.addChoices({
name: "Correct counts",
name: translations.top.options.sort.choices.wins.desc,
name_localizations: translations.top.options.sort.choices.wins.translations,
value: "wins",
}, {
name: "Failed counts",
name: translations.top.options.sort.choices.fails.desc,
name_localizations: translations.top.options.sort.choices.fails.translations,
value: "fails",
})),
/**
Expand Down

0 comments on commit 3c2c9f2

Please sign in to comment.