Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
/node_modules
/.tool-versions
/.yarnrc.yml

# Ignore Intellij settings
.idea/*
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Prefix your message with one of the following:
All notable changes to this project will be documented in this file. This
project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- [Changed] Update lodash to lodash-es for better tree-shaking.
- [Changed] Update `jest` configuration to leverage `@babel/preset-env` for ESM module support.

## v4.5.3 - Mar 4, 2026

- [Fixed] Handle BigNumber raising when receiving invalid numbers by default on
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,57 @@ i18n.toSentence(["apple", "banana", "pineapple"]);
//=> apple, banana, and pineapple.
```

### Browser Usage

#### Using a script tag

You can use i18n-js directly in the browser without a bundler by loading the
browser build via a `<script>` tag. The file can be found at
`node_modules/i18n-js/dist/browser/index.js`. The library will be available as
the global `I18n` object.

```html
<script src="/i18n.js"></script>
<script>
const i18n = new I18n.I18n({
en: { greeting: "Hello, World!" },
es: { greeting: "¡Hola, Mundo!" },
});

i18n.locale = "es";
console.log(i18n.t("greeting")); //=> ¡Hola, Mundo!
</script>
```

#### Using Import Maps

Modern browsers support [import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap),
which let you use ES module `import` syntax without a bundler. You can load
i18n-js (and its `lodash-es` dependency) from a CDN like [esm.sh](https://esm.sh).

```html
<script type="importmap">
{
"imports": {
"i18n-js": "https://esm.sh/i18n-js@4.5.4",
"lodash-es/": "https://esm.sh/lodash-es@4.17.23/"
}
}
</script>

<script type="module">
import { I18n } from "i18n-js";

const i18n = new I18n({
en: { greeting: "Hello, World!" },
es: { greeting: "¡Hola, Mundo!" },
});

i18n.locale = "es";
console.log(i18n.t("greeting")); //=> ¡Hola, Mundo!
</script>
```

## Troubleshooting

### I'm getting an error like `Unable to resolve "make-plural" from "node modules/i18n-js/dist/import/Pluralization.js"`
Expand Down
2 changes: 1 addition & 1 deletion __tests__/numberToRounded.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { repeat } from "lodash";
import repeat from "lodash-es/repeat";
import { BigNumber } from "bignumber.js";

import { I18n } from "../src/I18n";
Expand Down
2 changes: 1 addition & 1 deletion __tests__/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from "lodash";
import get from "lodash-es/get";
import { I18n } from "../src/I18n";

describe("I18n#store", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/translate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { snakeCase } from "lodash";
import snakeCase from "lodash-es/snakeCase";

import { I18n } from "../src/I18n";
import { Dict, Scope } from "../src/typing";
Expand Down
2 changes: 1 addition & 1 deletion __tests__/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from "lodash";
import get from "lodash-es/get";

import { I18n } from "../src/I18n";

Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
modulePaths: ["src"],
testPathIgnorePatterns: ["/vendor/bundle/"],
reporters: ["default", ["jest-hud-reporter", {}]],
transformIgnorePatterns: ["node_modules/(?!(lodash-es)/)"],
};
Loading