Skip to content
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

[#1547] Add and use Current.locale #1623

Closed
wants to merge 18 commits into from
Closed

Conversation

veganstraightedge
Copy link
Contributor

@veganstraightedge veganstraightedge commented May 25, 2020

Closes #1547

Like #1621

Use CurrentAttributes for the current locale, which can be set from:

  • subdomain
  • user's browser setting
  • or from the URL params (like in TCE).

@CobyR CobyR temporarily deployed to crimethinc-staging-pr-1623 May 25, 2020 23:56 Inactive
@veganstraightedge veganstraightedge temporarily deployed to crimethinc-staging-pr-1623 May 26, 2020 00:06 Inactive
@veganstraightedge veganstraightedge temporarily deployed to crimethinc-staging-pr-1623 May 26, 2020 00:13 Inactive
<ul>
<li class="nav-link"><%= link_to t('header.locale_articles'), language_path(@site_locale.canonical) %></li>
<li class="nav-link"><%= link_to t('header.locale_articles'), language_path(Current.locale.name) %></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if this is the source of the test failures, but canonical == slug

Suggested change
<li class="nav-link"><%= link_to t('header.locale_articles'), language_path(Current.locale.name) %></li>
<li class="nav-link"><%= link_to t('header.locale_articles'), language_path(Current.locale.slug) %></li>

Comment on lines +19 to +22
def set_current_locale
Current.locale = ::Locale.find_by abbreviation: I18n.locale
end

Copy link
Contributor

@astronaut-wannabe astronaut-wannabe May 30, 2020

Choose a reason for hiding this comment

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

this is why the tests are failing.

You are making it so that the routing logic now depends on the locale database tables to exist an be populated

this will be nil in the specs because there are no locales, and that will make line 36 fail.

return if Current.locale.english?

you can get the specs passing by putting before { create(:locale, :en) } at the top of the failing specs, but this brings up a question for me

should middleware routing be tied to the state of the DB? and does making a database call outside of application code introduce any risks (security or otherwise)

I am not familiar enough with rack to really know, but if it's fine then adding the before in failing specs should do the trick

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.

Use Current Attributes for: Current.locale
3 participants