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 🙏

© 2024 – Pkg Stats / Ryan Hefner

loc-i18next

v0.1.6

Published

Smart selectors to be used with i18next

Downloads

4,698

Readme

loc-i18next

Introduction

A replicate of jquery-i18next module (which is great by the way!), intended for use without jquery.

Comparaison with jquery-i18next

jquery-i18next plugin :

jqueryI18next.init(i18nextInstance, $);
$(".nav").localize();

loc-i18next :

localize = locI18next.init(i18next);
localize(".nav");

Initialize the plugin

With options :

import i18next from 'i18next';
import locI18next from "loc-i18next";

const localize = locI18next.init(i18next, {
  selectorAttr: 'data-i18n', // selector for translating elements
  targetAttr: 'i18n-target',
  optionsAttr: 'i18n-options',
  useOptionsAttr: false,
  parseDefaultValueFromContent: true
  document: window.document,
});

Using default values :

import i18next from 'i18next';
import locI18next from "loc-i18next";

const localize = locI18next.init(i18next);

Using options in translation function

<a id="btn1" href="#" data-i18n="myKey"></a>
localize("#btn1", options);

or

<a id="btn1" href="#" data-i18n="myKey" i18n-options="{ 'a': 'b' }"></a>
localize("#btn1");

Usage of selector function

translate an element

<a id="btn1" href="#" data-i18n="myKey"></a>
localize("#btn1", options);

myKey: same key as used in i18next (optionally with namespaces) options: same options as supported in i18next.t

translate children of an element

<ul class="nav">
  <li><a href="#" data-i18n="nav.home"></a></li>
  <li><a href="#" data-i18n="nav.page1"></a></li>
  <li><a href="#" data-i18n="nav.page2"></a></li>
</ul>
localize(".nav");

translate some inner element

<div class="outer" data-i18n="ns:key" data-i18n-target=".inner">
  <input class="inner" type="text"></input>
</div>
localize(".outer");

set different attribute

<a id="btn1" href="#" data-i18n="[title]key.for.title"></a>
localize("#btn1");

set multiple attributes

<a id="btn1" href="#" data-i18n="[title]key.for.title;myNamespace:key.for.text"></a>
localize("#btn1");

set innerHtml attributes

<a id="btn1" href="#" data-i18n="[html]key.for.title"></a>
localize("#btn1");

prepend content

<a id="btn1" href="#" data-i18n="[prepend]key.for.title">insert before me, please!</a>
localize("#btn1");

append content

<a id="btn1" href="#" data-i18n="[append]key.for.title">append after me, please!</a>
localize("#btn1");

set as an attribute

<a id="btn1" href="#" data-i18n="[data-someNameAttribute]key.for.content"></a>
localize("#btn1");

use a custom document object

<template id="template">
  <a id="btn1" href="#" data-i18n="myKey"></a>
</template>
const shadowRoot = document.body.attachShadow();
const template = document.getElementById("template");
shadowRoot.appendChild(template.content.cloneNode(true));
localize("#btn1", {document: shadowRoot});

Motivation

  • Having an occasion to try some packages like rollup, babel or uglify.
  • Obtaining the same kind of functionnalities than with jquery-i18next in a project not using jquery.

Project actively using loc-i18next

Blog posts about using loc-i18next