@lumiapassport/ui-kit 1.17.2 → 1.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,45 +39,74 @@ export const queryClient = new QueryClient({
39
39
 
40
40
  ### 2. I18n config (Required) & typing (Optional)
41
41
 
42
- i18next lib should be inited above both passport & your app, so your app language can be switched by Passport's lang selector.
43
- Create the following folder structure for your app's translations:
42
+ i18next lib must be initiated for both passport & your app (namespace concept used to manage translations), so your app's language can be switched by Passport's lang selector.
43
+
44
+ There is no need to provide any translations for Passport ( has built-in default lang-set ), unless it's not required to expand supported languages by custom langs, but it is required to init i18next inside DApp.
45
+
46
+ First, create the following folder structure for your dapp's translations (or update existant, if needed):
47
+
48
+ example: common.json
49
+
50
+ ```json
51
+ {
52
+ "appname": "My App",
53
+ "signin": "Sign IN"
54
+ }
55
+ ```
44
56
 
45
57
  ```
46
58
  src/
47
59
  └── i18n/
48
60
  ├── locales/
49
- └── en.json
61
+ ├── en/
62
+ │ ├── ├── common.json
63
+ │ ├── ├── header.json
64
+ │ ├── ├── page1.json
65
+ │ ├── ├── page2.json
66
+ │ ├── └── ...restTranslationsJsons
67
+ │ ├── /...restLocales/...
50
68
  └── index.ts
51
69
  ```
52
70
 
53
71
  Where:
54
72
 
55
- - `locales/*.json` files contain i18next translation maps
56
- - `index.ts` exports translation resources as const
73
+ - `locales/**/*.json` files contain i18next translation maps. OPTIONAL Use dedicated files for easier translations maintainance.
74
+ - `index.ts` exports translation resources
57
75
 
58
- `IMPORTANT` YOUR_APP_TRANSLATION_RESOURSES should be structured with namespaces as shown, where "app" is example namespace
76
+ > **IMPORTANT:** YOUR_APP_TRANSLATION_RESOURSES must be structured with namespaces (as shown), where "app" is example namespace
59
77
 
60
78
  ```tsx
61
- import en from './locales/en.json'
79
+ import commonEn from './i18n/locales/en/common.json'
80
+ import headerEn from './i18n/locales/en/header.json'
81
+ import page1en from './locales/en/page1.json'
82
+ import page2en from './locales/en/page2.json'
62
83
 
63
84
  export const YOUR_APP_TRANSLATION_RESOURSES = {
64
- en: { app: en } // language: { namespace: jsonLocale }
85
+ // language: { namespace: jsonLocale }
86
+ en: {
87
+ app: {
88
+ common: commonEn,
89
+ header: headerEn,
90
+ page1: page1en,
91
+ page2: page2en
92
+ }
93
+ }
65
94
  // ...
66
95
  } as const
67
96
  ```
68
97
 
69
- `NOTE` If you don't need to translate your app then leave YOUR_APP_TRANSLATION_RESOURSES empty. Also there is no need in locales folder
98
+ > **Note:** If you don't need to translate your app then leave YOUR_APP_TRANSLATION_RESOURSES empty with no locales folder.
70
99
 
71
- Decalre types at `src/i18next.d.ts` so t-method provides intellisence typings for yor translations, your default locale can be used for typing
100
+ Decalre types (usualy at `src/i18next.d.ts`) so t-method provides intellisence typings for your translations. Default locale is recomended to be used for typing as shown
72
101
 
73
102
  ```tsx
74
- import en from './i18n/locales/en.json'
103
+ import { YOUR_APP_TRANSLATION_RESOURSES } from './i18n'
75
104
 
76
105
  declare module 'i18next' {
77
106
  interface CustomTypeOptions {
78
107
  defaultNS: 'app' //
79
108
  resources: {
80
- app: typeof en
109
+ app: typeof YOUR_APP_TRANSLATION_RESOURSES.en.app
81
110
  }
82
111
  }
83
112
  }
@@ -85,6 +114,16 @@ declare module 'i18next' {
85
114
 
86
115
  ### 3. Wrap your app with providers & init i18n
87
116
 
117
+ > **Note:** Declare your specific dapp's high order useTranslation hook re-expoting namespaced react-i18next useTranslation, since now t-method is typed by your default locale.
118
+
119
+ ```tsx
120
+ import { useTranslation } from 'react-i18next'
121
+
122
+ export function useT() {
123
+ return useTranslation('app') // this will make t-method typed accordingly
124
+ }
125
+ ```
126
+
88
127
  ```tsx
89
128
  import {
90
129
  combineI18NResources,
@@ -98,22 +137,20 @@ import {
98
137
  import i18n from 'i18next'
99
138
  import { initReactI18next, useTranslation } from 'react-i18next'
100
139
 
101
- // import { YOUR_APP_TRANSLATION_RESOURSES } from './i18n'
140
+ import { YOUR_APP_TRANSLATION_RESOURSES } from './i18n'
102
141
  import { queryClient } from './queryClient'
103
142
 
104
- const i18nResourcesWithPassport = combineI18NResources(/** YOUR_APP_TRANSLATION_RESOURSES */)
105
- const savedLanguage = localStorage.getItem(LOCAL_STORAGE_I18N_KEY) // passport saves language setup on change
106
-
107
143
  i18n.use(initReactI18next).init({
108
- resources: i18nResourcesWithPassport,
109
- lng: savedLanguage || 'en',
144
+ resources: combineI18NResources(YOUR_APP_TRANSLATION_RESOURSES),
145
+ lng: localStorage.getItem(LOCAL_STORAGE_I18N_KEY) || 'en', // passport saves language setup on change
110
146
  fallbackLng: 'en', // default
111
147
  defaultNS: 'app', // your app i18n-namespace, example: app
148
+ namespace: 'app', // your app i18n-namespace, example: app
112
149
  debug: false
113
150
  })
114
151
 
115
152
  function Root() {
116
- const { t } = useTranslation(/** optionaly our app i18next namespace, example namespace: app */)
153
+ const { t } = useT()
117
154
 
118
155
  return (
119
156
  <QueryClientProvider client={queryClient}>
@@ -122,9 +159,13 @@ function Root() {
122
159
  >
123
160
  <LumiaRainbowKitProvider>
124
161
  <LumiaPassportSessionProvider>
125
- {/* Note! provided translation resourses will be available under provided namespace, example namespace: app */}
126
- {/* <span>{t('app:title')}</span> */}
127
- <YourApp />
162
+ <header>
163
+ <h1>{t('common.appname')}</h1>
164
+ </header>
165
+
166
+ <main>
167
+ <span>{t('page1.title')}</span>
168
+ </main>
128
169
  </LumiaPassportSessionProvider>
129
170
  </LumiaRainbowKitProvider>
130
171
  </LumiaPassportProvider>
@@ -139,10 +180,12 @@ function Root() {
139
180
  import { ConnectWalletButton } from '@lumiapassport/ui-kit'
140
181
 
141
182
  function YourApp() {
183
+ const { t } = useT()
184
+
142
185
  return (
143
186
  <div>
144
- <h1>My App</h1>
145
- <ConnectWalletButton label="Sign in" />
187
+ <h1>{t('common.appname')}</h1>
188
+ <ConnectWalletButton label={t('common.signin')} />
146
189
  </div>
147
190
  )
148
191
  }
@@ -161,10 +204,12 @@ function CustomButtonComponent(props: HTMLAttributes<HTMLButtonElement>) => {
161
204
  }
162
205
 
163
206
  function YourApp() {
207
+ const { t } = useT()
208
+
164
209
  return (
165
210
  <div>
166
211
  <h1>My App</h1>
167
- <ConnectWalletButton label="Sign in" ConnectButton={CustomButtonComponent} />
212
+ <ConnectWalletButton label={t('common.signin')} ConnectButton={CustomButtonComponent} />
168
213
  </div>
169
214
  )
170
215
  }
@@ -15,7 +15,7 @@
15
15
  <meta http-equiv="X-Content-Type-Options" content="nosniff" />
16
16
  <meta http-equiv="Referrer-Policy" content="strict-origin-when-cross-origin" />
17
17
 
18
- <title>Lumia Passport Secure Wallet - iframe version 1.17.2</title>
18
+ <title>Lumia Passport Secure Wallet - iframe version 1.17.5</title>
19
19
 
20
20
  <!-- Styles will be injected by build process -->
21
21
  <style>
@@ -4411,7 +4411,7 @@ var SigningManager = class extends TokenRefreshApiClient {
4411
4411
  };
4412
4412
 
4413
4413
  // src/iframe/main.ts
4414
- var IFRAME_VERSION = "1.17.2";
4414
+ var IFRAME_VERSION = "1.17.5";
4415
4415
  var IframeWallet = class {
4416
4416
  constructor() {
4417
4417
  console.log("=".repeat(60));