PluginsLocalizationExamples

Examples

Simple usage

index.ts
// Import the module
import Localization from "@kyrobot/localization";

// Create a new Localization class
const locale = new Localization({
  path: "languages", // Where your languages are stored. You must specify the directory without the root directory.
  autoReload: true, // If the module should auto reload the languages.
  autoReloadInterval: 3000, // The interval in milliseconds between reloading.
});

await locale.init();

// Now you can get translations! See the directory of the module for the rest of the functions
locale.getKey("en", "some.very.deep.path.object.to.the.translation");
WARNING

Make sure to call the .init() function or else your locales won't load and therefore cannot be used.

Usage with placeholders

en.json
{
  "welcome": "Welcome to the server, {member}!"
}
index.js
getKey("en", "welcome", {
  member: member.user.username,
});

// Welcome to the server, Aezen!

Last updated on