Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@alienfast/i18next-loader
Advanced tools
Webpack loader for client embedded i18next locales from json or yaml.
yarn add -D @alienfast/i18next-loader
This webpack loader generates the resources
structure necessary for i18next. The structure is webpacked with the client bundle at build time, thus avoiding loading any language resources via extra HTTP requests.
Given a locales directory, by default, the loader will find and parse any json|yaml|yml
file and attribute the
contents to the containing lang folder e.g. en
. There is no need to add lang such as en
or de
inside your
json
or yaml
files.
See the test/data
directory for structure and example data.
└── app
└── src
│ └── app.js
└── locales
├── index.js
├── de
│ ├── foo.json
│ └── bar.yaml
└── en
├── foo.json
└── bar.yaml
module.exports = {
// ... snip
module: {
rules: [
{
test: /locales/,
loader: '@alienfast/i18next-loader',
// options here
//query: { overrides: [ '../node_modules/lib/locales' ] }
}
]
}
// ... snip
}
// File: app.js
import i18n from 'i18next'
import resources from '../locales' // typescript: import * as resources from '../locales'
i18n.init({
resources
});
// Use the resources as documented on i18next.com
i18n.t('key')
// File: app.js
import i18n from 'i18next'
import resources from '@alienfast/i18next-loader!../locales/index.js'
i18n.init({
resources
});
// Use the resources as documented on i18next.com
i18n.t('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.
Options are set via the loader query
. See webpack documentation for more details regarding how this mechanism works.
The following examples assume you understand these values are used as the query
value.
You can filter files in your file structure by specifying any glob supported by glob-all
.
By default, any json|yaml|yml
will be loaded.
{include: ['**/*.json']}
{include: ['**/*.json', '!**/excludeThis.json']}
Applications that reuse libraries e.g. white labeling, can utilize one to many sets of locale directories that the app will override.
{overrides: ['../node_modules/lib1/locales']}
This configures the loader to work on a file structure like the following:
└── app
├── src
│ └── app.js
├── locales
│ ├── index.js
│ └── en
│ ├── foo.json
│ └── bar.yaml
└── node_modules
└── lib1
└── locales
├── index.js
└── en
├── foo.json
└── bar.yaml
Everything from app/locales
will override anything specified in one to many libraries.
{basenameAsNamespace: true}
The following file structure would result in resources loaded as below:
└── app
├── src
│ └── app.js
└── locales
├── index.js
└── en
├── foo.json
└── bar.yaml
foo.json
{
"header": {
"title": "TITLE"
}
}
bar.yaml
footer:
aboutUs: About us
Results in this object loaded:
"en": {
"foo": {
"header": {
"title":"TITLE"
}
},
"bar": {
"footer":{
"aboutUs":"About us"
}
}
}
This was forked from i18next-resource-store-loader because
we changed it in breaking ways that are incompatible.
Thanks to the original authors and contributors.
FAQs
Webpack loader for client embedded i18next locales from json or yaml.
The npm package @alienfast/i18next-loader receives a total of 4,800 weekly downloads. As such, @alienfast/i18next-loader popularity was classified as popular.
We found that @alienfast/i18next-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.