Add lang attribute to <html> tag in page template#5811
Add lang attribute to <html> tag in page template#5811evnchn wants to merge 2 commits intozauberzeug:mainfrom
lang attribute to <html> tag in page template#5811Conversation
Sets the HTML `lang` attribute based on the NiceGUI language setting, improving accessibility and SEO. The language code is split on '-' to use just the primary subtag (e.g. 'en' from 'en-US'). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
falkoschindler
left a comment
There was a problem hiding this comment.
Thanks, @evnchn!
One concern about the current approach:
split('-')[0] discards meaningful region/script information for several languages in the Language type. For example:
zh-CN(Simplified Chinese) andzh-TW(Traditional Chinese) both become justzh- screen readers use thelangattribute to select the correct voice/pronunciation, and these variants are meaningfully differentpt-BR(Brazilian Portuguese) andpt(European Portuguese) both becomept
Almost all Quasar language codes are already valid BCP 47 tags. The simplest fix would be to pass the full value directly:
<html lang="{{ language }}">This preserves zh-CN, pt-BR, ko-KR, etc. where the distinction matters for accessibility.
|
I agree with you. |
|
One thing to consider: the Before this change, the So for a developer with e.g. a German-language app who never touched the Could this be made opt-in instead (e.g. only emit |
|
Hmm fair. Not only that, considering cases where the user doesn't know what the language is (perhaps user-provided content dominates), the possibility of |
|
@falkoschindler do you think evnchn#85 is ready to be brought upstream? |
|
@falkoschindler I closed it to bake stuff into 1 commit and ask Claude Code to review (as usual) It is alive at https://github.com/evnchn/nicegui/tree/copilot/add-lang-attribute-html, but sure let's focus on 3.8 first. |
|
We have agreed to tackle i18n not in 3.10. I'm not sure if it will be 3.11 though (since if further work is required for the NiceGUI docs design, doing the i18n later dodges merge conflicts) |
Motivation
The
<html>tag in NiceGUI's page template lacks alangattribute. This affects accessibility (screen readers) and SEO (search engines use it to determine page language).Split out from #5767 per review feedback — this is a library-wide template change affecting all NiceGUI users.
Implementation
nicegui/templates/index.html: Changes<html>to<html lang="{{ language.split('-')[0] }}">, using the primary language subtag from the configured NiceGUI language (e.g.'en'from'en-US')The
languagetemplate variable is always populated viaself.page.resolve_language()inClient.build_response(), so it is neverNone.Progress
🤖 Generated with Claude Code