Extract methods in locale switcher
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
<% if I18n.available_locales.size > 1 %>
|
<div class="locale">
|
||||||
<div class="locale">
|
<form class="locale-form">
|
||||||
<form class="locale-form">
|
<label class="inline-block" for="locale-switcher">
|
||||||
<label class="inline-block" for="locale-switcher">
|
<%= t("layouts.header.locale") %>
|
||||||
<%= t("layouts.header.locale") %>
|
</label>
|
||||||
</label>
|
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
||||||
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
<% locales.map do |loc| %>
|
||||||
<% I18n.available_locales.map do |loc| %>
|
<option <%= "selected" if loc == I18n.locale %>
|
||||||
<option <%= "selected" if loc == I18n.locale %>
|
value="<%= current_path_with_query_params(locale: loc) %>"><%= name_for_locale(loc) %></option>
|
||||||
value="<%= current_path_with_query_params(locale: loc) %>"><%= name_for_locale(loc) %></option>
|
<% end %>
|
||||||
<% end %>
|
</select>
|
||||||
</select>
|
</form>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
||||||
delegate :name_for_locale, :current_path_with_query_params, to: :helpers
|
delegate :name_for_locale, :current_path_with_query_params, to: :helpers
|
||||||
|
|
||||||
|
def render?
|
||||||
|
locales.size > 1
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def locales
|
||||||
|
I18n.available_locales
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user