@sewadah/selaras-docs 1.4.1 → 1.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.2
4
+
5
+ [compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.1...selaras-docs-v1.4.2)
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **fix(docs):** sync active locale with route ([0b8599d](https://github.com/sewadahapp/selaras/commit/0b8599daff9df6b358c5be5815e31aab3722e2f2))
10
+
11
+ ### 🤖 Other changes
12
+
13
+ - Merge pull request #36 from sewadahapp/fix/docs-locale-route-state ([15e5002](https://github.com/sewadahapp/selaras/commit/15e50021f9db28bc1d47b6cd0c7ff404388d18dd))
14
+
15
+ Published against `@sewadah/selaras` ^1.3.0.
16
+
3
17
  ## v1.4.1
4
18
 
5
19
  [compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.4.0...selaras-docs-v1.4.1)
@@ -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 (typeof active === 'string' ? active : active?.value) ?? defaultLocale.value
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.1",
4
+ "version": "1.4.2",
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.2.0",
36
+ "@sewadah/selaras": "^1.3.0",
37
37
  "tailwindcss": "^4.3.0"
38
38
  }
39
39
  }