1.7.4 • Published 3 years ago
discord.js-multilingual-utils v1.7.4
discord.js-Multilingual-Utils
Multilingual utilities for discord.js.
Installation
npm install discord.js-multilingual-utils
Importing
import { MultilingualService } from 'discord.js-multilingual-utils';
Example Language File
Language files should be named using the language code of their contents. For example:
lang.en.json
:
{
"default": {
"color": "0x0099ff"
},
"embeds": {
"example": {
"title": "{{REF:exampleTitle}}",
"description": [
"This is an example",
"",
"I can have new lines!",
"",
"This is an **{{EXAMPLE_VARIABLE}}**!",
"",
"{{REF:exampleReference}}"
],
"fields": [{ "name": "Example Field", "value": "This is an example field!" }]
}
},
"regexes": {
"example": "/\\b(example|ex)\\b/i"
},
"refs": {
"exampleTitle": "Example Embed",
"exampleReference": [
"This is an example reference!",
"",
"I can be a single line or have multiple lines!"
]
}
}
Example Usage
Code Example
import { Client } from 'discord.js';
import { MultilingualService } from 'discord.js-multilingual-utils';
import path from 'path';
let Config = require('../config/config.json');
let folderPath = path.join(__dirname, '../lang');
let multilingualService = new MultilingualService(folderPath);
let client = new Client();
client.on('ready', () => {
console.log(`Logged in as '${client.user.tag}'!`);
});
client.on('message', async msg => {
let args = msg.content.split(' ');
switch (args[0]) {
case 'testEmbed': {
let embed = multilingualService.getEmbed('example', 'en', {
EXAMPLE_VARIABLE: 'Example Variable',
});
await msg.channel.send(embed);
return;
}
case 'testRegex': {
let value = args[1];
if (!value) {
await msg.channel.send('Please enter a value to test.');
return;
}
let regex = multilingualService.getRegex('example', 'en');
let result = regex.test(args[1]);
if (result) {
await msg.channel.send('Value matched!');
return;
} else {
await msg.channel.send('Value did NOT match!');
return;
}
}
case 'testRef': {
let ref = multilingualService.getRef('exampleReference', 'en');
await msg.channel.send(ref);
return;
}
}
});
client.login(Config.token);
Embed Example
Regex Example
Reference Example
1.7.4
3 years ago
1.7.3
3 years ago
1.7.2
3 years ago
1.7.1
3 years ago
1.7.0
3 years ago
1.6.4
3 years ago
1.6.3
3 years ago
1.6.5
3 years ago
1.6.2
3 years ago
1.6.1
3 years ago
1.6.0
3 years ago
1.5.0
3 years ago
1.4.0
3 years ago
1.3.2
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.2.3
3 years ago
1.2.2
3 years ago
1.2.1
3 years ago
1.2.0
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.11
3 years ago
1.0.10
3 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago