Skip to content

Allow configuring <html lang> via html-lang file#92

Open
MavenRain wants to merge 2 commits intolamdera:lamdera-nextfrom
MavenRain:feat/html-lang-attribute
Open

Allow configuring <html lang> via html-lang file#92
MavenRain wants to merge 2 commits intolamdera:lamdera-nextfrom
MavenRain:feat/html-lang-attribute

Conversation

@MavenRain
Copy link
Copy Markdown

Read an optional html-lang file from the project root to set the lang attribute on the generated tag. If the file contains e.g. "fr", the output becomes . If absent or empty, the tag is plain as before. Fixes #84.

  Read an optional html-lang file from the project root to set the
  lang attribute on the generated <html> tag.  If the file contains
  e.g. "fr", the output becomes <html lang="fr">.  If absent or empty,
  the tag is plain <html> as before.  Fixes lamdera#84.
Comment thread extra/Lamdera/Live.hs Outdated
let trimmed = T.strip lang in
if T.null trimmed
then "<html>"
else "<html lang=\"" <> T.encodeUtf8Builder trimmed <> "\">"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should HTML-escape the value. Otherwise people will end up writing stuff like this in the file:

en" other-attribute="i want it" third="yes

@lydell
Copy link
Copy Markdown
Contributor

lydell commented Apr 1, 2026

I don’t think this solves the problem fully. What if you have a multi-lingual Lamdera app where you can change the language?

@CharlonTank
Copy link
Copy Markdown
Contributor

I don’t think this solves the problem fully. What if you have a multi-lingual Lamdera app where you can change the language?

Yup it seems that it doesn't help, my app handles 12 languages, I really need this to be fixed

  Prevents attribute injection via the html-lang file by escaping
  &, ", <, > as HTML entities. Addresses PR review feedback from lydell.
@MavenRain
Copy link
Copy Markdown
Author

I don’t think this solves the problem fully. What if you have a multi-lingual Lamdera app where you can change the language?

I think this might be a bit more involved than a simple code fix. I'm wondering if a JS approach or Elm port message might be more appropriate for dynamic lang updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuring <html lang> attribute

3 participants