New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

i18next-resource-store-loader

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-resource-store-loader

a resStore loader for webpack and i18next

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 19 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc