diff --git a/docs/guide/global-computed.md b/docs/guide/global-computed.md index d1c0d3f1..384d0e38 100644 --- a/docs/guide/global-computed.md +++ b/docs/guide/global-computed.md @@ -64,6 +64,14 @@ Reference of `$page.frontmatter`. } ``` +## $lang + +The language of the current page. Default: `en-US`. + +## $localePath + +The locale path prefix for the current page. Default: `/`. + ## $title Value of the `` label used for the current page. diff --git a/src/client/app/mixin.ts b/src/client/app/mixin.ts index 24841ce8..061c046a 100644 --- a/src/client/app/mixin.ts +++ b/src/client/app/mixin.ts @@ -42,6 +42,25 @@ export function mixinGlobalComputed( } }, + $lang: { + get() { + return siteByRoute.value.lang + } + }, + + $localePath: { + get() { + const { locales } = site.value + const { lang } = siteByRoute.value + + const path = Object.keys(locales).find( + (lp) => locales[lp].lang === lang + ) + + return (locales && path) || '/' + } + }, + $title: { get() { return page.value.title