@cellarnode/i18n 0.1.0 → 0.2.0
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.
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { type i18n } from 'i18next';
|
|
2
2
|
import type { I18nInstanceOptions } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Creates and initializes an i18next instance.
|
|
4
|
+
* Creates and initializes an i18next instance connected to React.
|
|
5
5
|
* Each frontend project calls this once in src/lib/i18n.ts.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Translations load in the background via i18next-http-backend.
|
|
10
|
-
* react-i18next handles the loading state via its `ready` prop / Suspense.
|
|
7
|
+
* Uses initReactI18next to bind the instance to react-i18next,
|
|
8
|
+
* enabling useTranslation() hooks to re-render on language changes.
|
|
11
9
|
*/
|
|
12
10
|
export declare function createI18nInstance(options: I18nInstanceOptions): i18n;
|
package/dist/create-instance.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import i18next from 'i18next';
|
|
2
|
+
import { initReactI18next } from 'react-i18next';
|
|
2
3
|
import HttpBackend from 'i18next-http-backend';
|
|
3
4
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
4
5
|
import { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE } from './constants';
|
|
5
6
|
/**
|
|
6
|
-
* Creates and initializes an i18next instance.
|
|
7
|
+
* Creates and initializes an i18next instance connected to React.
|
|
7
8
|
* Each frontend project calls this once in src/lib/i18n.ts.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Translations load in the background via i18next-http-backend.
|
|
12
|
-
* react-i18next handles the loading state via its `ready` prop / Suspense.
|
|
10
|
+
* Uses initReactI18next to bind the instance to react-i18next,
|
|
11
|
+
* enabling useTranslation() hooks to re-render on language changes.
|
|
13
12
|
*/
|
|
14
13
|
export function createI18nInstance(options) {
|
|
15
14
|
const { defaultNS = 'common', ns = ['common'], loadPath = '/locales/{{lng}}/{{ns}}.json', lng, debug = false, } = options;
|
|
@@ -17,6 +16,7 @@ export function createI18nInstance(options) {
|
|
|
17
16
|
instance
|
|
18
17
|
.use(HttpBackend)
|
|
19
18
|
.use(LanguageDetector)
|
|
19
|
+
.use(initReactI18next)
|
|
20
20
|
.init({
|
|
21
21
|
lng,
|
|
22
22
|
fallbackLng: [DEFAULT_LANGUAGE],
|
|
@@ -26,7 +26,7 @@ export function createI18nInstance(options) {
|
|
|
26
26
|
fallbackNS: 'common',
|
|
27
27
|
debug,
|
|
28
28
|
interpolation: {
|
|
29
|
-
escapeValue: false,
|
|
29
|
+
escapeValue: false,
|
|
30
30
|
},
|
|
31
31
|
detection: {
|
|
32
32
|
order: ['localStorage', 'navigator'],
|
|
@@ -38,6 +38,8 @@ export function createI18nInstance(options) {
|
|
|
38
38
|
},
|
|
39
39
|
react: {
|
|
40
40
|
useSuspense: false,
|
|
41
|
+
bindI18n: 'loaded languageChanged',
|
|
42
|
+
bindI18nStore: 'added',
|
|
41
43
|
},
|
|
42
44
|
});
|
|
43
45
|
return instance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cellarnode/i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shared i18n configuration for CellarNode frontends — language constants, i18next factory, browser locale detection, and common translations.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -44,8 +44,12 @@
|
|
|
44
44
|
"i18next-browser-languagedetector": "^8.0.0",
|
|
45
45
|
"i18next-http-backend": "^3.0.0"
|
|
46
46
|
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react-i18next": ">=15.0.0"
|
|
49
|
+
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"@types/node": "^25.5.0",
|
|
52
|
+
"react-i18next": "^15.7.4",
|
|
49
53
|
"typescript": "^5.8.0",
|
|
50
54
|
"vitest": "^3.0.0"
|
|
51
55
|
},
|