npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mlbrgn/translator

v1.0.18

Published

A small JavaScript library to translate webpages into different languages

Readme

Translator

docs generated using Junie AI

A small JavaScript library to translate webpages into different languages.

Overview

Translator is a lightweight library that helps you implement multilingual support in your web applications. It can automatically detect the user's language, load translation files, and apply translations to your HTML elements.

Key Features

  • Language Detection: Automatically detects the user's preferred language based on browser settings
  • Persistence: Optionally saves the selected language in localStorage
  • Dynamic Translation: Translates elements added to the DOM after initial load using MutationObserver
  • Fallback Support: Provides fallback language and translations when needed
  • Global Translation Function: Exposes a global translation function for use in JavaScript
  • Flexible Configuration: Customizable options for language paths, supported languages, and more

Installation

npm install @mlbrgn/translator

Usage

Basic Setup

import { Translator } from '@mlbrgn/translator';

const translator = new Translator({
  rootElement: document.body, // only searches for translatable items inside this element
  fallbackLanguage: 'en',
  detectLanguage: true,
  persist: true,
  languagesSupported: ['en', 'nl', 'fr'],
  languagesPath: '/lang'
});

HTML Markup

Add data-i18n attributes to elements you want to translate:

<h1 data-i18n="welcome">Welcome</h1>
<p data-i18n="intro">This text will be translated</p>

<!-- Translate attributes -->
<input data-i18n-placeholder="email" placeholder="Enter your email">

<!-- Translate with parameters -->
<p data-i18n="greeting" data-i18n-params='{"name":"John"}'>Hello, John!</p>

Translation Files

Create JSON files for each language in your languagesPath directory:

/* File: /lang/en.json */
{
  "welcome": "Welcome",
  "intro": "This text will be translated",
  "email": "Enter your email",
  "greeting": "Hello, {{name}}!"
}
/* File: /lang/nl.json */
{
  "welcome": "Welkom",
  "intro": "Deze tekst wordt vertaald",
  "email": "Voer je e-mailadres in",
  "greeting": "Hallo, {{name}}!"
}

Switching Languages

// Switch to Dutch
translator.use('nl');

// Get current language
const currentLang = translator.activeLanguage;

Using the Translation Function in JavaScript

// If exposeFnName is set to '__' in the config
const message = __('welcome');

// Or use the translator instance directly
const message = translator._('welcome');

// With parameters
const greeting = translator._('greeting', { name: 'Jane' });

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | rootElement | Element | document | Element to search for translatable items | | fallbackTranslations | Object | null | Used when fetching translations fails | | fallbackLanguage | String | 'en' | Language to use when preferred language is not available | | detectLanguage | Boolean | true | Whether to detect user's language from browser | | persist | Boolean | false | Whether to save language preference in localStorage | | persistKey | String | 'active_language' | Key to use for localStorage | | languagesSupported | Array | ['en', 'nl'] | List of supported language codes | | languagesPath | String | null | Path to translation JSON files | | exposeFnName | String | '__' | Name of global translation function | | debug | Boolean | false | Enable debug logging |

Development

This package is developed inside the mlbrgn-node-workspace monorepo. Do not run npm run dev or npm install inside this repository.

Clone the monorepo instead: https://github.com/evertjanmlbrgn/mlbrgn-node-workspace