Wondering what’s next for npm?Check out our public roadmap! »

    discord.js-multilingual-utils
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.2 • Public • Published

    discord.js-Multilingual-Utils

    NPM Version discord.js Version Downloads

    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:

    {
        "defaultEmbed": {
            "color": "0x0099ff"
        },
        "embeds": {
            "myCategory": {
                "example": {
                    "title": "{{REF:myCategory.exampleTitle}}",
                    "description": [
                        "This is an example",
                        "",
                        "I can have new lines!",
                        "",
                        "This is an **{{EXAMPLE_VARIABLE}}**!",
                        "",
                        "{{REF:myCategory.exampleReference}}"
                    ],
                    "fields": [{ "name": "Example Field", "value": "This is an example field!" }]
                }
            }
        },
        "regexes": {
            "myCategory": {
                "example": "/\\b(example|ex)\\b/i"
            }
        },
        "refs": {
            "myCategory": {
                "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('myCategory.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('myCategory.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('myCategory.exampleReference', 'en');
                await msg.channel.send(ref);
                return;
            }
        }
    });
    
    client.login(Config.token);

    Embed Example

    Embed Example

    Regex Example

    Regex Example

    Reference Example

    Reference Example

    Install

    npm i discord.js-multilingual-utils

    DownloadsWeekly Downloads

    8

    Version

    1.3.2

    License

    MIT

    Unpacked Size

    55.5 kB

    Total Files

    62

    Last publish

    Collaborators

    • avatar