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

i18n-switch

v2.0.2

Published

I18NSwitch is a vanilla JavaScript based component to make internationalization using two languages easier on web pages.

Downloads

165

Readme

I18NSwitch

I18NSwitch is a vanilla JavaScript based component to make internationalization using two languages easier on web pages.

This component will automatically change between two languages everytime user clicks on the switch.

Everytime the switch changes, it'll look for the elements on your page that has the data-i18n attribute, and change its text by the one you configured on the object constructor.

Instalation

You can easily import the component into your page on the following ways.

CDN

Copy-paste the stylesheet into your head tag after all other stylesheets.

<link href="https://unpkg.com/[email protected]/style/I18NSwitch.css" rel="stylesheet"/>

Copy-paste the script into the end of your body tag.

<script src="https://unpkg.com/[email protected]/script/I18NSwitch.js"></script>

NPM

npm i i18n-switch

Constructor

new I18NSwitch(id, main, secondary, general)

Construct and initialize your switch using the following Argument:

id - Div's id in which the switch will be built.

main and secundary - Objects that contains the flag and the content that will override your page content with the following structure:

{
    flag: "An image url",
    language: {
        key: value,
        key: value,
        key: value
    }
}

The key values on the language object it is the value the component will look for as value for the data-i18n attribute in all page elements, and the value it is the content that will override the previous one.

general - (Optional argument) Object that contains the content that will override your page content if is no defined by the main or the secondary languages.

Example:


const langSwitch = new I18NSwitch(
    "container-id",
    {
        flag: "/assets/example1.png",
        language: {
            "hello": "Olá!"
        }
    },
    {
        flag: "/assets/example2.png",
        language: {
            "hello": "Hello!"
        }
    },
    {
        "bye": "Sayonara";
    }
);

CountryFlags

An enum of country flags, this is all available indexes:

  • BRAZIL
  • CHINA
  • FRANCE
  • GERMANY
  • INDIA
  • ITALY
  • JAPAN
  • PORTUGAL
  • RUSSIA
  • SPAIN
  • UNITED_KINGDOM
  • UNITED_STATES

Example of use:

const brazilFlag = CountryFlags.BRAZIL;

Functions

isMainLanguageOn

Returns true if the main language is selected.

isSecondaryLanguageOn

Returns true if the secondary language is selected.

change

Changes the language without clicking on the switch.

Listeners

onChange

Triggers every change between languages.

Example on static web pages

<!DOCTYPE html>
<html>
    <head>
        <title>I18N Switch</title>
        <link rel="stylesheet" href="https://unpkg.com/[email protected]/style/I18NSwitch.css">
    </head>
    <body>
        <!-- The container where the switch will be built -->
        <div id="i18n-switch"></div>

        <!-- A mapped field, that will receve content from the switch -->
        <p data-i18n="hello"></p>


        <script src="https://unpkg.com/[email protected]/script/I18NSwitch.js"></script>
        <script>

            //Variables that contains the content that will be used to configure the component
            const english = {};
            const portuguese = {
                "hello": "Olá mundo!"
            };
            const general = {
                "hello": "Hello world!"
            };

            //The content constructor.
            const langSwitch = new I18NSwitch(
                "i18n-switch",
                {
                    flag: CountryFlags.UNITED_STATES,
                    language: english
                },
                {
                    flag: CountryFlags.BRAZIL,
                    language: portuguese
                },
                general
            );

            //Some demonstration on how to use some functions
            langSwitch.onChange(() => {
                if(langSwitch.isMainLanguageOn()){
                    console.log("main");
                }else if(langSwitch.isSecondaryLanguageOn()){
                    console.log("secondary");
                }
            });

        </script>
    </body>
</html>

And this is how it will looks like:

alt text

Mentions

The flag images used on the project and others can be found for free on the following link: https://www.flaticon.com/packs/country-flags-icons