
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@commandkit/i18n
Advanced tools
@commandkit/i18n
A commandkit plugin for i18next integration.
$ npm i @commandkit/i18n
Add the following to your commandkit config:
import { defineConfig } from "commandkit"
import { i18n } from "@commandkit/i18n"
export default defineConfig({
plugins: [i18n()]
})
You can pass options to the plugin:
import { defineConfig } from "commandkit"
import { i18n } from "@commandkit/i18n"
export default defineConfig({
plugins: [
i18n({
plugins: [i18nextPlugins]
})
]
})
Create locales
directory inside src/app
and add your translation files. The directory structure should look like this:
src
└── app
├── locales
│ ├── en-US
│ │ └── ping.json
│ └── fr
│ └── ping.json
└── commands
└── ping.ts
CommandKit automatically localizes your commands if you follow the naming convention and translation file structure.
If your translation file contains $command
key with localization object, it will be used to localize the command name and description.
{
"$command": {
"name": "Ping",
"description": "Ping the server",
"options": [
{
"name": "database",
"description": "Ping the database"
}
]
},
"response": "Pong! The latency is {{latency}}ms"
}
The $command
key defines localization for the command name and description (or options). These properties are later merged with the actual command to build the final command object with localizations that Discord understands. Anything else in the translation file is used to localize the command response.
This plugin adds locale()
function to your command context. You can use it to localize your command responses.
export const chatInput: SlashCommand = async (ctx) => {
// ctx.locale() auto infers the localization of the current guild
// you can also pass a discord.js locale enum to use custom locale
// ctx.locale("fr") // uses french locale
const { t, i18n } = ctx.locale()
// ^ TFunction
// ^ i18next instance
ctx.interaction.reply({
content: t("response", { latency: client.ping }),
ephemeral: true
})
}
Additionally, you can use the locale()
function outside of the context to get the localization api. This is mostly useful if you are using i18n
with legacy commands plugin.
import { locale } from "@commandkit/i18n"
export async function run({ interaction }) {
const { t } = locale()
return interaction.reply({
content: t("response", { latency: client.ping }),
ephemeral: true
})
}
This function is identical to the one in the context and it can also infer the locale automatically.
FAQs
CommandKit plugin that adds command localizations backed by i18next
The npm package @commandkit/i18n receives a total of 1,056 weekly downloads. As such, @commandkit/i18n popularity was classified as popular.
We found that @commandkit/i18n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.