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

i18next-resource-store-loader

v0.1.3

Published

a resStore loader for webpack and i18next

Downloads

18,079

Readme

Deprecated Package

we don't activley use this package anymore as now overloading has become way more easy by requiring json data directly. By flattening key and exploding seperate files into the "resources structure" you can basically achieve the same if you want you i18next ressource bundled

import germanBaseTrans from './translation-gen/de/de-base.json';
import englishBaseTrans from './translation-gen/en/en-base.json';

const germanTrans = {
  ...germanBaseTrans,
};

const englishTrans = {
  ...englishBaseTrans,
};

...
  i18n
    .init({
      resources: {
        de: {
          translation: germanTrans,
        },
        en: {
          translation: englishTrans,
        },
      },
      ...
    })

i18next-resource-store-loader

npm install i18next-resource-store-loader

This loader generates the resStore config needed for i18next to avoid loading language resources via extra HTTP requests. It generates this config given a directory.

Usage

In this example we will assume the following file structure:

└── app
    └── src
        ├── assets
        │   └── i18n
        │       ├── index.js
        │       ├── de
        │       │   └── translation.json
        │       └── en
        │           └── translation.json
        └── js
            └── main.js

Use the loader in the following way:

// File: main.js
var i18n = require("i18next");
var resBundle = require("i18next-resource-store-loader!../assets/i18n/index.js");

i18n.init({
  resources: resBundle,
});

// Use the resources as documented on i18next.com
i18n.t("key");

For older versions of i18n < 2.X, use the old property names while setting up i18n

// File: main.js
var i18n = require("i18next-client");
var resBundle = require("i18next-resource-store-loader!../assets/i18n/index.js");

i18n.init({
  resStore: resBundle,
});

// Use the resources as documented on i18next.com
// e.g. 'translation' namespace
i18n.t("translation:key");

And you're done! The index.js can be empty, it's just needed to point the loader to the root directory of the locales.

Advanced Usage

Filter

You can filter files in your file structure using include and exclude parameters:

// will only load files with json extension
var resBundle = require("i18next-resource-store-loader" +
  "?include=\\.json$!../assets/i18n/index.js");
// will skip files with json extension
var resBundle = require("i18next-resource-store-loader" +
  "?exclude=\\.json$!../assets/i18n/index.js");

Override

In cases of customized applications it may be handy to have an easy way to replace particular parts of the res store bundle with customized values. The loader supports that by two query parameters.

// will replace everyhting from base with what is existent in override
var resBundle = require("i18next-resource-store-loader" +
  "?overrideDir=override&baseDir=base!../assets/i18n/index.js");

This configures the loader to work on a file structure like the following:

└── app
    └── src
        ├── assets
        │   └── i18n
        │       ├── index.js
        │       ├── base
        │       │   ├── de
        │       │   │   └── translation.json
        │       │   └── en
        │       │       └── translation.json
        │       └── override
        │           └── en
        │               └── translation.json
        │
        └── js
            └── main.js

Everthing from base/en/translation.js will be overridden with stuff noted in override/en/translation.js - partial overrides are possible.