@esershnr/artalk-sidebar 1.0.3 → 1.0.4
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/package.json +2 -2
- package/src/artalk.ts +1 -0
- package/src/global.ts +1 -0
- package/src/main.ts +25 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esershnr/artalk-sidebar",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The sidebar of artalk",
|
|
6
6
|
"private": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/crypto-js": "^4.2.2",
|
|
18
18
|
"@vitejs/plugin-vue": "^5.1.4",
|
|
19
|
-
"@esershnr/artalk": "
|
|
19
|
+
"@esershnr/artalk": "2.9.3",
|
|
20
20
|
"crypto-js": "^4.2.0",
|
|
21
21
|
"pinia": "^2.2.4",
|
|
22
22
|
"typescript": "^5.6.3",
|
package/src/artalk.ts
CHANGED
package/src/global.ts
CHANGED
package/src/main.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { setupI18n } from './i18n'
|
|
|
7
7
|
import '@esershnr/artalk/Artalk.css'
|
|
8
8
|
import './style.scss'
|
|
9
9
|
import App from './App.vue'
|
|
10
|
-
import { setArtalk } from './global'
|
|
10
|
+
import { bootParams, setArtalk } from './global'
|
|
11
11
|
import { setupArtalk, syncArtalkUser } from './artalk'
|
|
12
12
|
import './lib/promise-polyfill'
|
|
13
13
|
|
|
@@ -15,6 +15,23 @@ import './lib/promise-polyfill'
|
|
|
15
15
|
// @see https://vue-i18n.intlify.dev
|
|
16
16
|
const { i18n, setLocale } = setupI18n()
|
|
17
17
|
|
|
18
|
+
// Debugging
|
|
19
|
+
const ARTALK_LOCALE_KEY = 'atk_sidebar_forced_locale'
|
|
20
|
+
|
|
21
|
+
// Immediately apply local passed from parent via URL params if present
|
|
22
|
+
let urlLocale = bootParams.locale && bootParams.locale !== 'auto' ? bootParams.locale : ''
|
|
23
|
+
|
|
24
|
+
// Store in sessionStorage to survive potential reloads (since replaceState clears URL)
|
|
25
|
+
if (urlLocale) {
|
|
26
|
+
sessionStorage.setItem(ARTALK_LOCALE_KEY, urlLocale)
|
|
27
|
+
} else {
|
|
28
|
+
urlLocale = sessionStorage.getItem(ARTALK_LOCALE_KEY) || ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (urlLocale) {
|
|
32
|
+
setLocale(urlLocale)
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
// Router
|
|
19
36
|
// @see https://github.com/posva/unplugin-vue-router
|
|
20
37
|
const router = createRouter({
|
|
@@ -36,7 +53,13 @@ const artalkLoader = () =>
|
|
|
36
53
|
Artalk.use((ctx) => {
|
|
37
54
|
// When artalk is ready, notify the loader and load the locale
|
|
38
55
|
ctx.watchConf(['locale'], async (conf) => {
|
|
39
|
-
|
|
56
|
+
// PRIORITIZE: The locale passed from the parent site or stored in session
|
|
57
|
+
// FALLBACK: The locale set in the Artalk backend/admin panel
|
|
58
|
+
const locale = urlLocale || conf.locale
|
|
59
|
+
|
|
60
|
+
if (typeof locale === 'string' && locale !== 'auto') {
|
|
61
|
+
await setLocale(locale) // update i18n locale
|
|
62
|
+
}
|
|
40
63
|
|
|
41
64
|
if (!artalkLoaded) {
|
|
42
65
|
artalkLoaded = true
|