next-language-selector 0.2.0 → 0.2.2
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 +3 -2
- package/dist/index.cjs +7 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +7 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ export default function Footer() {
|
|
|
36
36
|
<LanguageSelector
|
|
37
37
|
locales={locales}
|
|
38
38
|
defaultLocale="en"
|
|
39
|
-
activeColor="#3b82f6"
|
|
39
|
+
activeColor="#3b82f6" // optional
|
|
40
40
|
isDropdown={false} // Renders as a list of buttons
|
|
41
41
|
/>
|
|
42
42
|
</footer>
|
|
@@ -96,7 +96,8 @@ export default createMiddleware({
|
|
|
96
96
|
| :-------------- | :--------------- | :------------ | :---------------------------------------------------------- |
|
|
97
97
|
| `locales` | `LocaleConfig[]` | **Required** | Array of `{ name, code, flag }` objects |
|
|
98
98
|
| `defaultLocale` | `string` | **Required** | Initial language code |
|
|
99
|
-
| `isDropdown` | `boolean` | `
|
|
99
|
+
| `isDropdown` | `boolean` | `false` | Toggle between `<select>` and a list of buttons |
|
|
100
|
+
| `autoReload` | `boolean` | `true` | Trigger reload on cookie change |
|
|
100
101
|
| `cookieName` | `string` | `NEXT_LOCALE` | Name of the cookie to store the selected language |
|
|
101
102
|
| `activeColor` | `string` | `red` | Underline color for the active language (non-dropdown mode) |
|
|
102
103
|
| `className` | `string` | - | CSS class for the wrapper element |
|
package/dist/index.cjs
CHANGED
|
@@ -29,10 +29,12 @@ module.exports = __toCommonJS(index_exports);
|
|
|
29
29
|
var import_react = require("react");
|
|
30
30
|
|
|
31
31
|
// src/utils.ts
|
|
32
|
-
var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
|
|
32
|
+
var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE", autoReload = true) => {
|
|
33
33
|
if (typeof document === "undefined") return;
|
|
34
34
|
document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
|
|
35
|
-
|
|
35
|
+
if (autoReload) {
|
|
36
|
+
window.location.reload();
|
|
37
|
+
}
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
// src/selector.tsx
|
|
@@ -42,7 +44,8 @@ function LanguageSelector(props) {
|
|
|
42
44
|
locales,
|
|
43
45
|
defaultLocale,
|
|
44
46
|
cookieName = "NEXT_LOCALE",
|
|
45
|
-
isDropdown =
|
|
47
|
+
isDropdown = false,
|
|
48
|
+
autoReload = true,
|
|
46
49
|
renderCustom,
|
|
47
50
|
className,
|
|
48
51
|
activeColor = "red"
|
|
@@ -54,7 +57,7 @@ function LanguageSelector(props) {
|
|
|
54
57
|
}, [cookieName]);
|
|
55
58
|
const handleSelect = (code) => {
|
|
56
59
|
setCurrent(code);
|
|
57
|
-
setLocaleCookie(code, cookieName);
|
|
60
|
+
setLocaleCookie(code, cookieName, autoReload);
|
|
58
61
|
};
|
|
59
62
|
if (renderCustom) {
|
|
60
63
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: renderCustom({
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
declare const setLocaleCookie: (locale: string, cookieName?: string) => void;
|
|
3
|
+
declare const setLocaleCookie: (locale: string, cookieName?: string, autoReload?: boolean) => void;
|
|
4
4
|
|
|
5
5
|
interface LocaleConfig {
|
|
6
6
|
name: string;
|
|
@@ -14,6 +14,7 @@ interface LanguageSelectorProps {
|
|
|
14
14
|
cookieName?: string;
|
|
15
15
|
activeColor?: string;
|
|
16
16
|
className?: string;
|
|
17
|
+
autoReload?: boolean;
|
|
17
18
|
renderCustom?: (props: {
|
|
18
19
|
locales: LocaleConfig[];
|
|
19
20
|
currentLocale: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
declare const setLocaleCookie: (locale: string, cookieName?: string) => void;
|
|
3
|
+
declare const setLocaleCookie: (locale: string, cookieName?: string, autoReload?: boolean) => void;
|
|
4
4
|
|
|
5
5
|
interface LocaleConfig {
|
|
6
6
|
name: string;
|
|
@@ -14,6 +14,7 @@ interface LanguageSelectorProps {
|
|
|
14
14
|
cookieName?: string;
|
|
15
15
|
activeColor?: string;
|
|
16
16
|
className?: string;
|
|
17
|
+
autoReload?: boolean;
|
|
17
18
|
renderCustom?: (props: {
|
|
18
19
|
locales: LocaleConfig[];
|
|
19
20
|
currentLocale: string;
|
package/dist/index.mjs
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
|
|
4
4
|
// src/utils.ts
|
|
5
|
-
var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE") => {
|
|
5
|
+
var setLocaleCookie = (locale, cookieName = "NEXT_LOCALE", autoReload = true) => {
|
|
6
6
|
if (typeof document === "undefined") return;
|
|
7
7
|
document.cookie = `${cookieName}=${locale}; max-age=31536000; path=/`;
|
|
8
|
-
|
|
8
|
+
if (autoReload) {
|
|
9
|
+
window.location.reload();
|
|
10
|
+
}
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
// src/selector.tsx
|
|
@@ -15,7 +17,8 @@ function LanguageSelector(props) {
|
|
|
15
17
|
locales,
|
|
16
18
|
defaultLocale,
|
|
17
19
|
cookieName = "NEXT_LOCALE",
|
|
18
|
-
isDropdown =
|
|
20
|
+
isDropdown = false,
|
|
21
|
+
autoReload = true,
|
|
19
22
|
renderCustom,
|
|
20
23
|
className,
|
|
21
24
|
activeColor = "red"
|
|
@@ -27,7 +30,7 @@ function LanguageSelector(props) {
|
|
|
27
30
|
}, [cookieName]);
|
|
28
31
|
const handleSelect = (code) => {
|
|
29
32
|
setCurrent(code);
|
|
30
|
-
setLocaleCookie(code, cookieName);
|
|
33
|
+
setLocaleCookie(code, cookieName, autoReload);
|
|
31
34
|
};
|
|
32
35
|
if (renderCustom) {
|
|
33
36
|
return /* @__PURE__ */ jsx(Fragment, { children: renderCustom({
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-language-selector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Configurable language selector for Next.js",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
10
11
|
"import": "./dist/index.mjs",
|
|
11
12
|
"require": "./dist/index.cjs"
|
|
12
13
|
}
|