Skip to content

Commit

Permalink
Merge pull request #2805 from refinery/dialect-overflow
Browse files Browse the repository at this point in the history
fix dialect overflow in locale picker
  • Loading branch information
simi committed Dec 11, 2014
2 parents 114fdd1 + e8daaa7 commit 772a698
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions core/app/helpers/refinery/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def current_admin_locale
# TODO: move current_admin_locale to Refinery::I18n
::I18n.locale
end

def locale_country(locale)
locale.to_s.upcase.split('-').last
end

end
end
6 changes: 2 additions & 4 deletions core/app/views/refinery/admin/_locale_picker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
<% locales = Refinery::I18n.locales.clone %>
<% Refinery::I18n.frontend_locales.each do |locale| %>
<% locale_name = locales.delete(locale) %>

<li<%= %Q{ class=selected} if locale.to_s == local_assigns[:current_locale].to_s %>>
<%= link_to refinery.url_for(:switch_locale => locale, :parent_id => params[:parent_id]), id: locale do %>
<div class="locale_icon">
<%= refinery_icon_tag('locale.svg', :size => '24x24') %>
<span class="code"><%= locale.upcase %></span>
<%= refinery_icon_tag('locale.svg', :size => '24x24', :alt => locale.upcase) %>
<span class="code"><%= locale_country(locale) %></span>
</div>
<%= locale_name %>
<% end %>

</li>
<% end %>
</ul>
Expand Down
15 changes: 15 additions & 0 deletions core/spec/helpers/refinery/admin_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec_helper"

module Refinery
describe AdminHelper, :type => :helper do
describe "locale_country" do
it "should return the second part of a dialect" do
expect(helper.locale_country('zh-TW')).to eq("TW")
end

it "should return the locale if it is not a dialect" do
expect(helper.locale_country('en')).to eq("EN")
end
end
end
end
7 changes: 3 additions & 4 deletions pages/app/views/refinery/admin/pages/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
<% page.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
<% if translation.title.present? %>
<%= link_to refinery.admin_edit_page_path(page.nested_url, :switch_locale => translation.locale),
:class => 'locale' do %>
:class => 'locale', :title => translation.locale.upcase do %>

<div class="locale_icon <%= translation.locale %>">
<%= refinery_icon_tag('locale-blue.svg', :size => '24x24') %>
<span class="code"><%= translation.locale.upcase %></span>
<%= refinery_icon_tag('locale-blue.svg', :size => '24x24', :alt => translation.locale.upcase) %>
<span class="code"><%= locale_country(translation.locale) %></span>
</div>

<% end %>
<% end %>
<% end %>
Expand Down

0 comments on commit 772a698

Please sign in to comment.