Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(locales): use correct lang #276

Merged
merged 3 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/config/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ module.exports = {

The `lang` attribute for the site. This will render as a `<html lang="en-US">` tag in the page HTML.

Note that the `lang` attribute will only be added when building the site via `vitepress build`. You will not see this rendered during `vitepress dev`.

```js
module.exports = {
lang: 'en-US'
Expand Down
22 changes: 21 additions & 1 deletion src/client/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import 'vite/dynamic-import-polyfill'
import { App, createApp as createClientApp, createSSRApp, h } from 'vue'
import {
App,
createApp as createClientApp,
createSSRApp,
h,
onMounted,
watch
} from 'vue'
import { inBrowser, pathToFile } from './utils'
import { Router, RouterSymbol, createRouter } from './router'
import { mixinGlobalComputed, mixinGlobalComponents } from './mixin'
Expand All @@ -15,6 +22,19 @@ const NotFound = Theme.NotFound || (() => '404 Not Found')
const VitePressApp = {
name: 'VitePressApp',
setup() {
const siteData = useSiteDataByRoute()

// change the language on the HTML element based on the current lang
onMounted(() => {
watch(
() => siteData.value.lang,
(lang: string) => {
document.documentElement.lang = lang
},
{ immediate: true }
)
})

if (import.meta.env.PROD) {
// in prod mode, enable intersectionObserver based pre-fetch
usePrefetch()
Expand Down
2 changes: 1 addition & 1 deletion src/client/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { reactive, inject, markRaw, nextTick, readonly } from 'vue'
import type { Component, InjectionKey } from 'vue'
import { PageData } from '../../../types/shared'
import { inBrowser } from './utils'

export interface Route {
path: string
Expand Down Expand Up @@ -38,7 +39,6 @@ export function createRouter(
fallbackComponent?: Component
): Router {
const route = reactive(getDefaultRoute())
const inBrowser = typeof window !== 'undefined'

function go(href: string = inBrowser ? location.href : '/') {
// ensure correct deep link so page refresh lands on correct files.
Expand Down
4 changes: 3 additions & 1 deletion src/client/app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const inBrowser = typeof window !== 'undefined'
import { inBrowser } from '/@shared/config'

export { inBrowser }

/**
* Join two paths by resolving the slash collision.
Expand Down
2 changes: 1 addition & 1 deletion src/shared/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SiteData } from '/@types/shared'

const inBrowser = typeof window !== 'undefined'
export const inBrowser = typeof window !== 'undefined'

function findMatchRoot(route: string, roots: string[]) {
// first match to the routes with the most deep level.
Expand Down