Clone the .env.example
file and rename it to .env
. Then, fill in the required fields:
cp .env.example .env
Environment Variables
Environment Variable | Required |
---|---|
NODE_ENV |
No |
LOG_LEVEL |
No |
SAVE_LOGS |
No |
DISCORD_TOKEN |
Yes |
The localization is done using the typesafe-i18n, read the documentation for more information. Basically, you can create a folder for each language you want to support, and then execute the following command to generate the types:
pnpm run typesafe-i18n
Warning Make sure to always use the Discord's locales names for the language folders, otherwise the bot won't be able to organize the translations.
There's a dedicated namespace for commands, so you can simply add the keys to his respective file.
mergeTranslations
Helper
To avoid repeating spreading the main translations object, you can use the mergeTranslations
helper, which will merge the translations with the main object. This helper is especially useful when working with large and complex internationalization projects.
Example
// source/i18n/%LANGUAGE%/SLASH/index.ts
import { mergeTranslations } from '../../helpers';
export default mergeTranslations('SLASH', {
EXAMPLE_EXAMPLE_NAME: 'example',
EXAMPLE_EXAMPLE_DESCRIPTION: 'This is a useless example command.',
PATH_TO_ANOTHER_NAME: 'another',
PATH_TO_ANOTHER_DESCRIPTION: 'This is another useless example command.',
});
The commands are located in the source/modules
folder. The way to create a command is pretty much the same as in the discordx, the unique differences are the naming and the name
/description
fields, which are now localized.
akane | discordx |
---|---|
Command |
Slash |
Option |
SlashOption |
Group |
SlashGroup |
Example
import { ChatInputCommandInteraction } from 'discord.js';
import { Discord } from 'discordx';
import { Command } from '@libraries/localization';
@Discord()
class Moderation {
// Implicitly the prefix for name and description translation
// paths will be `MODERATION_BAN_`.
@Command()
ban(interaction: ChatInputCommandInteraction) {
/** ... */
}
// Explicitly set the paths for name and description translations.
@Command({
name: 'PATH_TO_ANOTHER_NAME',
description: 'PATH_TO_ANOTHER_DESCRIPTION',
})
kick(interaction: ChatInputCommandInteraction) {
/** ... */
}
}
export default Moderation;