@sewadah/selaras-docs 1.3.3 β†’ 1.4.0

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,31 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.0
4
+
5
+ [compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.3.3...selaras-docs-v1.4.0)
6
+
7
+ ### πŸš€ Enhancements
8
+
9
+ - **feat(docs):** style locale picker with country flags ([52cdf75](https://github.com/sewadahapp/selaras/commit/52cdf75ad5066d75702900fb739a6978d6d3d36b))
10
+ - **feat(docs):** localize shared site navigation ([74bf72d](https://github.com/sewadahapp/selaras/commit/74bf72dd3768711d9528c12148209ea532620a03))
11
+ - **feat(docs):** add locale-prefixed Indonesian routes ([fa4027b](https://github.com/sewadahapp/selaras/commit/fa4027b3927b658582197da9e6820b00383f229f))
12
+
13
+ ### 🩹 Fixes
14
+
15
+ - **fix(docs):** keep SEO helpers within packed docs layer ([5375302](https://github.com/sewadahapp/selaras/commit/5375302141d67dd519c1b98337f4762976d10099))
16
+ - **fix(docs):** bundle circular locale flags ([a84da63](https://github.com/sewadahapp/selaras/commit/a84da63f7919d318c0ed822f269fac3841b83c14))
17
+
18
+ ### πŸ“– Documentation
19
+
20
+ - **docs(i18n):** add EN/ID localization infrastructure ([6b81981](https://github.com/sewadahapp/selaras/commit/6b819818be0ded51644277c803dc2b0ee1463a12))
21
+
22
+ ### πŸ€– Other changes
23
+
24
+ - Merge pull request #27 from sewadahapp/feat/docs-i18n-expanded ([9be0a40](https://github.com/sewadahapp/selaras/commit/9be0a4095a4fb01a344daedb53de06215fb54edd))
25
+ - Merge branch 'feat/docs-i18n-infrastructure' into feat/docs-i18n-expanded ([881a930](https://github.com/sewadahapp/selaras/commit/881a93061b8329d77048f8e288df567eb5caff9c))
26
+
27
+ Published against `@sewadah/selaras` ^1.2.0.
28
+
3
29
  ## v1.3.3
4
30
 
5
31
  [compare changes](https://github.com/sewadahapp/selaras/compare/selaras-docs-v1.3.2...selaras-docs-v1.3.3)
@@ -361,3 +361,13 @@
361
361
  .dark .selaras-docs-logo--dark {
362
362
  display: block;
363
363
  }
364
+ /* Shown when the active locale has no translation of the current page. */
365
+ .selaras-docs-translation-notice {
366
+ margin: 0 0 1.5rem;
367
+ padding: 0.75rem 1rem;
368
+ border: 1px solid var(--selaras-resolved-border-default);
369
+ border-radius: var(--selaras-resolved-radius-md);
370
+ color: var(--selaras-resolved-text-muted);
371
+ font-size: 0.875rem;
372
+ line-height: 1.6;
373
+ }
@@ -7,6 +7,7 @@ const props = defineProps<{
7
7
 
8
8
  const appConfig = useAppConfig()
9
9
  const docsConfig = computed(() => appConfig.selarasDocs ?? {})
10
+ const messages = useDocsMessages()
10
11
 
11
12
  const editUrl = computed(() => getDocsRepositoryLinks(docsConfig.value.repository, props.path).edit)
12
13
  </script>
@@ -14,6 +15,6 @@ const editUrl = computed(() => getDocsRepositoryLinks(docsConfig.value.repositor
14
15
  <template>
15
16
  <a v-if="editUrl" :href="editUrl" class="selaras-docs-edit-link" target="_blank" rel="noreferrer">
16
17
  <SIcon name="hugeicons:pencil-edit-01" aria-hidden="true" />
17
- Edit this page
18
+ {{ messages.editPage }}
18
19
  </a>
19
20
  </template>
@@ -4,6 +4,7 @@ withDefaults(defineProps<{ heading?: 'h1' | 'h2' }>(), { heading: 'h1' })
4
4
  const appConfig = useAppConfig()
5
5
  const config = useRuntimeConfig()
6
6
  const headingId = useId()
7
+ const messages = useDocsMessages()
7
8
  const copy = computed(() => appConfig.selarasDocs?.empty ?? {})
8
9
  const homeHref = computed(() => {
9
10
  const path = appConfig.selarasDocs?.errors?.homeTo ?? '/'
@@ -19,13 +20,13 @@ const homeHref = computed(() => {
19
20
  </slot>
20
21
  </div>
21
22
  <component :is="heading" :id="headingId" class="selaras-docs-empty-title">
22
- {{ copy.title ?? 'No content yet' }}
23
+ {{ copy.title ?? messages.emptyTitle }}
23
24
  </component>
24
25
  <p class="selaras-docs-empty-description">
25
- {{ copy.description ?? 'There’s no content on this page yet. You can explore the rest of the documentation using the navigation.' }}
26
+ {{ copy.description ?? messages.emptyDescription }}
26
27
  </p>
27
28
  <SButton as="a" :href="homeHref" variant="outline" color="neutral" class="selaras-docs-empty-action">
28
- {{ appConfig.selarasDocs?.errors?.homeLabel ?? 'Back to documentation' }}
29
+ {{ appConfig.selarasDocs?.errors?.homeLabel ?? messages.backToDocumentation }}
29
30
  </SButton>
30
31
  </section>
31
32
  </template>
@@ -9,6 +9,7 @@ const props = withDefaults(defineProps<{
9
9
 
10
10
  const emit = defineEmits<{ retry: [], home: [event: MouseEvent] }>()
11
11
  const appConfig = useAppConfig()
12
+ const messages = useDocsMessages()
12
13
  const config = useRuntimeConfig()
13
14
  const homeHref = computed(() => {
14
15
  const path = appConfig.selarasDocs?.errors?.homeTo ?? '/'
@@ -23,10 +24,10 @@ onMounted(() => {
23
24
  })
24
25
  const copy = computed(() => {
25
26
  const defaults = {
26
- notFound: { title: 'Page not found', description: 'The link may have changed, or this page may no longer exist. You can start again from the homepage.' },
27
- fatal: { title: 'Something went wrong', description: 'We couldn’t load this page. Reload it to try again, or return to the homepage.' },
28
- page: { title: 'This page couldn’t load', description: 'Please try again. You can still use the navigation to explore other pages.' },
29
- example: { title: 'This example couldn’t load', description: 'Try loading the example again. The rest of the documentation is still available.' },
27
+ notFound: { title: messages.value.notFoundTitle, description: messages.value.notFoundDescription },
28
+ fatal: { title: messages.value.fatalTitle, description: messages.value.fatalDescription },
29
+ page: { title: messages.value.pageTitle, description: messages.value.pageDescription },
30
+ example: { title: messages.value.exampleTitle, description: messages.value.exampleDescription },
30
31
  }
31
32
  return { ...defaults[props.kind], ...appConfig.selarasDocs?.errors?.[props.kind] }
32
33
  })
@@ -55,10 +56,10 @@ const showHome = computed(() => props.showHome ?? props.kind !== 'example')
55
56
  </p>
56
57
  <div class="selaras-docs-error-actions">
57
58
  <SButton v-if="kind !== 'notFound'" :loading="pending" :disabled="pending" @click="emit('retry')">
58
- {{ pending ? labels.retryingLabel ?? 'Trying again…' : kind === 'fatal' ? labels.reloadLabel ?? 'Reload page' : labels.retryLabel ?? 'Try again' }}
59
+ {{ pending ? labels.retryingLabel ?? messages.retrying : kind === 'fatal' ? labels.reloadLabel ?? messages.reload : labels.retryLabel ?? messages.retry }}
59
60
  </SButton>
60
61
  <SButton v-if="showHome" as="a" :href="homeHref" :variant="kind === 'notFound' ? 'solid' : 'outline'" :color="kind === 'notFound' ? 'primary' : 'neutral'" @click="emit('home', $event)">
61
- {{ labels.homeLabel ?? 'Go to homepage' }}
62
+ {{ labels.homeLabel ?? messages.home }}
62
63
  </SButton>
63
64
  </div>
64
65
  </div>
@@ -1,18 +1,22 @@
1
1
  <script setup lang="ts">
2
+ import { useDocsRoutePath } from '../composables/useDocsRoutePath'
3
+
2
4
  const appConfig = useAppConfig()
3
5
  const docsConfig = computed(() => appConfig.selarasDocs ?? {})
4
6
  const footer = computed(() => docsConfig.value.footer)
7
+ const messages = useDocsMessages()
8
+ const docsRoutePath = useDocsRoutePath()
5
9
  </script>
6
10
 
7
11
  <template>
8
12
  <footer v-if="footer?.text || footer?.links?.length" class="selaras-docs-footer" :class="{ 'selaras-docs-footer--fluid': footer?.fluid }">
9
13
  <SContainer size="full" class="selaras-docs-footer-inner">
10
14
  <DocsFooterBrand />
11
- <nav v-if="footer?.links?.length" class="selaras-docs-footer-links" aria-label="Footer navigation">
15
+ <nav v-if="footer?.links?.length" class="selaras-docs-footer-links" :aria-label="messages.footerNavigation">
12
16
  <NuxtLink
13
17
  v-for="link in footer.links"
14
18
  :key="`${link.to}:${link.label ?? link.icon ?? ''}`"
15
- :to="link.to"
19
+ :to="docsRoutePath(link.to)"
16
20
  :target="link.target"
17
21
  :rel="link.rel"
18
22
  :aria-label="link.ariaLabel ?? link.label"
@@ -1,12 +1,26 @@
1
1
  <script setup lang="ts">
2
+ import type { SelarasDocsNavigationItem } from '../../types'
3
+ import { useDocsRoutePath } from '../composables/useDocsRoutePath'
4
+
2
5
  const route = useRoute()
3
6
  const appConfig = useAppConfig()
4
7
  const { data: navigation } = useDocsNavigation()
8
+ const messages = useDocsMessages()
9
+ const docsRoutePath = useDocsRoutePath()
5
10
  const navigationOpen = ref(false)
11
+ const { locale } = useDocsLocale()
6
12
 
7
13
  const docsConfig = computed(() => appConfig.selarasDocs ?? {})
8
14
  const siteName = computed(() => docsConfig.value.header?.title ?? docsConfig.value.site?.name ?? 'Documentation')
9
- const headerLinks = computed(() => docsConfig.value.header?.links ?? [])
15
+ function localizedLink(link: SelarasDocsNavigationItem): SelarasDocsNavigationItem {
16
+ return {
17
+ ...link,
18
+ label: link.labels?.[locale.value] ?? link.label,
19
+ ...(link.to ? { to: docsRoutePath(link.to) } : {}),
20
+ ...(link.children ? { children: link.children.map(localizedLink) } : {}),
21
+ }
22
+ }
23
+ const headerLinks = computed(() => (docsConfig.value.header?.links ?? []).map(localizedLink))
10
24
  const repositoryUrl = computed(() => docsConfig.value.repository?.url)
11
25
  const sidebarEnabled = computed(() => docsConfig.value.sidebar?.enabled !== false)
12
26
  const mobileNavigationEnabled = computed(() => sidebarEnabled.value || headerLinks.value.length > 0)
@@ -25,7 +39,7 @@ watch(() => route.path, () => {
25
39
  }"
26
40
  >
27
41
  <div class="selaras-docs-brand-area">
28
- <NuxtLink to="/" class="selaras-docs-brand" :aria-label="`${siteName} home`">
42
+ <NuxtLink :to="docsRoutePath('/')" class="selaras-docs-brand" :aria-label="`${siteName} home`">
29
43
  <DocsHeaderBrand />
30
44
  </NuxtLink>
31
45
  </div>
@@ -39,14 +53,15 @@ watch(() => route.path, () => {
39
53
  <DocsSearchButton v-if="docsConfig.header?.search !== false" />
40
54
  <SColorModeToggle v-if="docsConfig.header?.colorMode !== false" />
41
55
  <DocsThemePicker v-if="docsConfig.header?.themePicker" />
56
+ <DocsLanguageSwitcher />
42
57
  <SButton
43
58
  v-if="repositoryUrl"
44
59
  as="a"
45
60
  :href="repositoryUrl"
46
61
  target="_blank"
47
62
  rel="noreferrer"
48
- aria-label="Source repository"
49
- title="Source repository"
63
+ :aria-label="messages.sourceRepository"
64
+ :title="messages.sourceRepository"
50
65
  icon="hugeicons:github"
51
66
  variant="ghost"
52
67
  color="neutral"
@@ -56,20 +71,20 @@ watch(() => route.path, () => {
56
71
  variant="ghost"
57
72
  color="neutral"
58
73
  class="selaras-docs-nav-toggle"
59
- aria-label="Open documentation navigation"
74
+ :aria-label="messages.openNavigation"
60
75
  @click="navigationOpen = true"
61
76
  >
62
77
  Menu
63
78
  </SButton>
64
79
  </div>
65
80
  </SHeader>
66
- <SDrawer v-if="mobileNavigationEnabled" v-model:open="navigationOpen" side="left" title="Documentation navigation" :handle="false">
81
+ <SDrawer v-if="mobileNavigationEnabled" v-model:open="navigationOpen" side="left" :title="messages.documentationNavigation" :handle="false">
67
82
  <template #body>
68
83
  <SNavigationMenu
69
84
  v-if="headerLinks.length"
70
85
  :items="headerLinks"
71
86
  orientation="vertical"
72
- aria-label="Main navigation"
87
+ :aria-label="messages.mainNavigation"
73
88
  :ui="{ root: 'mb-6 w-full' }"
74
89
  />
75
90
  <SContentNavigation v-if="sidebarEnabled" :navigation="navigation ?? []" :collapsed="docsConfig.sidebar?.collapsed" />
@@ -0,0 +1,83 @@
1
+ <script setup lang="ts">
2
+ import { formatDocsMessage } from '../utils/docs-messages'
3
+
4
+ const { locale, locales, localeOption, hasLocaleSwitching, setLocale } = useDocsLocale()
5
+ const messages = useDocsMessages()
6
+ const open = ref(false)
7
+
8
+ const nextLocale = computed(() => locales.value.find(option => option.code !== locale.value) ?? localeOption.value)
9
+ const label = computed(() => formatDocsMessage(messages.value.languageSwitcher, { language: nextLocale.value.name }))
10
+ </script>
11
+
12
+ <template>
13
+ <SPopover v-if="hasLocaleSwitching" v-model:open="open" :positioning="{ side: 'bottom', align: 'end', sideOffset: 8 }" :ui="{ content: 'p-2' }">
14
+ <SButton
15
+ variant="ghost"
16
+ color="neutral"
17
+ square
18
+ :aria-label="label"
19
+ :title="label"
20
+ :aria-expanded="open"
21
+ >
22
+ <Icon v-if="localeOption.code === 'en'" aria-hidden="true" name="circle-flags:gb" class="size-5" />
23
+ <Icon v-else-if="localeOption.code === 'id'" aria-hidden="true" name="circle-flags:id" class="size-5" />
24
+ <Icon v-else aria-hidden="true" name="hugeicons:globe-02" class="size-5" />
25
+ </SButton>
26
+
27
+ <template #content>
28
+ <section class="w-[min(19rem,calc(100vw-2rem))] p-1" aria-labelledby="docs-language-picker-title">
29
+ <div class="px-1 pb-1.5 pt-0.5">
30
+ <h2 id="docs-language-picker-title" class="text-sm font-semibold text-[var(--selaras-resolved-text-default)]">
31
+ {{ locale === 'id' ? 'Bahasa' : 'Language' }}
32
+ </h2>
33
+ <p class="mt-0.5 text-xs text-[var(--selaras-resolved-text-muted)]">
34
+ {{ locale === 'id' ? 'Pilih bahasa dokumentasi' : 'Choose a documentation language' }}
35
+ </p>
36
+ </div>
37
+
38
+ <div class="flex flex-col gap-0.5" role="group" :aria-label="locale === 'id' ? 'Bahasa dokumentasi' : 'Documentation languages'">
39
+ <button
40
+ v-for="option in locales"
41
+ :key="option.code"
42
+ type="button"
43
+ class="group flex w-full items-center gap-2.5 rounded-[var(--selaras-resolved-radius-md)] border p-2 text-start transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--_selaras-color-focus)]"
44
+ :class="locale === option.code
45
+ ? 'border-[var(--selaras-resolved-color-primary-fill)] bg-[var(--selaras-resolved-surface-elevated)]'
46
+ : 'border-transparent hover:bg-[var(--selaras-resolved-surface-elevated)]'"
47
+ :aria-pressed="locale === option.code"
48
+ @click="setLocale(option.code); open = false"
49
+ >
50
+ <span aria-hidden="true" class="flex size-10 shrink-0 items-center justify-center">
51
+ <Icon v-if="option.code === 'en'" name="circle-flags:gb" class="size-8" />
52
+ <Icon v-else-if="option.code === 'id'" name="circle-flags:id" class="size-8" />
53
+ <Icon v-else name="hugeicons:globe-02" class="size-8" />
54
+ </span>
55
+
56
+ <span class="min-w-0 flex-1">
57
+ <span class="block text-sm font-medium text-[var(--selaras-resolved-text-default)]">
58
+ {{ option.name }}
59
+ </span>
60
+ <span class="mt-0.5 block text-xs text-[var(--selaras-resolved-text-muted)]">
61
+ {{ option.language ?? option.code }}
62
+ </span>
63
+ </span>
64
+
65
+ <svg
66
+ v-if="locale === option.code"
67
+ aria-hidden="true"
68
+ viewBox="0 0 20 20"
69
+ class="size-4 shrink-0 text-[var(--selaras-resolved-color-primary-text)]"
70
+ fill="none"
71
+ stroke="currentColor"
72
+ stroke-width="2"
73
+ stroke-linecap="round"
74
+ stroke-linejoin="round"
75
+ >
76
+ <path d="m4 10 4 4 8-8" />
77
+ </svg>
78
+ </button>
79
+ </div>
80
+ </section>
81
+ </template>
82
+ </SPopover>
83
+ </template>
@@ -9,17 +9,18 @@ const props = withDefaults(defineProps<{
9
9
  }>(), { editLink: true, issueLink: true })
10
10
 
11
11
  const appConfig = useAppConfig()
12
+ const messages = useDocsMessages()
12
13
  const links = computed(() => getDocsRepositoryLinks(appConfig.selarasDocs?.repository, props.path, props.title))
13
14
  const hasEditLink = computed(() => props.editLink && !!links.value.edit)
14
15
  const hasIssueLink = computed(() => props.issueLink && !!links.value.issue)
15
16
  </script>
16
17
 
17
18
  <template>
18
- <nav v-if="hasEditLink || hasIssueLink" class="selaras-docs-page-actions" aria-label="Page actions">
19
+ <nav v-if="hasEditLink || hasIssueLink" class="selaras-docs-page-actions" :aria-label="messages.pageActions">
19
20
  <DocsEditLink v-if="hasEditLink" :path="path" />
20
21
  <a v-if="hasIssueLink" :href="links.issue" target="_blank" rel="noreferrer" class="selaras-docs-issue-link">
21
22
  <SIcon name="hugeicons:bug-01" aria-hidden="true" />
22
- Report an issue
23
+ {{ messages.reportIssue }}
23
24
  </a>
24
25
  </nav>
25
26
  </template>
@@ -2,10 +2,11 @@
2
2
  const { open } = useCommandPalette()
3
3
  const icons = useIcons()
4
4
  const messages = useMessages()
5
+ const docsMessages = useDocsMessages()
5
6
  </script>
6
7
 
7
8
  <template>
8
- <SButton variant="soft" color="neutral" size="sm" :icon="icons.search" aria-label="Search documentation" class="sm:min-w-48 xl:min-w-60" @click="open">
9
+ <SButton variant="soft" color="neutral" size="sm" :icon="icons.search" :aria-label="docsMessages.searchDocumentation" class="sm:min-w-48 xl:min-w-60" @click="open">
9
10
  <span class="hidden sm:inline">{{ messages.search }}</span>
10
11
  <span class="ms-auto hidden gap-1 sm:flex">
11
12
  <SKbd value="meta" size="sm" />
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  const appConfig = useAppConfig()
3
3
  const { data: navigation } = useDocsNavigation()
4
+ const messages = useDocsMessages()
4
5
  const sidebar = computed(() => appConfig.selarasDocs?.sidebar)
5
6
  </script>
6
7
 
@@ -8,7 +9,7 @@ const sidebar = computed(() => appConfig.selarasDocs?.sidebar)
8
9
  <SPageAside
9
10
  v-if="sidebar?.enabled !== false"
10
11
  class="selaras-docs-sidebar"
11
- aria-label="Documentation navigation"
12
+ :aria-label="messages.documentationNavigation"
12
13
  :ui="{ root: 'top-16 h-[calc(100vh-4rem)]' }"
13
14
  >
14
15
  <SContentNavigation :navigation="navigation ?? []" :collapsed="sidebar?.collapsed" />
@@ -7,13 +7,14 @@ defineProps<{
7
7
 
8
8
  const appConfig = useAppConfig()
9
9
  const docsConfig = computed(() => appConfig.selarasDocs ?? {})
10
+ const messages = useDocsMessages()
10
11
  </script>
11
12
 
12
13
  <template>
13
14
  <SPageAside
14
15
  v-if="links.length && docsConfig.toc?.enabled !== false"
15
16
  class="selaras-docs-toc"
16
- aria-label="Table of contents"
17
+ :aria-label="messages.tableOfContents"
17
18
  :ui="{ root: 'top-16 h-[calc(100vh-4rem)]' }"
18
19
  >
19
20
  <SContentToc :links="links" :title="docsConfig.toc?.title" />
@@ -14,6 +14,7 @@ const props = withDefaults(defineProps<{
14
14
  height: 540,
15
15
  })
16
16
  const selected = defineModel<string>('device')
17
+ const messages = useDocsMessages()
17
18
  const defaultDevices: readonly SelarasDocsViewportDevice[] = [
18
19
  { value: 'desktop', label: 'Desktop', icon: 'hugeicons:computer', width: 1024 },
19
20
  { value: 'tablet', label: 'Tablet', icon: 'hugeicons:tablet-01', width: 768 },
@@ -38,7 +39,7 @@ const previewUrl = computed(() => assetUrl(props.src))
38
39
  </p>
39
40
  </slot>
40
41
  <div class="flex items-center gap-2">
41
- <div class="inline-flex gap-1 rounded-[var(--selaras-resolved-radius-md)] border border-[var(--selaras-resolved-border-default)] p-1" role="group" aria-label="Preview viewport">
42
+ <div class="inline-flex gap-1 rounded-[var(--selaras-resolved-radius-md)] border border-[var(--selaras-resolved-border-default)] p-1" role="group" :aria-label="messages.previewViewport">
42
43
  <SButton
43
44
  v-for="option in devices" :key="option.value"
44
45
  :icon="option.icon" :aria-label="option.label" :aria-pressed="device.value === option.value"
@@ -0,0 +1,48 @@
1
+ import type { SelarasDocsLocaleOption } from '../../types'
2
+
3
+ interface DocsI18nRuntime {
4
+ locale?: string | { value?: string }
5
+ setLocale?: (code: string) => Promise<void> | void
6
+ }
7
+
8
+ interface DocsLocaleAppConfig {
9
+ selarasDocs?: {
10
+ i18n?: {
11
+ defaultLocale?: string
12
+ locales?: SelarasDocsLocaleOption[]
13
+ }
14
+ }
15
+ }
16
+
17
+ const fallbackLocales: SelarasDocsLocaleOption[] = [
18
+ { code: 'en', name: 'English', language: 'en-GB' },
19
+ ]
20
+
21
+ /**
22
+ * Read the active docs locale without importing @nuxtjs/i18n. The published
23
+ * docs layer must keep working in sites that do not install the module, so the
24
+ * runtime injection is read defensively and falls back to the configured
25
+ * default locale.
26
+ */
27
+ export function useDocsLocale() {
28
+ const nuxtApp = useNuxtApp()
29
+ const appConfig = useAppConfig() as DocsLocaleAppConfig
30
+ const configured = computed(() => appConfig.selarasDocs?.i18n?.locales ?? [])
31
+ const locales = computed<SelarasDocsLocaleOption[]>(() => configured.value.length ? configured.value : fallbackLocales)
32
+ const defaultLocale = computed(() => appConfig.selarasDocs?.i18n?.defaultLocale ?? locales.value[0]?.code ?? 'en')
33
+ const i18n = (nuxtApp as unknown as { $i18n?: DocsI18nRuntime }).$i18n
34
+ const locale = computed(() => {
35
+ const active = i18n?.locale
36
+ return (typeof active === 'string' ? active : active?.value) ?? defaultLocale.value
37
+ })
38
+ const localeOption = computed(() => locales.value.find(option => option.code === locale.value) ?? locales.value[0]!)
39
+ const hasLocaleSwitching = computed(() => locales.value.length > 1 && typeof i18n?.setLocale === 'function')
40
+
41
+ async function setLocale(code: string) {
42
+ if (code === locale.value || !i18n?.setLocale)
43
+ return
44
+ await i18n.setLocale(code)
45
+ }
46
+
47
+ return { locale, locales, defaultLocale, localeOption, hasLocaleSwitching, setLocale }
48
+ }
@@ -0,0 +1,20 @@
1
+ import type { SelarasDocsMessages } from '../../types'
2
+ import { resolveDocsMessages } from '../utils/docs-messages'
3
+
4
+ interface DocsMessagesAppConfig {
5
+ selarasDocs?: {
6
+ messages?: Partial<Record<string, SelarasDocsMessages>>
7
+ }
8
+ }
9
+
10
+ /** UI copy for the active locale, with consumer overrides applied. */
11
+ export function useDocsMessages() {
12
+ const appConfig = useAppConfig() as DocsMessagesAppConfig
13
+ const { locale, defaultLocale } = useDocsLocale()
14
+
15
+ return computed(() => resolveDocsMessages(
16
+ locale.value,
17
+ defaultLocale.value,
18
+ appConfig.selarasDocs?.messages?.[locale.value],
19
+ ))
20
+ }
@@ -1,26 +1,33 @@
1
- interface DocsNavigationNode {
2
- title: string
3
- path: string
4
- icon?: string | false
5
- order?: number
6
- collapse?: boolean
7
- navBadges?: Array<string | { text: string }>
8
- navigation?: boolean | {
9
- title?: string
10
- icon?: string | false
11
- order?: number
12
- navBadges?: Array<string | { text: string }>
13
- }
14
- children?: DocsNavigationNode[]
15
- }
1
+ import type { DocsNavigationNode } from '../utils/docs-navigation'
2
+ import { docsDefaultContentPath, docsLocalizedRoutePath } from '../utils/content-path'
3
+ import { applyDocsTranslatedTitles, withoutDocsLocaleFolders } from '../utils/docs-navigation'
16
4
 
17
5
  export function useDocsNavigation() {
18
6
  const appConfig = useAppConfig()
7
+ const { locale, defaultLocale, locales } = useDocsLocale()
8
+ const translatedFolder = computed(() => locales.value.find(option => option.code !== defaultLocale.value)?.code ?? '')
9
+ const localeFolders = computed(() => locales.value
10
+ .map(option => option.code)
11
+ .filter(code => code !== defaultLocale.value))
19
12
 
20
13
  return useAsyncData('selaras-docs-navigation', async () => {
21
14
  const tree = await queryCollectionNavigation('docs', ['order', 'icon', 'collapse', 'navBadges'])
22
15
  .order('order', 'ASC')
23
16
 
17
+ // The navigation tree always mirrors the default locale's structure, so a
18
+ // partially translated site never hides whole sections. Translated pages
19
+ // contribute their own titles; untranslated pages keep the source title.
20
+ let defaultTree = withoutDocsLocaleFolders(tree as DocsNavigationNode[], localeFolders.value)
21
+
22
+ if (locale.value !== defaultLocale.value && translatedFolder.value) {
23
+ const translated = await queryCollection('docs')
24
+ .where('path', 'LIKE', `/${translatedFolder.value}/%`)
25
+ .select('path', 'title')
26
+ .all()
27
+ const titles = new Map(translated.map(page => [docsDefaultContentPath(page.path, translatedFolder.value), page.title]))
28
+ defaultTree = applyDocsTranslatedTitles(defaultTree, titles)
29
+ }
30
+
24
31
  const excluded = new Set(appConfig.selarasDocs?.sidebar?.exclude ?? [])
25
32
  const visit = (items: DocsNavigationNode[], applyExclusions = false): DocsNavigationNode[] => items
26
33
  .filter(item => !applyExclusions || !excluded.has(item.path))
@@ -48,6 +55,12 @@ export function useDocsNavigation() {
48
55
  return a.order - b.order
49
56
  })
50
57
 
51
- return visit(tree as DocsNavigationNode[], excluded.size > 0)
52
- })
58
+ const localize = (items: DocsNavigationNode[]): DocsNavigationNode[] => items.map(item => ({
59
+ ...item,
60
+ path: docsLocalizedRoutePath(item.path, locale.value, defaultLocale.value),
61
+ ...(item.children ? { children: localize(item.children) } : {}),
62
+ }))
63
+
64
+ return localize(visit(defaultTree, excluded.size > 0))
65
+ }, { watch: [locale, defaultLocale] })
53
66
  }
@@ -0,0 +1,66 @@
1
+ import { docsContentPath, docsIsLocalizedContentPath, docsLocalizedContentPath, docsUnlocalizedRoutePath } from '../utils/content-path'
2
+
3
+ function unique<T>(items: T[]) {
4
+ return Array.from(new Set(items))
5
+ }
6
+
7
+ /**
8
+ * Resolve the content page for the active locale at the current URL. English
9
+ * (the default locale) lives at the content root; every other locale keeps its
10
+ * Markdown under `<locale>/` and is served under the locale-specific route.
11
+ *
12
+ * The public route's locale prefix is stripped before looking up its default
13
+ * content path. All configured locale variants are resolved in one batch so
14
+ * Nuxt Content includes every translation in the static payload. When the
15
+ * active locale has no translation, the default page is returned with
16
+ * `fallback: true` so the page can show an explicit translation notice.
17
+ */
18
+ export async function useDocsPageContent() {
19
+ const route = useRoute()
20
+ const { locale, defaultLocale, locales } = useDocsLocale()
21
+ const localeFolders = locales.value
22
+ .map(option => option.code)
23
+ .filter(code => code !== defaultLocale.value)
24
+ const routeLocale = computed(() => locales.value.find(option => route.path === `/${option.code}` || route.path.startsWith(`/${option.code}/`))?.code ?? locale.value)
25
+ const defaultPath = computed(() => docsContentPath(docsUnlocalizedRoutePath(route.path, routeLocale.value, defaultLocale.value)))
26
+ const contentPaths = computed(() => unique([
27
+ defaultPath.value,
28
+ ...localeFolders.map(folder => docsLocalizedContentPath(defaultPath.value, folder, defaultLocale.value)),
29
+ ]))
30
+
31
+ const { data, error, status, refresh } = await useAsyncData(
32
+ () => `selaras-docs:${defaultPath.value}`,
33
+ async () => {
34
+ const pages = await Promise.all(contentPaths.value.map(path => queryCollection('docs').path(path).first()))
35
+ const byLocale: Record<string, any> = {}
36
+ byLocale[defaultLocale.value] = pages[0]
37
+ for (let i = 0; i < localeFolders.length; i++)
38
+ byLocale[localeFolders[i]!] = pages[i + 1]
39
+ return { byLocale, defaultPath: defaultPath.value }
40
+ },
41
+ { watch: [() => route.path, routeLocale] },
42
+ )
43
+
44
+ const page = computed(() => data.value?.byLocale[routeLocale.value] ?? data.value?.byLocale[defaultLocale.value])
45
+ const contentPath = computed(() => routeLocale.value === defaultLocale.value
46
+ ? defaultPath.value
47
+ : data.value?.byLocale[routeLocale.value]
48
+ ? docsLocalizedContentPath(defaultPath.value, routeLocale.value, defaultLocale.value)
49
+ : defaultPath.value)
50
+ const hasTranslation = computed(() => routeLocale.value === defaultLocale.value
51
+ ? localeFolders.some(folder => docsIsLocalizedContentPath(data.value?.byLocale[folder]?.path ?? '', folder))
52
+ : docsIsLocalizedContentPath(data.value?.byLocale[routeLocale.value]?.path ?? '', routeLocale.value))
53
+ const isLocalizedPage = computed(() => routeLocale.value !== defaultLocale.value
54
+ && docsIsLocalizedContentPath(page.value?.path ?? '', routeLocale.value))
55
+
56
+ return {
57
+ page,
58
+ fallback: computed(() => routeLocale.value !== defaultLocale.value && !isLocalizedPage.value),
59
+ hasTranslation,
60
+ contentPath,
61
+ contentPaths: contentPaths.value,
62
+ error,
63
+ status,
64
+ refresh,
65
+ }
66
+ }
@@ -0,0 +1,7 @@
1
+ import { docsLocalizedRoutePath } from '../utils/content-path'
2
+
3
+ /** Localize an internal docs URL without coupling the published layer to i18n. */
4
+ export function useDocsRoutePath() {
5
+ const { locale, defaultLocale } = useDocsLocale()
6
+ return (path: string) => docsLocalizedRoutePath(path, locale.value, defaultLocale.value)
7
+ }
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  const appConfig = useAppConfig()
3
+ const messages = useDocsMessages()
3
4
  </script>
4
5
 
5
6
  <template>
@@ -9,7 +10,7 @@ const appConfig = useAppConfig()
9
10
  'selaras-docs-root--fluid': appConfig.selarasDocs?.main?.fluid,
10
11
  }"
11
12
  >
12
- <a class="selaras-docs-skip-link" href="#selaras-docs-main">Skip to content</a>
13
+ <a class="selaras-docs-skip-link" href="#selaras-docs-main">{{ messages.skipToContent }}</a>
13
14
  <DocsHeader />
14
15
  <div class="selaras-docs-shell">
15
16
  <DocsSidebar />
@@ -7,13 +7,14 @@ import ProseH4 from '@sewadah/selaras/components/ProseH4.vue'
7
7
  import ProseH5 from '@sewadah/selaras/components/ProseH5.vue'
8
8
  import ProseH6 from '@sewadah/selaras/components/ProseH6.vue'
9
9
  import ProsePre from '@sewadah/selaras/components/ProsePre.vue'
10
- import { docsContentPath } from '../utils/content-path'
10
+ import { docsDefaultContentPath, docsLocalizedRoutePath } from '../utils/content-path'
11
+ import { docsCanonicalUrl, docsSite } from '../utils/seo'
11
12
 
12
13
  const route = useRoute()
13
14
  const appConfig = useAppConfig()
14
15
  const nuxtApp = useNuxtApp()
15
- const contentPath = docsContentPath(route.path)
16
- const { data: page, error, status, refresh } = await useAsyncData(`selaras-docs:${contentPath}`, () => queryCollection('docs').path(contentPath).first())
16
+ const messages = useDocsMessages()
17
+ const { page, fallback, contentPath, hasTranslation, error, status, refresh } = await useDocsPageContent()
17
18
 
18
19
  const recoveringBuild = import.meta.client && (!page.value || error.value)
19
20
  && await nuxtApp.$docsCheckBuild(route.fullPath, true)
@@ -34,16 +35,38 @@ async function retryPage() {
34
35
  }
35
36
 
36
37
  definePageMeta({ layout: 'selaras-docs' })
38
+ const { locale, defaultLocale, locales, localeOption } = useDocsLocale()
39
+ const siteUrl = appConfig.selarasDocs?.site?.url || docsSite.url
40
+ const config = useRuntimeConfig()
41
+ const defaultRoutePath = computed(() => docsDefaultContentPath(contentPath.value, locale.value, defaultLocale.value))
42
+ const translatedPage = computed(() => locale.value !== defaultLocale.value && contentPath.value.startsWith(`/${locale.value}/`))
43
+ const canonicalPath = computed(() => contentPath.value)
44
+ const canonicalUrl = computed(() => siteUrl ? docsCanonicalUrl(canonicalPath.value, siteUrl, config.app.baseURL) : undefined)
45
+ const alternateLinks = computed(() => {
46
+ if ((locale.value !== defaultLocale.value && !translatedPage.value) || !hasTranslation.value || !siteUrl)
47
+ return []
48
+ const translatedLocale = locales.value.find(item => item.code !== defaultLocale.value)
49
+ const defaultLanguage = locales.value.find(item => item.code === defaultLocale.value)?.language ?? defaultLocale.value
50
+ const translatedPath = docsLocalizedRoutePath(defaultRoutePath.value, translatedLocale?.code ?? 'id', defaultLocale.value)
51
+ const defaultUrl = docsCanonicalUrl(defaultRoutePath.value, siteUrl, config.app.baseURL)
52
+ return [
53
+ { rel: 'alternate' as const, type: 'text/html', hreflang: defaultLanguage, href: defaultUrl },
54
+ ...(translatedLocale?.language ? [{ rel: 'alternate' as const, type: 'text/html', hreflang: translatedLocale.language, href: docsCanonicalUrl(translatedPath, siteUrl, config.app.baseURL) }] : []),
55
+ { rel: 'alternate' as const, type: 'text/html', hreflang: 'x-default', href: defaultUrl },
56
+ ]
57
+ })
37
58
  useSeoMeta({
38
- title: () => page.value?.title ?? appConfig.selarasDocs?.errors?.page?.title ?? 'Documentation unavailable',
59
+ title: () => page.value?.title ?? appConfig.selarasDocs?.errors?.page?.title ?? messages.value.documentationUnavailable,
39
60
  description: () => page.value?.description ?? appConfig.selarasDocs?.site?.description,
40
- robots: () => error.value ? 'noindex' : undefined,
61
+ robots: () => error.value || fallback.value ? 'noindex' : undefined,
62
+ ogUrl: () => canonicalUrl.value,
63
+ ogLocale: () => (localeOption.value.language ?? locale.value).replace('-', '_'),
41
64
  })
42
65
  useHead(() => ({
66
+ htmlAttrs: { lang: localeOption.value.language ?? locale.value },
67
+ ...(fallback.value && { meta: [{ name: 'robots', content: 'noindex, follow' }] }),
43
68
  ...(appConfig.selarasDocs?.site?.titleTemplate && { titleTemplate: appConfig.selarasDocs.site.titleTemplate }),
44
- ...(appConfig.selarasDocs?.site?.url && {
45
- link: [{ rel: 'canonical', href: new URL(route.path, appConfig.selarasDocs.site.url).href }],
46
- }),
69
+ ...(canonicalUrl.value && { link: [{ rel: 'canonical', href: canonicalUrl.value, key: 'canonical', tagPriority: 'critical' }, ...alternateLinks.value] }),
47
70
  }))
48
71
 
49
72
  const proseComponents = {
@@ -69,6 +92,9 @@ const surround = useDocsSurround()
69
92
  <p v-if="page!.description" class="selaras-docs-description">
70
93
  {{ page!.description }}
71
94
  </p>
95
+ <p v-if="fallback" class="selaras-docs-translation-notice" role="note">
96
+ {{ messages.untranslatedNotice }}
97
+ </p>
72
98
  <ContentRenderer :value="page!" :components="proseComponents" class="selaras-docs-content selaras-prose">
73
99
  <template #empty>
74
100
  <DocsEmptyState />
@@ -2,3 +2,53 @@
2
2
  export function docsContentPath(path: string) {
3
3
  return path.replace(/\/+$/, '') || '/'
4
4
  }
5
+
6
+ /** Remove the locale segment used by public routes (`/id/guide` -> `/guide`). */
7
+ export function docsUnlocalizedRoutePath(path: string, locale: string, defaultLocale = 'en') {
8
+ const base = docsContentPath(path)
9
+ if (!locale || locale === defaultLocale)
10
+ return base
11
+ return docsDefaultContentPath(base, locale)
12
+ }
13
+
14
+ /** Add the active locale prefix to an internal public route. */
15
+ export function docsLocalizedRoutePath(path: string, locale: string, defaultLocale = 'en') {
16
+ const suffixIndex = [path.indexOf('?'), path.indexOf('#')].filter(index => index >= 0).sort((a, b) => a - b)[0] ?? path.length
17
+ const pathname = path.slice(0, suffixIndex) || '/'
18
+ const suffix = path.slice(suffixIndex)
19
+ if (!pathname.startsWith('/') || pathname.startsWith('//'))
20
+ return path
21
+
22
+ const base = locale === defaultLocale ? docsContentPath(pathname) : docsUnlocalizedRoutePath(pathname, locale, defaultLocale)
23
+ if (!locale || locale === defaultLocale)
24
+ return `${base}${suffix}`
25
+ return `${base === '/' ? `/${locale}` : `/${locale}${base}`}${suffix}`
26
+ }
27
+
28
+ /**
29
+ * The content path that stores a page for a locale. English (the default
30
+ * locale) lives at the content root; every other locale keeps its Markdown
31
+ * under `<locale>/` and is served under that locale's public prefix.
32
+ */
33
+ export function docsLocalizedContentPath(path: string, locale: string, defaultLocale = 'en') {
34
+ const base = docsContentPath(path)
35
+ if (!locale || locale === defaultLocale)
36
+ return base
37
+ return base === '/' ? `/${locale}` : `/${locale}${base}`
38
+ }
39
+
40
+ /** Strip a locale folder from a content path (`/id/components/button` -> `/components/button`). */
41
+ export function docsDefaultContentPath(path: string, locale: string, defaultLocale = 'en') {
42
+ const base = docsContentPath(path)
43
+ if (!locale || locale === defaultLocale)
44
+ return base
45
+ if (base !== `/${locale}` && !base.startsWith(`/${locale}/`))
46
+ return base
47
+ return base.slice(locale.length + 1) || '/'
48
+ }
49
+
50
+ /** Whether a content path belongs to a non-default locale folder. */
51
+ export function docsIsLocalizedContentPath(path: string, locale: string) {
52
+ const base = docsContentPath(path)
53
+ return base === `/${locale}` || base.startsWith(`/${locale}/`)
54
+ }
@@ -0,0 +1,95 @@
1
+ import type { SelarasDocsMessages } from '../../types'
2
+
3
+ /**
4
+ * The docs layer's own UI copy. The layer must not depend on @nuxtjs/i18n, so
5
+ * this catalog is resolved from the active locale code instead of vue-i18n
6
+ * messages. Sites can replace any string per locale through
7
+ * `app.config.selarasDocs.messages`.
8
+ */
9
+ export const docsMessages: Record<string, SelarasDocsMessages> = {
10
+ en: {
11
+ skipToContent: 'Skip to content',
12
+ documentationNavigation: 'Documentation navigation',
13
+ pageActions: 'Page actions',
14
+ reportIssue: 'Report an issue',
15
+ editPage: 'Edit this page',
16
+ footerNavigation: 'Footer navigation',
17
+ sourceRepository: 'Source repository',
18
+ openNavigation: 'Open documentation navigation',
19
+ mainNavigation: 'Main navigation',
20
+ previewViewport: 'Preview viewport',
21
+ tableOfContents: 'Table of contents',
22
+ searchDocumentation: 'Search documentation',
23
+ languageSwitcher: 'Switch to {language}',
24
+ documentationUnavailable: 'Documentation unavailable',
25
+ untranslatedNotice: 'This page is not yet available in Bahasa Indonesia. Showing the English original.',
26
+ emptyTitle: 'No content yet',
27
+ emptyDescription: 'There’s no content on this page yet. You can explore the rest of the documentation using the navigation.',
28
+ notFoundTitle: 'Page not found',
29
+ notFoundDescription: 'The link may have changed, or this page may no longer exist. You can start again from the homepage.',
30
+ fatalTitle: 'Something went wrong',
31
+ fatalDescription: 'We couldn’t load this page. Reload it to try again, or return to the homepage.',
32
+ pageTitle: 'This page couldn’t load',
33
+ pageDescription: 'Please try again. You can still use the navigation to explore other pages.',
34
+ exampleTitle: 'This example couldn’t load',
35
+ exampleDescription: 'Try loading the example again. The rest of the documentation is still available.',
36
+ retry: 'Try again',
37
+ retrying: 'Trying again…',
38
+ reload: 'Reload page',
39
+ backToDocumentation: 'Back to documentation',
40
+ home: 'Go to homepage',
41
+ },
42
+ id: {
43
+ skipToContent: 'Lewati ke konten',
44
+ documentationNavigation: 'Navigasi dokumentasi',
45
+ pageActions: 'Aksi halaman',
46
+ reportIssue: 'Laporkan masalah',
47
+ editPage: 'Sunting halaman ini',
48
+ footerNavigation: 'Navigasi footer',
49
+ sourceRepository: 'Repositori sumber',
50
+ openNavigation: 'Buka navigasi dokumentasi',
51
+ mainNavigation: 'Navigasi utama',
52
+ previewViewport: 'Pratinjau viewport',
53
+ tableOfContents: 'Daftar isi',
54
+ searchDocumentation: 'Cari dokumentasi',
55
+ languageSwitcher: 'Ganti bahasa ke {language}',
56
+ documentationUnavailable: 'Dokumentasi tidak tersedia',
57
+ untranslatedNotice: 'Halaman ini belum tersedia dalam Bahasa Indonesia. Menampilkan versi bahasa Inggris.',
58
+ emptyTitle: 'Belum ada konten',
59
+ emptyDescription: 'Halaman ini belum memiliki konten. Anda dapat menjelajahi bagian dokumentasi lain melalui navigasi.',
60
+ notFoundTitle: 'Halaman tidak ditemukan',
61
+ notFoundDescription: 'Tautan mungkin sudah berubah, atau halaman ini tidak lagi tersedia. Anda dapat memulai lagi dari beranda.',
62
+ fatalTitle: 'Terjadi kesalahan',
63
+ fatalDescription: 'Halaman ini tidak dapat dimuat. Muat ulang untuk mencoba lagi, atau kembali ke beranda.',
64
+ pageTitle: 'Halaman ini tidak dapat dimuat',
65
+ pageDescription: 'Silakan coba lagi. Anda tetap dapat menjelajahi halaman lain melalui navigasi.',
66
+ exampleTitle: 'Contoh ini tidak dapat dimuat',
67
+ exampleDescription: 'Coba muat ulang contoh ini. Dokumentasi lainnya tetap tersedia.',
68
+ retry: 'Coba lagi',
69
+ retrying: 'Mencoba lagi…',
70
+ reload: 'Muat ulang halaman',
71
+ backToDocumentation: 'Kembali ke dokumentasi',
72
+ home: 'Ke beranda',
73
+ },
74
+ }
75
+
76
+ /**
77
+ * Resolve the copy for a locale: default-locale strings first, then the
78
+ * locale's own strings, then any consumer overrides.
79
+ */
80
+ export function resolveDocsMessages(
81
+ locale: string,
82
+ defaultLocale = 'en',
83
+ overrides?: Partial<SelarasDocsMessages>,
84
+ ): Required<SelarasDocsMessages> {
85
+ return {
86
+ ...docsMessages[defaultLocale],
87
+ ...docsMessages[locale],
88
+ ...overrides,
89
+ } as Required<SelarasDocsMessages>
90
+ }
91
+
92
+ /** Replace `{name}` placeholders in a resolved message. */
93
+ export function formatDocsMessage(template: string, values: Record<string, string>) {
94
+ return template.replace(/\{(\w+)\}/g, (match, key: string) => values[key] ?? match)
95
+ }
@@ -0,0 +1,36 @@
1
+ export interface DocsNavigationNode {
2
+ title: string
3
+ path: string
4
+ icon?: string | false
5
+ order?: number
6
+ collapse?: boolean
7
+ navBadges?: Array<string | { text: string }>
8
+ navigation?: boolean | {
9
+ title?: string
10
+ icon?: string | false
11
+ order?: number
12
+ navBadges?: Array<string | { text: string }>
13
+ }
14
+ children?: DocsNavigationNode[]
15
+ }
16
+
17
+ /** Drop nodes that live in a non-default locale folder from a content tree. */
18
+ export function withoutDocsLocaleFolders(items: DocsNavigationNode[], localeFolders: Iterable<string>): DocsNavigationNode[] {
19
+ const folders = new Set(localeFolders)
20
+ const isLocalized = (path: string) => [...folders].some(code => path === `/${code}` || path.startsWith(`/${code}/`))
21
+ return items
22
+ .filter(item => !isLocalized(item.path))
23
+ .map(item => item.children ? { ...item, children: withoutDocsLocaleFolders(item.children, folders) } : item)
24
+ }
25
+
26
+ /**
27
+ * Replace default-locale navigation titles with translated ones. The tree keeps
28
+ * the default locale's structure and paths, so untranslated pages still appear.
29
+ */
30
+ export function applyDocsTranslatedTitles(items: DocsNavigationNode[], titles: Map<string, string>): DocsNavigationNode[] {
31
+ return items.map(item => ({
32
+ ...item,
33
+ title: titles.get(item.path) ?? item.title,
34
+ ...(item.children ? { children: applyDocsTranslatedTitles(item.children, titles) } : {}),
35
+ }))
36
+ }
@@ -0,0 +1,20 @@
1
+ export const docsSite = {
2
+ name: 'Selaras',
3
+ url: 'https://selarasui.my.id',
4
+ description: 'Nuxt-first components for adaptable design systems.',
5
+ }
6
+
7
+ export function docsCanonicalUrl(path: string, siteUrl: string, baseURL: string) {
8
+ const pathname = (path.split(/[?#]/)[0] || '/').replace(/\/$/, '') || '/'
9
+ const base = `/${baseURL.split('/').filter(Boolean).join('/')}`.replace(/\/$/, '')
10
+ return new URL(`${base}${pathname === '/' ? '/' : `${pathname}/`}`, siteUrl).href
11
+ }
12
+
13
+ export function docsPathWithoutBase(path: string, baseURL: string) {
14
+ const base = baseURL.replace(/\/$/, '')
15
+ return base && (path === base || path.startsWith(`${base}/`)) ? path.slice(base.length) || '/' : path
16
+ }
17
+
18
+ export function docsPageTitle(title: string) {
19
+ return title === docsSite.name ? title : `${title} β€” ${docsSite.name}`
20
+ }
package/content.config.ts CHANGED
@@ -12,11 +12,23 @@ export default defineContentConfig({
12
12
  {
13
13
  cwd: resolve(options.rootDir, 'content'),
14
14
  include: '**/*.md',
15
+ // Translations live under `<locale>/` and are served from the
16
+ // default locale's URL; only the default locale owns the root.
17
+ exclude: ['id/**'],
18
+ },
19
+ {
20
+ cwd: resolve(options.rootDir, 'content'),
21
+ include: 'id/**/*.md',
15
22
  },
16
23
  {
17
24
  cwd: resolve(options.rootDir, 'content'),
18
25
  // Nuxt Content reads this metadata into the navigation tree.
19
26
  include: '**/.navigation.yml',
27
+ exclude: ['id/**'],
28
+ },
29
+ {
30
+ cwd: resolve(options.rootDir, 'content'),
31
+ include: 'id/**/.navigation.yml',
20
32
  },
21
33
  ],
22
34
  schema: z.object({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sewadah/selaras-docs",
3
3
  "type": "module",
4
- "version": "1.3.3",
4
+ "version": "1.4.0",
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.1.0",
36
+ "@sewadah/selaras": "^1.2.0",
37
37
  "tailwindcss": "^4.3.0"
38
38
  }
39
39
  }
package/types.d.ts CHANGED
@@ -9,6 +9,8 @@ export interface SelarasDocsModuleOptions {
9
9
 
10
10
  export interface SelarasDocsLink {
11
11
  label?: string
12
+ /** Per-locale labels for links in the consuming site's navigation. */
13
+ labels?: Record<string, string>
12
14
  to: string
13
15
  icon?: string
14
16
  target?: string
@@ -20,6 +22,8 @@ export interface SelarasDocsLink {
20
22
  export interface SelarasDocsNavigationItem {
21
23
  /** Required so every header control has an accessible name. */
22
24
  label: string
25
+ /** Per-locale labels for links in the consuming site's navigation. */
26
+ labels?: Record<string, string>
23
27
  to?: string
24
28
  icon?: string
25
29
  target?: string
@@ -44,7 +48,65 @@ export interface SelarasDocsErrorCopy {
44
48
  description?: string
45
49
  }
46
50
 
51
+ /** A locale offered by the docs language switcher. */
52
+ export interface SelarasDocsLocaleOption {
53
+ code: string
54
+ /** Label shown in the switcher, written in the locale's own language. */
55
+ name: string
56
+ /** BCP-47 tag used for `html lang` and locale-aware components, e.g. `en-GB`. */
57
+ language?: string
58
+ }
59
+
60
+ export interface SelarasDocsI18n {
61
+ /** Locale served without URL changes and used for content at the content root. @default 'en' */
62
+ defaultLocale?: string
63
+ /** Locales available in the language switcher. @default [{ code: 'en', name: 'English', language: 'en-GB' }] */
64
+ locales?: SelarasDocsLocaleOption[]
65
+ }
66
+
67
+ /**
68
+ * UI copy shipped by the docs layer. Override a locale's copy through
69
+ * `app.config.selarasDocs.messages[locale]` when a site needs different wording.
70
+ */
71
+ export interface SelarasDocsMessages {
72
+ skipToContent?: string
73
+ documentationNavigation?: string
74
+ pageActions?: string
75
+ reportIssue?: string
76
+ editPage?: string
77
+ footerNavigation?: string
78
+ sourceRepository?: string
79
+ openNavigation?: string
80
+ mainNavigation?: string
81
+ previewViewport?: string
82
+ tableOfContents?: string
83
+ searchDocumentation?: string
84
+ /** Accessible name for the language switcher; `{language}` is replaced. */
85
+ languageSwitcher?: string
86
+ documentationUnavailable?: string
87
+ untranslatedNotice?: string
88
+ emptyTitle?: string
89
+ emptyDescription?: string
90
+ notFoundTitle?: string
91
+ notFoundDescription?: string
92
+ fatalTitle?: string
93
+ fatalDescription?: string
94
+ pageTitle?: string
95
+ pageDescription?: string
96
+ exampleTitle?: string
97
+ exampleDescription?: string
98
+ retry?: string
99
+ retrying?: string
100
+ reload?: string
101
+ backToDocumentation?: string
102
+ home?: string
103
+ }
104
+
47
105
  export interface SelarasDocsAppConfig {
106
+ /** Locales, the default locale, and language-switcher options. */
107
+ i18n?: SelarasDocsI18n
108
+ /** Per-locale overrides for the UI copy shipped by the docs layer. */
109
+ messages?: Partial<Record<string, SelarasDocsMessages>>
48
110
  /** Copy shown for an existing Markdown page with no body content. */
49
111
  empty?: {
50
112
  title?: string
@@ -111,6 +173,7 @@ export interface SelarasDocsAppConfig {
111
173
  }
112
174
  footer?: {
113
175
  text?: string
176
+ textByLocale?: Record<string, string>
114
177
  links?: SelarasDocsLink[]
115
178
  /** Let the footer span the viewport instead of the docs shell width. */
116
179
  fluid?: boolean