@sewadah/selaras-docs 1.4.1 → 1.4.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.4.3
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.2...selaras-docs-v1.4.3)
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **fix(docs):** refresh language trigger after hydration ([34994e2](https://github.com/sewadahapp/selaras/commit/34994e2a0c068243a4b08170aa53957b236add06))
|
|
10
|
+
|
|
11
|
+
### 🤖 Other changes
|
|
12
|
+
|
|
13
|
+
- Merge pull request #38 from sewadahapp/fix/docs-switcher-hydration ([272466a](https://github.com/sewadahapp/selaras/commit/272466ae26b3a4804d29039d0145484174b990f4))
|
|
14
|
+
|
|
15
|
+
Published against `@sewadah/selaras` ^1.3.0.
|
|
16
|
+
|
|
17
|
+
## v1.4.2
|
|
18
|
+
|
|
19
|
+
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.1...selaras-docs-v1.4.2)
|
|
20
|
+
|
|
21
|
+
### 🩹 Fixes
|
|
22
|
+
|
|
23
|
+
- **fix(docs):** sync active locale with route ([0b8599d](https://github.com/sewadahapp/selaras/commit/0b8599daff9df6b358c5be5815e31aab3722e2f2))
|
|
24
|
+
|
|
25
|
+
### 🤖 Other changes
|
|
26
|
+
|
|
27
|
+
- Merge pull request #36 from sewadahapp/fix/docs-locale-route-state ([15e5002](https://github.com/sewadahapp/selaras/commit/15e50021f9db28bc1d47b6cd0c7ff404388d18dd))
|
|
28
|
+
|
|
29
|
+
Published against `@sewadah/selaras` ^1.3.0.
|
|
30
|
+
|
|
3
31
|
## v1.4.1
|
|
4
32
|
|
|
5
33
|
[compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.0...selaras-docs-v1.4.1)
|
|
@@ -4,6 +4,12 @@ import { formatDocsMessage } from '../utils/docs-messages'
|
|
|
4
4
|
const { locale, locales, localeOption, hasLocaleSwitching, setLocale } = useDocsLocale()
|
|
5
5
|
const messages = useDocsMessages()
|
|
6
6
|
const open = ref(false)
|
|
7
|
+
// A root locale redirect can hydrate a different locale than the prerendered
|
|
8
|
+
// trigger. Replace that trigger after hydration so its icon and label match.
|
|
9
|
+
const hydrated = ref(false)
|
|
10
|
+
onMounted(() => {
|
|
11
|
+
hydrated.value = true
|
|
12
|
+
})
|
|
7
13
|
|
|
8
14
|
const nextLocale = computed(() => locales.value.find(option => option.code !== locale.value) ?? localeOption.value)
|
|
9
15
|
const label = computed(() => formatDocsMessage(messages.value.languageSwitcher, { language: nextLocale.value.name }))
|
|
@@ -12,6 +18,7 @@ const label = computed(() => formatDocsMessage(messages.value.languageSwitcher,
|
|
|
12
18
|
<template>
|
|
13
19
|
<SPopover v-if="hasLocaleSwitching" v-model:open="open" :positioning="{ side: 'bottom', align: 'end', sideOffset: 8 }" :ui="{ content: 'p-2' }">
|
|
14
20
|
<SButton
|
|
21
|
+
:key="String(hydrated)"
|
|
15
22
|
variant="ghost"
|
|
16
23
|
color="neutral"
|
|
17
24
|
square
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SelarasDocsLocaleOption } from '../../types'
|
|
2
|
+
import { resolveDocsLocale } from '../utils/docs-locale'
|
|
2
3
|
|
|
3
4
|
interface DocsI18nRuntime {
|
|
4
5
|
locale?: string | { value?: string }
|
|
@@ -30,10 +31,16 @@ export function useDocsLocale() {
|
|
|
30
31
|
const configured = computed(() => appConfig.selarasDocs?.i18n?.locales ?? [])
|
|
31
32
|
const locales = computed<SelarasDocsLocaleOption[]>(() => configured.value.length ? configured.value : fallbackLocales)
|
|
32
33
|
const defaultLocale = computed(() => appConfig.selarasDocs?.i18n?.defaultLocale ?? locales.value[0]?.code ?? 'en')
|
|
34
|
+
const route = useRoute()
|
|
33
35
|
const i18n = (nuxtApp as unknown as { $i18n?: DocsI18nRuntime }).$i18n
|
|
34
36
|
const locale = computed(() => {
|
|
35
37
|
const active = i18n?.locale
|
|
36
|
-
return (
|
|
38
|
+
return resolveDocsLocale(
|
|
39
|
+
route.path,
|
|
40
|
+
(typeof active === 'string' ? active : active?.value),
|
|
41
|
+
locales.value,
|
|
42
|
+
defaultLocale.value,
|
|
43
|
+
)
|
|
37
44
|
})
|
|
38
45
|
const localeOption = computed(() => locales.value.find(option => option.code === locale.value) ?? locales.value[0]!)
|
|
39
46
|
const hasLocaleSwitching = computed(() => locales.value.length > 1 && typeof i18n?.setLocale === 'function')
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface DocsLocaleCode {
|
|
2
|
+
code: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Prefer an explicit locale prefix in the current route over the i18n
|
|
7
|
+
* composer's active locale. On a root locale-detection redirect, SSR may
|
|
8
|
+
* render the prefixed locale before the client composer has synchronized.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveDocsLocale(
|
|
11
|
+
routePath: string,
|
|
12
|
+
activeLocale: string | undefined,
|
|
13
|
+
locales: readonly DocsLocaleCode[],
|
|
14
|
+
defaultLocale: string,
|
|
15
|
+
) {
|
|
16
|
+
const pathname = routePath.split(/[?#]/, 1)[0] || '/'
|
|
17
|
+
const routeLocale = locales.find(({ code }) => code !== defaultLocale
|
|
18
|
+
&& (pathname === `/${code}` || pathname.startsWith(`/${code}/`)))?.code
|
|
19
|
+
|
|
20
|
+
return routeLocale ?? activeLocale ?? defaultLocale
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sewadah/selaras-docs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.3",
|
|
5
5
|
"description": "Nuxt Content documentation layer for Selaras",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@nuxt/content": "^3.16.0",
|
|
35
35
|
"@nuxt/kit": "^4.5.2",
|
|
36
|
-
"@sewadah/selaras": "^1.
|
|
36
|
+
"@sewadah/selaras": "^1.3.0",
|
|
37
37
|
"tailwindcss": "^4.3.0"
|
|
38
38
|
}
|
|
39
39
|
}
|