Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: i18n added to react-core
  • Loading branch information
etnlbck committed Oct 21, 2023
commit 36abaf6accac1e930640eebf3d16e602f57d3196
5 changes: 5 additions & 0 deletions .changeset/cool-kids-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/react-core": minor
---

Adding i18n support
4 changes: 3 additions & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@
},
"dependencies": {
"@tanstack/react-query": "^4.33.0",
"@thirdweb-dev/auth": "workspace:*",
"@thirdweb-dev/chains": "workspace:*",
"@thirdweb-dev/generated-abis": "workspace:^",
"@thirdweb-dev/sdk": "workspace:*",
"@thirdweb-dev/storage": "workspace:*",
"@thirdweb-dev/wallets": "workspace:*",
"@thirdweb-dev/auth": "workspace:*",
"i18next": "^23.5.1",
"mime": "3.0.0",
"react-i18next": "^13.3.0",
"tiny-invariant": "^1.2.0"
},
"peerDependencies": {
Expand Down
26 changes: 26 additions & 0 deletions packages/react-core/src/core/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";

// Import translations
import en from './locales/en.json';
import fr from './locales/fr.json';

// the translations
// (tip move them in a JSON file and import them,
// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)


// Set up i18n instance
i18n.use(initReactI18next).init({
resources: {
en: { translation: en },
fr: { translation: fr },
},
lng: 'en',
fallbackLng: 'en',
interpolation: {
escapeValue: false,
},
});

export default i18n;
3 changes: 3 additions & 0 deletions packages/react-core/src/core/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Welcome to React": "Welcome to React, react-i18next, and thirdweb"
}
3 changes: 3 additions & 0 deletions packages/react-core/src/core/i18n/locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Welcome to React": "Bienvenue sur React, React, i18next et thirdweb"
}
10 changes: 10 additions & 0 deletions packages/react-core/src/core/providers/i18n.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import i18n from '../i18n';


export const I18nContext = React.createContext({});

// Create i18n provider
export const I18nProvider: React.FC = ({ children }) => {
return <I18nContext.Provider value={{ i18n }}>{children}</I18nContext.Provider>;
};
15 changes: 12 additions & 3 deletions packages/react-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"extends": "@thirdweb-dev/tsconfig/react-library.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}
"include": [
"."
],
"exclude": [
"dist",
"build",
"node_modules"
],
"compilerOptions": {
"resolveJsonModule": true
}
}