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

@localjs/localjs

v1.7.0

Published

A Javascript library for localization and globalization to make any website multilinguil with ease

Readme

LocalJS

LocalJS is a lightweight JavaScript library for easy localization of HTML elements. It allows you to replace specific words or phrases with translations based on the selected language.

Features

  • Simple and intuitive Library for HTML localization
  • Dynamic replacement of words or phrases with translations
  • Supports multiple languages and customizable translations
  • Lightweight and easy to integrate with existing projects

Installation

You can install LocalJS using npm. Run the following command in your project directory:

npm i @localjs/localjs

Alternatively, you can use the following CDN link to include LocalJS directly in your HTML file:

// JSDeliver
<script src="https://cdn.jsdelivr.net/npm/@localjs/localjs@stable/localjs.js"></script>
// unpkg
<script src="https://unpkg.com/@localjs/localjs@stable/localjs.js"></script>

Usage

Initialization

To start using LocalJS, follow these steps:

Include the LocalJS script in your HTML file:

<script src="node_modules/@localjs/localjs/dist/localjs.js"></script>
  1. Add the translate attribute to the HTML elements you want to localize.

      <h1 translate>Sloka of the Day</h1>
      <p translate>Today's sloka is a beautiful verse.</p>
  2. Initialize the library with the desired translations and language selector. For example:

    <script>
      var translations = {
        "Sloka of the Day": {
          "en": "Sloka of the Day",
          "hi": "आज का श्लोक",
          "te": "నేటి శ్లోకం"
        },
        "Today's sloka is a beautiful verse": {
          "en": "Today's sloka is a beautiful verse",
          "hi": "आज का श्लोक एक सुंदर श्लोक है।",
          "te": "నేటి శ్లోకం ఒక అందమైన శ్లోకం."
        }
      };
    
      localjs.init("en", translations);
    </script>

Functions

The LocalJS library provides the following methods:

init(language, translations)

Initialize the library with the language and translations.

  • language (string): language id

update(language, translations)

Update the localization with a new language and translations.

  • language (string): language id

Supported Languages

LocalJS supports multiple languages. You can add any language translations you want by providing the language code and corresponding translations.

Example

| Language | Code | | ---------- | ---- | | English | en | | Telugu | te | | Hindi | hi | | Tamil | ta | | Kannada | kn | | Malayalam | ml | | Bengali | bn | | Gujarati | gu | | Marathi | mr | | Punjabi | pa | | Urdu | ur | | Spanish | es | | French | fr | | German | de | | Italian | it | | Portuguese | pt | | Dutch | nl | | Russian | ru | | Japanese | ja | | Korean | ko |

translations (object): An object containing the translations for the words or phrases you want to replace.

Example

Here's an example implementation of LocalJS:

{
  "Sloka of the Day": {
    "en": "Sloka of the Day",
    "hi": "आज का श्लोक",
    "te": "నేటి శ్లోకం"
  },
  "Today's sloka is a beautiful verse": {
    "en": "Today's sloka is a beautiful verse",
    "hi": "आज का श्लोक एक सुंदर श्लोक है।",
    "te": "నేటి శ్లోకం ఒక అందమైన శ్లోకం."
  },
  "Select Language": {
    "en": "Select Language",
    "hi": "भाषा चुनें",
    "te": "భాషను ఎంచుకోండి"
  }
}

Demos

Demo 1


<!DOCTYPE html>
<html>
<head>
  <title>LocalJS Example</title>
  <script src="path/to/localjs.js"></script>
</head>
<body>
  <h1 translate>Sloka of the Day</h1>
  <p translate>Today's sloka is a beautiful verse.</p>

  <script>
    var translations = {
      "Sloka of the Day": {
        "en": "Sloka of the Day",
        "hi": "आज का श्लोक",
        "te": "నేటి శ్లోకం"
      },
      "Today's sloka is a beautiful verse": {
        "en": "Today's sloka is a beautiful verse",
        "hi": "आज का श्लोक एक सुंदर श्लोक है।",
        "te": "నేటి శ్లోకం ఒక అందమైన శ్లోకం."
      }
    };

    localjs.init("en", translations);
  </script>
</body>
</html>

Demo 2 (with language select dropdown)


<!DOCTYPE html>
<html>
<head>
  <title>Localization Example</title>
  <meta charset="UTF-8"> <!-- Add this line to specify the character encoding -->
</head>
<body>
  <h1 translate>Sloka of the Day</h1>
  <p translate>Today's sloka is a beautiful verse.</p>

  <h4 translate>Sloka of the Day</h4>

  <h2>Hello</h2>
  
  <div>
    <label for="languageSelector" translate>Select Language:</label>
    <select id="languageSelector">
      <option value="en">English</option>
      <option value="hi">Hindi</option>
      <option value="te">Telugu</option>
    </select>
  </div>

  <script src="path/to/localjs.js"></script>

  <script>
    var translations = {
      "Sloka of the Day": {
        "en": "Sloka of the Day",
        "hi": "आज का श्लोक",
        "te": "నేటి శ్లోకం"
      },
      "Today's sloka is a beautiful verse": {
        "en": "Today's sloka is a beautiful verse",
        "hi": "आज का श्लोक एक सुंदर श्लोक है।",
        "te": "నేటి శ్లోకం ఒక అందమైన శ్లోకం."
      },
      "Select Language": {
        "en": "Select Language",
        "hi": "भाषा चुनिए",
        "te": "భాషను ఎంచుకోండి"
      }
    };

    var languageSelector = document.getElementById("languageSelector");
    var initialLanguage = languageSelector.value;

    localjs.init(initialLanguage, translations);

    languageSelector.addEventListener("change", function() {
      var selectedLanguage = languageSelector.value;
      localjs.update(selectedLanguage, translations);
    });
  </script>
</body>
</html>