Sha256: 91c0eb484892c9bafb36b5ccbb6607eb379f9cb19faaa590f10d8bfa3e80c404

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

# Produces `<brut-locale-detection>`
class Brut::FrontEnd::Components::LocaleDetection < Brut::FrontEnd::Component
  def initialize(session:)
    @timezone = session.timezone_from_browser
    @locale   = session.http_accept_language.known? ? session.http_accept_language.weighted_locales.first&.locale : nil
    @url      = Brut::FrontEnd::Handlers::LocaleDetectionHandler.routing
  end

  def render
    attributes = {
      "url" => @url,
    }
    if @timezone
      attributes["timezone-from-server"] = @timezone.name
    end
    if @locale
      attributes["locale-from-server"] = @locale
    end
    if !Brut.container.project_env.production?
      attributes["show-warnings"] = true
    end

    html_tag("brut-locale-detection",**attributes)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brut-0.0.1 lib/brut/front_end/components/locale_detection.rb