sheet-i18n 0.2.6-canary.3 → 0.3.0-canary.3
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 +30 -25
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -222,9 +222,9 @@ export const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
|
|
|
222
222
|
import React from 'react';
|
|
223
223
|
import { IntlProvider } from './i18nContext';
|
|
224
224
|
|
|
225
|
-
const App = (
|
|
225
|
+
const App = () => {
|
|
226
226
|
return (
|
|
227
|
-
<IntlProvider
|
|
227
|
+
<IntlProvider>
|
|
228
228
|
<YourComponent />
|
|
229
229
|
</IntlProvider>
|
|
230
230
|
);
|
|
@@ -292,7 +292,7 @@ Generates React context, including the `IntlProvider` and `useTranslation`.
|
|
|
292
292
|
|
|
293
293
|
#### Parameters:
|
|
294
294
|
|
|
295
|
-
- **`i18nStore`**:
|
|
295
|
+
- **`i18nStore`**: Instance of `I18nStore`.
|
|
296
296
|
|
|
297
297
|
> ⚠️ Caveats:
|
|
298
298
|
|
|
@@ -309,15 +309,39 @@ const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
|
|
|
309
309
|
|
|
310
310
|
A React component to provide translations to child components.
|
|
311
311
|
|
|
312
|
-
####
|
|
312
|
+
#### Properties:
|
|
313
|
+
|
|
314
|
+
- **`currentLocale`** (optional):
|
|
315
|
+
|
|
316
|
+
- A key representing the current locale to use for translations.
|
|
317
|
+
- If not provided, the user's preferred language is automatically detected based on their browser settings.
|
|
318
|
+
- Falls back to the default locale in **i18nStore** if the detected language is unsupported.
|
|
313
319
|
|
|
314
|
-
- **`currentLocale`**: Key locale. This will determine which locale to use for translations data.
|
|
315
320
|
- **`children`**: React children.
|
|
316
321
|
|
|
317
322
|
#### Example:
|
|
318
323
|
|
|
319
324
|
```tsx
|
|
320
|
-
|
|
325
|
+
// Add currentLocale if you want to manually handle the locale
|
|
326
|
+
|
|
327
|
+
// The example is Next.js app routing
|
|
328
|
+
import { i18nStore } from './file-path-of-i18nStore-initiated';
|
|
329
|
+
|
|
330
|
+
interface LayoutProps {
|
|
331
|
+
params: {
|
|
332
|
+
locale: Locale;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export default function Layout({
|
|
337
|
+
children,
|
|
338
|
+
params,
|
|
339
|
+
}: PropsWithChildren<PageProps>) {
|
|
340
|
+
const { defaultLocale } = i18nStore;
|
|
341
|
+
const currentLocale = params?.locale ?? defaultLocale;
|
|
342
|
+
|
|
343
|
+
return <IntlProvider currentLocale={currentLocale}>{children}</IntlProvider>;
|
|
344
|
+
}
|
|
321
345
|
```
|
|
322
346
|
|
|
323
347
|
### `useTranslation`
|
|
@@ -369,25 +393,6 @@ Custom error messages help identify misconfigurations:
|
|
|
369
393
|
2. **Missing Default Locale**: The `defaultLocale` must exist in `supportedLocales`.
|
|
370
394
|
3. **Invalid LocaleSet**: Ensure the `localeSet` keys match `supportedLocales`.
|
|
371
395
|
|
|
372
|
-
## 🌍 Example Usage in Applications
|
|
373
|
-
|
|
374
|
-
```tsx
|
|
375
|
-
import { useTranslation } from './i18nContext';
|
|
376
|
-
|
|
377
|
-
const TableComponent = () => {
|
|
378
|
-
const { t } = useTranslation('header');
|
|
379
|
-
|
|
380
|
-
const columns = [
|
|
381
|
-
{
|
|
382
|
-
title: t('logout'),
|
|
383
|
-
dataIndex: 'action',
|
|
384
|
-
},
|
|
385
|
-
];
|
|
386
|
-
|
|
387
|
-
return <Table columns={columns} />;
|
|
388
|
-
};
|
|
389
|
-
```
|
|
390
|
-
|
|
391
396
|
## 📜 Library Versions 🔢
|
|
392
397
|
|
|
393
398
|
This package supports the following library versions:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sheet-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-canary.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@sheet-i18n/exporter": "0.
|
|
36
|
-
"@sheet-i18n/react": "0.
|
|
35
|
+
"@sheet-i18n/exporter": "0.3.0-canary.1",
|
|
36
|
+
"@sheet-i18n/react": "0.2.0-canary.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^6.0.0",
|
|
40
40
|
"typescript": "^5.0.0",
|
|
41
|
-
"@sheet-i18n/typescript-config": "0.
|
|
41
|
+
"@sheet-i18n/typescript-config": "0.3.0-canary.1"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|