@modern-js/plugin-i18n 3.0.0-alpha.0 → 3.0.0-alpha.1

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.
@@ -32,6 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
33
33
  const runtime_namespaceObject = require("@modern-js/runtime");
34
34
  const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
35
+ const head_namespaceObject = require("@modern-js/runtime/head");
35
36
  const external_react_namespaceObject = require("react");
36
37
  const external_context_cjs_namespaceObject = require("./context.cjs");
37
38
  const external_hooks_cjs_namespaceObject = require("./hooks.cjs");
@@ -48,7 +49,7 @@ const external_I18nLink_cjs_namespaceObject = require("./I18nLink.cjs");
48
49
  const i18nPlugin = (options)=>({
49
50
  name: '@modern-js/plugin-i18n',
50
51
  setup: (api)=>{
51
- const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend } = options;
52
+ const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
52
53
  const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
53
54
  const { enabled: backendEnabled = false } = backend || {};
54
55
  let I18nextProvider;
@@ -128,11 +129,20 @@ const i18nPlugin = (options)=>({
128
129
  ignoreRedirectRoutes,
129
130
  forceUpdate
130
131
  ]);
131
- const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_cjs_namespaceObject.ModernI18nProvider, {
132
- value: contextValue,
133
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
134
- ...props
135
- })
132
+ const appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
133
+ children: [
134
+ Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
135
+ htmlAttributes: {
136
+ lang
137
+ }
138
+ }),
139
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_cjs_namespaceObject.ModernI18nProvider, {
140
+ value: contextValue,
141
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
142
+ ...props
143
+ })
144
+ })
145
+ ]
136
146
  });
137
147
  if (!i18nInstance) return appContent;
