Nerexon - Langpack

Warning

This website does not use Langpack, as it is not designed for static websites.

Information

What is Langpack?

Langpack is a lightweight Node.js module for translating JavaScript applications. It is fast, easy to use, and requires no external dependencies. Translations are stored in simple JSON files and accessed through a key-based system with optional placeholder replacement.

Documentation

Installation

Install Langpack using npm:

npm install langpack.js

Preparation

Create a directory named languages with your translation files:

languages/
  en.json
  fr.json

Then, import and initialize the language manager with the path to your directory:

const { LanguageManager } = require('langpack.js');
const manager = new LanguageManager('./languages');

Translation Usage

To retrieve translations, use the get method. It accepts the locale, the key, and an optional object of variables to replace:

manager.get("en", "user.welcome", { user: "John" }); // "Welcome John!"

Example Translation File

Here is a simple example of a translation JSON file:

{
  "user": {
    "welcome": "Welcome {user}!",
    "notification": "You received {count} notifications."
  }
}