Naughty Pinching Mannequins

    This package has been deprecated

    Author message:

    discord.js-Multilingual-Utils has been deprecated in favor of Linguini, a more flexible and feature-rich evolution of discord.js-Multilingual-Utils. For more information please read the deprecation notice here: https://github.com/KevinNovak/discord.js-Multilingual-Utils#deprecation-notice

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

    1.7.4 • Public • Published

    discord.js-Multilingual-Utils

    NPM Version discord.js Version Downloads

    Multilingual utilities for discord.js.

    Deprecation Notice

    This package has been deprecated in favor of Linguini, a more flexible and feature-rich evolution of discord.js-Multilingual-Utils.

    To replicate discord.js-Multilingual-Utils's functionality, you'll need to implement a Custom Type Mapper with Linguini.

    Here is an example of how you can use Linguini to replace discord.js-Multilingual-Utils:

    import { MessageEmbed } from 'discord.js';
    import { Linguini, Utils } from 'linguini';
    
    // ...
    
    // Creating a custom MessageEmbed Type Mapper
    let messageEmbedTm = jsonValue => {
        return new MessageEmbed({
            author: jsonValue.author,
            title: Utils.join(jsonValue.title, '\n'),
            url: jsonValue.url,
            thumbnail: jsonValue.thumbnail,
            description: Utils.join(jsonValue.description, '\n'),
            fields: jsonValue.fields?.map(field => ({
                name: Utils.join(field.name, '\n'),
                value: Utils.join(field.value, '\n'),
            })),
            image: jsonValue.image,
            footer: {
                text: Utils.join(jsonValue.footer?.text, '\n'),
                iconURL: Utils.join(jsonValue.footer?.icon, '\n'),
            },
            timestamp: jsonValue.timestamp ? Date.now() : undefined,
            color: jsonValue.color ?? '#0099ff',
        });
    };
    
    // ...
    
    // Using our custom Type Mapper to get an embed:
    let myEmbed = linguini.get('myCategory.example', 'en', messageEmbedTm);

    See Linguini's documentation for more information.

    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({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
    
    client.on('ready', () => {
        console.log(`Logged in as '${client.user.tag}'!`);
    });
    
    client.on('messageCreate', 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({ embeds: [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

    41

    Version

    1.7.4

    License

    MIT

    Unpacked Size

    38.5 kB

    Total Files

    30

    Last publish

    Collaborators

    • kevinnovak