138
148
  if (I18nextProvider) {
@@ -1,6 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { isBrowser, useRuntimeContext } from "@modern-js/runtime";
3
3
  import { merge } from "@modern-js/runtime-utils/merge";
4
+ import { Helmet } from "@modern-js/runtime/head";
4
5
  import { useEffect, useMemo, useRef, useState } from "react";
5
6
  import { ModernI18nProvider, useModernI18n } from "./context";
6
7
  import { createContextValue, useClientSideRedirect, useLanguageSync, useSdkResourcesLoader } from "./hooks";
@@ -17,7 +18,7 @@ import { I18nLink } from "./I18nLink";
17
18
  const i18nPlugin = (options)=>({
18
19
  name: '@modern-js/plugin-i18n',
19
20
  setup: (api)=>{
20
- const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend } = options;
21
+ const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
21
22
  const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
22
23
  const { enabled: backendEnabled = false } = backend || {};
23
24
  let I18nextProvider;
@@ -97,11 +98,20 @@ const i18nPlugin = (options)=>({
97
98
  ignoreRedirectRoutes,
98
99
  forceUpdate
99
100
  ]);
100
- const appContent = /*#__PURE__*/ jsx(ModernI18nProvider, {
101
- value: contextValue,
102
- children: /*#__PURE__*/ jsx(App, {
103
- ...props
104
- })
101
+ const appContent = /*#__PURE__*/ jsxs(Fragment, {
102
+ children: [
103
+ Boolean(htmlLangAttr) && /*#__PURE__*/ jsx(Helmet, {
104
+ htmlAttributes: {
105
+ lang
106
+ }
107
+ }),
108
+ /*#__PURE__*/ jsx(ModernI18nProvider, {
109
+ value: contextValue,
110
+ children: /*#__PURE__*/ jsx(App, {
111
+ ...props
112
+ })
113
+ })
114
+ ]
105
115
  });
106
116
  if (!i18nInstance) return appContent;
107
117
  if (I18nextProvider) {
@@ -1,6 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { isBrowser, useRuntimeContext } from "@modern-js/runtime";
3
3
  import { merge } from "@modern-js/runtime-utils/merge";
4
+ import { Helmet } from "@modern-js/runtime/head";
4
5
  import { useEffect, useMemo, useRef, useState } from "react";
5
6
  import { ModernI18nProvider, useModernI18n } from "./context.js";
6
7
  import { createContextValue, useClientSideRedirect, useLanguageSync, useSdkResourcesLoader } from "./hooks.js";
@@ -17,7 +18,7 @@ import { I18nLink } from "./I18nLink.js";
17
18
  const i18nPlugin = (options)=>({
18
19
  name: '@modern-js/plugin-i18n',
19
20
  setup: (api)=>{
20
- const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend } = options;
21
+ const { entryName, i18nInstance: userI18nInstance, initOptions, localeDetection, backend, htmlLangAttr = false } = options;
21
22
  const { localePathRedirect = false, i18nextDetector = true, languages = [], fallbackLanguage = 'en', detection, ignoreRedirectRoutes } = localeDetection || {};
22
23
  const { enabled: backendEnabled = false } = backend || {};
23
24
  let I18nextProvider;
@@ -97,11 +98,20 @@ const i18nPlugin = (options)=>({
97
98
  ignoreRedirectRoutes,
98
99
  forceUpdate
99
100
  ]);
100
- const appContent = /*#__PURE__*/ jsx(ModernI18nProvider, {
101
- value: contextValue,
102
- children: /*#__PURE__*/ jsx(App, {
103
- ...props
104
- })
101
+ const appContent = /*#__PURE__*/ jsxs(Fragment, {
102
+ children: [
103
+ Boolean(htmlLangAttr) && /*#__PURE__*/ jsx(Helmet, {
104
+ htmlAttributes: {
105
+ lang
106
+ }
107
+ }),
108
+ /*#__PURE__*/ jsx(ModernI18nProvider, {
109
+ value: contextValue,
110
+ children: /*#__PURE__*/ jsx(App, {
111
+ ...props
112
+ })
113
+ })
114
+ ]
105
115
  });
106
116
  if (!i18nInstance) return appContent;
107
117
  if (I18nextProvider) {
@@ -11,6 +11,7 @@ export interface I18nPluginOptions {
11
11
  i18nInstance?: I18nInstance;
12
12
  changeLanguage?: (lang: string) => void;
13
13
  initOptions?: I18nInitOptions;
14
+ htmlLangAttr?: boolean;
14
15
  [key: string]: any;
15
16
  }
16
17
  export declare const i18nPlugin: (options: I18nPluginOptions) => RuntimePlugin;
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "modern",
17
17
  "modern.js"
18
18
  ],
19
- "version": "3.0.0-alpha.0",
19
+ "version": "3.0.0-alpha.1",
20
20
  "engines": {
21
21
  "node": ">=20"
22
22
  },
@@ -80,23 +80,23 @@
80
80
  "dependencies": {
81
81
  "@swc/helpers": "^0.5.17",
82
82
  "i18next-browser-languagedetector": "^8.2.0",
83
- "i18next-http-middleware": "^3.9.1",
83
+ "i18next-http-middleware": "^3.9.2",
84
84
  "i18next-fs-backend": "^2.6.1",
85
85
  "i18next-http-backend": "^3.0.2",
86
- "i18next-chained-backend": "^4.6.2",
87
- "@modern-js/plugin": "3.0.0-alpha.0",
88
- "@modern-js/server-core": "3.0.0-alpha.0",
89
- "@modern-js/server-runtime": "3.0.0-alpha.0",
90
- "@modern-js/runtime-utils": "3.0.0-alpha.0",
91
- "@modern-js/types": "3.0.0-alpha.0",
92
- "@modern-js/utils": "3.0.0-alpha.0"
86
+ "i18next-chained-backend": "^4.6.3",
87
+ "@modern-js/plugin": "3.0.0-alpha.1",
88
+ "@modern-js/server-core": "3.0.0-alpha.1",
89
+ "@modern-js/runtime-utils": "3.0.0-alpha.1",
90
+ "@modern-js/types": "3.0.0-alpha.1",
91
+ "@modern-js/server-runtime": "3.0.0-alpha.1",
92
+ "@modern-js/utils": "3.0.0-alpha.1"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "react": ">=17.0.2",
96
96
  "react-dom": ">=17.0.2",
97
97
  "i18next": ">=25.7.3",
98
98
  "react-i18next": ">=15.7.4",
99
- "@modern-js/runtime": "^3.0.0-alpha.0"
99
+ "@modern-js/runtime": "^3.0.0-alpha.1"
100
100
  },
101
101
  "peerDependenciesMeta": {
102
102
  "i18next": {
@@ -109,7 +109,7 @@
109
109
  "devDependencies": {
110
110
  "i18next": "25.7.3",
111
111
  "react-i18next": "15.7.4",
112
- "@rslib/core": "0.18.5",
112
+ "@rslib/core": "0.19.1",
113
113
  "@types/jest": "^29.5.14",
114
114
  "@types/node": "^20",
115
115
  "jest": "^29.7.0",
@@ -118,8 +118,8 @@
118
118
  "ts-jest": "^29.4.6",
119
119
  "ts-node": "^10.9.2",
120
120
  "typescript": "^5",
121
- "@modern-js/runtime": "3.0.0-alpha.0",
122
- "@modern-js/app-tools": "3.0.0-alpha.0",
121
+ "@modern-js/runtime": "3.0.0-alpha.1",
122
+ "@modern-js/app-tools": "3.0.0-alpha.1",
123
123
  "@scripts/jest-config": "2.66.0",
124
124
  "@modern-js/rslib": "2.68.10"
125
125
  },
@@ -4,6 +4,7 @@ import {
4
4
  useRuntimeContext,
5
5
  } from '@modern-js/runtime';
6
6
  import { merge } from '@modern-js/runtime-utils/merge';
7
+ import { Helmet } from '@modern-js/runtime/head';
7
8
  import type { TInternalRuntimeContext } from '@modern-js/runtime/internal';
8
9
  import type React from 'react';
9
10
  import { useEffect, useMemo, useRef, useState } from 'react';
@@ -52,6 +53,7 @@ export interface I18nPluginOptions {
52
53
  i18nInstance?: I18nInstance;
53
54
  changeLanguage?: (lang: string) => void;
54
55
  initOptions?: I18nInitOptions;
56
+ htmlLangAttr?: boolean;
55
57
  [key: string]: any;
56
58
  }
57
59
 
@@ -69,6 +71,7 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
69
71
  initOptions,
70
72
  localeDetection,
71
73
  backend,
74
+ htmlLangAttr = false,
72
75
  } = options;
73
76
  const {
74
77
  localePathRedirect = false,
@@ -245,9 +248,12 @@ export const i18nPlugin = (options: I18nPluginOptions): RuntimePlugin => ({
245
248
  );
246
249
 
247
250
  const appContent = (
248
- <ModernI18nProvider value={contextValue}>
249
- <App {...props} />
250
- </ModernI18nProvider>
251
+ <>
252
+ {Boolean(htmlLangAttr) && <Helmet htmlAttributes={{ lang }} />}
253
+ <ModernI18nProvider value={contextValue}>
254
+ <App {...props} />
255
+ </ModernI18nProvider>
256
+ </>
251
257
  );
252
258
 
253
259
  if (!i18nInstance) {