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

i18n-js

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-js - npm Package Compare versions

Comparing version 4.0.0-alpha.11 to 4.0.0-alpha.12

json/af.json

3

package.json
{
"name": "i18n-js",
"version": "4.0.0-alpha.11",
"version": "4.0.0-alpha.12",
"description": "A small library to provide I18n on JavaScript.",

@@ -12,2 +12,3 @@ "main": "./dist/import/index.js",

"dist/**/*",
"json/**/*",
"typings/**/*"

@@ -14,0 +15,0 @@ ],

@@ -11,3 +11,3 @@ <p align="center">

<a href="https://github.com/fnando/i18n/actions?query=workflow%3Atests"><img src="https://github.com/fnando/i18n/workflows/tests/badge.svg" alt="Tests"></a>
<a href="https://www.npmjs.com/package/i18n-js"><img src="https://img.shields.io/npm/v/i18n-js.svg" alt="npm version"></a>
<a href="https://www.npmjs.com/package/i18n-js"><img src="https://img.shields.io/npm/v/i18n-js/next.svg" alt="npm version"></a>
<a href="https://www.npmjs.com/package/i18n-js"><img src="https://img.shields.io/npm/dt/i18n-js.svg" alt="npm downloads"></a>

@@ -30,3 +30,3 @@ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>

```js
import { I18n } from "i18n";
import { I18n } from "i18n-js";
import translations from "./translations.json";

@@ -958,2 +958,55 @@

## Troubleshooting
### I'm getting an error like `SyntaxError: Unexpected end of JSON input` or `Uncaught SyntaxError: Unexpected token ;`
You may get such error if you're trying to load empty JSON files with
`import data from "file.json"`. This has nothing to do with I18n and is related
to how your JSON file is loaded. **JSON files must contain valid JSON data.**
Similarly, make sure you're writing valid JSON, and not JavaScript. For
instance, if you write something like `{};`, you'll get an error like
`Uncaught SyntaxError: Unexpected token ;`.
### My JSON contains a flat structure. How can I load and use it with I18n.js?
I18n.js expects a nested object to represent the translation tree. For this
reason, you cannot use an object like the following by default:
```json
{
"en.messages.hello": "hello",
"pt-BR.messages.hello": "olá"
}
```
One solution is using something like the following to transform your flat into a
nested object:
```js
const { set } = require("lodash");
const from = {
"en.messages.hello": "hello",
"pt-BR.messages.hello": "olá",
};
function flatToNestedObject(target) {
const nested = {};
Object.keys(target).forEach((path) => set(nested, path, target[path]));
return nested;
}
console.log(flatToNestedObject(from));
// {
// en: { messages: { hello: 'hello' } },
// 'pt-BR': { messages: { hello: 'olá' } }
// }
```
You can also use something like [flat](https://github.com/hughsk/flat) to
perform the same transformation.
## License

@@ -960,0 +1013,0 @@

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