Skip to content

Fix : Dynamically set html lang attribute based on selected language (#9193) #9199

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

Shivang14d04
Copy link

@Shivang14d04 Shivang14d04 commented Jul 3, 2025

Fixes #9193

Short description of what this resolves:

This resolves an issue where the <html lang="en"> attribute was hardcoded, preventing proper accessibility and locale-based styling. It sets the lang attribute dynamically based on the active language in the app.

Changes proposed in this pull request:

  • Added a new Ember initializer set-html-lang
  • Used appInstance.lookup('service:intl') to get the current locale
  • Set document.documentElement.lang dynamically at app boot
  • Added error handling for robustness

Checklist

  • I have read the Contribution & Best practices Guide.
  • My branch is up-to-date with the Upstream development branch.
  • The acceptance, integration, unit tests and linter pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by Sourcery

Initialize the HTML lang attribute dynamically from the Ember Intl service on application boot

Bug Fixes:

  • Fix hardcoded HTML lang attribute by setting it based on the active locale from the Ember Intl service

Enhancements:

  • Add error handling in the initializer to log any failures when setting the lang attribute

Copy link

sourcery-ai bot commented Jul 3, 2025

Reviewer's Guide

Introduces an Ember initializer that dynamically sets the <html lang> attribute from the app’s active locale with error handling for robustness.

Sequence diagram for setting the html lang attribute at app boot

sequenceDiagram
    participant AppInstance
    participant IntlService
    participant Document

    AppInstance->>IntlService: lookup('service:intl')
    IntlService-->>AppInstance: return current locale
    AppInstance->>Document: set document.documentElement.lang = locale
    Note right of Document: If locale unavailable, defaults to 'en'
    AppInstance->>AppInstance: catch errors and log if any
Loading

Class diagram for the new set-html-lang initializer

classDiagram
    class SetHtmlLangInitializer {
      +initialize(appInstance)
    }
    class IntlService {
      +locale: Array
    }
    SetHtmlLangInitializer ..> IntlService : uses
    SetHtmlLangInitializer ..> Document : sets lang attribute
Loading

File-Level Changes

Change Details Files
Added an initializer to dynamically set the HTML lang attribute from the active locale
  • Created set-html-lang initializer module
  • Used appInstance.lookup('service:intl') to obtain current locale
  • Set document.documentElement.lang to the first locale code, defaulting to 'en'
  • Wrapped the logic in a try/catch block and logged errors on failure
app/initializers/set-html-lang.js

Assessment against linked issues

Issue Objective Addressed Explanation
#9193 Set the lang attribute of the html tag dynamically based on the application's language setting.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

vercel bot commented Jul 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-event-frontend ❌ Failed (Inspect) Jul 3, 2025 6:14pm

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Shivang14d04 - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

[BUG] Set html lang attribute according to language
1 participant