Skip to content

Commit

Permalink
fix: i18n-js module resolution for esm (#1549)
Browse files Browse the repository at this point in the history
* fix: common-js module

* CSR webpack i18n import fix

* format fix

* fix: use index.js (required by react webpack)

* format:fix

* biome format:fix again

* chore: refactor

* chore: changeset

---------

Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
magiziz and DanielSinclair authored Oct 6, 2023
1 parent 265da51 commit b60e335
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-students-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rainbow-me/rainbowkit": patch
---

Fixed a dependency resolution issue for `ESModule` projects related to `i18n-js`
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { I18n as _I18N } from 'i18n-js';
import React, { ReactNode, createContext, useMemo } from 'react';

import { Locale, i18n as _i18n } from '../../locales';
import { detectedBrowserLocale } from '../../utils/locale';

export const I18nContext = createContext<_I18N>(_i18n);
export const I18nContext = createContext<typeof _i18n>(_i18n);

interface I18nProviderProps {
children: ReactNode;
Expand Down
2 changes: 2 additions & 0 deletions packages/rainbowkit/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ declare module '*.png' {
const dataUrl: string;
export default dataUrl;
}

declare module 'i18n-js/dist/require/index.js';
6 changes: 4 additions & 2 deletions packages/rainbowkit/src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { I18n } from 'i18n-js';
import type * as I18nTypes from 'i18n-js';
import { I18n } from 'i18n-js/dist/require/index.js';

import ar_AR from './ar_AR.json';
import en_US from './en_US.json';
import es_419 from './es_419.json';
Expand Down Expand Up @@ -42,7 +44,7 @@ export type Locale =
| 'zh-CN';

// biome-ignore format: locale keys
export const i18n = new I18n({
export const i18n: I18nTypes.I18n = new I18n({
'ar': ar_AR,
'ar-AR': ar_AR,
'en': en_US,
Expand Down

2 comments on commit b60e335

@vercel
Copy link

@vercel vercel bot commented on b60e335 Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b60e335 Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.