Supporting different languages
Seyfert has a i18n built-in feature that allows you to create language files and use them in your bot.
For this section we are going to follow the setup we did in Getting Started for example purposes
Updating seyfert config
Before starting this chapter we could update seyfert.config.mjs
to tell seyfert where our languages file will be.
Creating a language file
Each language file shall export by default an object containing the translations for the language.
You can create as many language files as you want, seyfert will load them and they will be available to use in your bot.
Each key should return either a string or a function that returns a string.
The name of the file will be the language code, that you will use to get the language translations.
Next we must do some updates to the declare module
on index file:
Preventing errors
You can assign a default language to avoid getting undefined
.
You can pass any of the language files to the DefaultLocale
interface since they should be the same object structure.
After doing this, you can use the language in your commands, events, components, etc.
Using translations in your commands
Let's see an example with our ping
command by adding an option to respond in a specific language
Below is the current file tree of the project if you did follow the previous steps.