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
HTML "lang" attribute support #133
Comments
There isn't any helper of this library right now for this. (Maybe we can consider to add it 🙂). Meanwhile, you can handle this with this: import Document, { Html, Head, Main, NextScript } from 'next/document'
import i18nConfig from '../i18n.json'
function documentLang({ __NEXT_DATA__}) {
const { page } = __NEXT_DATA__
const [,langQuery] = page.split('/')
const lang = i18nConfig.allLanguages.find(l => l === langQuery)
return lang || i18nConfig.defaultLanguage
}
export default class MyDocument extends Document {
render() {
return (
<Html lang={documentLang(this.props)}>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
} |
Thanks for the quick feedback. I was wondering, why it's not possible to use |
The reason is that |
I'm exporting the next project using static html, so it shouldn't be an issue for this use case. Thanks anyway! |
In this case, is not a problem and you can use However, using SSR on some page ( |
@neslinesli93 on import Document, { Html, Head, Main, NextScript } from 'next/document'
import documentLang from 'next-translate/documentLang'
export default class MyDocument extends Document {
render() {
return (
<Html lang={documentLang(this.props)}>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
} |
Hi,
is it possible to set a custom
lang
attribute for thehtml
tag inside a custom_document.js
, while keeping static site generation support? I think it could be fairly easy to inject it at build time in the generated html...The text was updated successfully, but these errors were encountered: