Skip to content

Commit

Permalink
Merge pull request #1866 from zz9pzza/issue_4099
Browse files Browse the repository at this point in the history
Issue 4099 add a preference for the preferred locale for a user.
  • Loading branch information
ariana-paris committed May 11, 2015
2 parents d119af7 + 8e6c0c8 commit b0c5942
Show file tree
Hide file tree
Showing 111 changed files with 137 additions and 1,396 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ services:
- redis-server
- memcached
script:
- bundle exec rake db:create:all --trace
- bundle exec rake db:schema:load --trace
- rm -f structure.sql
- RAILS_ENV=test bundle exec rake db:create:all --trace
- RAILS_ENV=test bundle exec rake db:schema:load --trace
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec $TEST_GROUP
before_script:
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/archive_faqs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def set_locale
if params[:language_id] && session[:language_id] != params[:language_id]
session[:language_id] = params[:language_id]
end
@i18n_locale = session[:language_id] || I18n.default_locale
if current_user.present? && $rollout.active?(:set_locale_preference, current_user)
@i18n_locale = session[:language_id] || Locale.find(current_user.preference.preferred_locale).iso
else
@i18n_locale = session[:language_id] || I18n.default_locale
end
end

def require_language_id
Expand Down
1 change: 1 addition & 0 deletions app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index
@user = User.find_by_login(params[:user_id])
@preference = @user.preference || Preference.create(:user_id => @user.id)
@available_skins = (current_user.skins.site_skins + Skin.approved_skins.site_skins).uniq
@available_locales = Locale.where(email_enabled: true)
end

def update
Expand Down
2 changes: 0 additions & 2 deletions app/models/locale.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Locale < ActiveRecord::Base
belongs_to :language
# has_many :translations
# has_many :translation_notes
validates_presence_of :iso
validates_uniqueness_of :iso
validates_presence_of :name
Expand Down
32 changes: 32 additions & 0 deletions app/views/locales/_locale_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_for(@locale, html: { class: 'post' }) do |f| %>
<p class="required notice">* <%= t('.required_notice', :default => "Required information") %></p>

<fieldset>
<legend><%= t('.locale_legend', :default => "Locale") %></legend>
<h3 class="landmark heading"><%= t('.locale_heading', :default => "Locale") %></h3>
<dl>
<dt class="required"><%= f.label :name, t('.name', :default => "Name") + '*' %></dt>
<dd class="required"><%= f.text_field :name %></dd>

<dt class="required"><%= f.label :iso, t('.iso', :default => "ISO code") + '*' %></dt>
<dd class="required"><%= f.text_field :iso %></dd>

<dt class="required"><%= f.label :language_id, t('.language', :default => "Language") + '*' %></dt>
<dd class="required"><%= f.select(:language_id, @languages.collect { |language| [ language.name, language.id ] }) %></dd>

<dt><%= f.check_box :email_enabled %></dt>
<dd><%= f.label :email_enabled, t('.enable_email', :default => "Use this locale to send email") %></dd>

<dt><%= f.check_box :interface_enabled %></dt>
<dd><%= f.label :interface_enabled, t('.enable_interface', :default => "Use this locale for the interface") %></dd>

</dl>
</fieldset>
<fieldset>
<legend><%= t('.actions_legend', :default => "Actions") %></legend>
<h3 class="landmark heading"><%= t('.actions_heading', :default => "Actions") %></h3>
<p class="submit actions">
<%= f.submit @locale.new_record? ? t('.create_button', :default => "Create Locale") : t('.edit_button', :default => "Update Locale") %>
</p>
</fieldset>
<% end %>
4 changes: 4 additions & 0 deletions app/views/locales/_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ul class="navigation actions" role="navigation">
<li><%= span_if_current t('.link_to_index', :default => 'Locales'), locales_path %></li>
<li><%= span_if_current t('.link_to_new', :default => 'New Locale'), new_locale_path %></li>
</ul>
15 changes: 3 additions & 12 deletions app/views/locales/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<!--Descriptive page name, messages and instructions-->
<h2 class="heading"><%= t('.edit_locale', :default => 'Edit a locale:') %></h2>
<h2 class="heading"><%= t('.edit_locale', :default => 'Edit Locale') %></h2>
<%= error_messages_for :locale %>
<!--/descriptions-->

<!--subnav-->
<%= render 'navigation' %>
<!--/subnav-->

<!--main content-->
<%= form_for(@locale) do |f| %>
<dl>
<dt><%= f.label :language_id, t('.language', :default => "Language:") %></dt>
<dd><%= f.select(:language_id, @languages.collect {|l| [ l.name, l.id ] }) %></dd>
<dt><%= f.label :name, t('.name', :default => "Name:") %></dt>
<dd><%= f.text_field :name %></dd>
<dt><%= f.label :iso, t('.iso', :default => "Iso:") %></dt>
<dd><%= f.text_field :iso %></dd>
</dl>
<p class="submit actions"><%= f.submit t('.forms.submit', :default => "Submit") %></p>
<% end %>
<%= render 'locale_form' %>
<!--/content-->

54 changes: 32 additions & 22 deletions app/views/locales/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
<!--Descriptive page name, messages and instructions-->
<h2 class="heading"><%= t('.supported_locales', :default => 'The archive supports the following locales:') %></h2>
<h2 class="heading"><%= t('.supported_locales', :default => 'Supported Locales') %></h2>
<!--/descriptions-->

<!--main content-->
<% if logged_in_as_admin? || permit?("translation_admin") %>
<p>
<%= link_to t('.link_to_new', :default => 'Add a new one'), new_locale_path %>
</p>
<!--main content-->
<h3 class="landmark heading">List of Locales</h3>
<table summary="Locales">
<caption>Locales</caption>
<% if logged_in_as_admin? || permit?("translation_admin") %>
<%= render 'navigation' %>
<!--main content-->
<table summary="<%= t('.locale_table_summary', :default => 'Lists supported locales, along with details of how they are used and options to modify them.') %>">
<caption><%= t('.locale_table_caption', :default => 'Supported Locales') %></caption>
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Name</th>
<th scope="col">ISO code</th>
<th scope="col">Primary locale</th>
<th scope="col">ISO Code</th>
<th scope="col">Primary Locale</th>
<th scope="col">Use for Email</th>
<th scope="col">Use for Interface</th>
<th scope="col">Created at</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<% for locale in @locales %>
<tr> <td><%= link_to ts('Edit'), {controller: :locales, action: :edit, id: locale.iso} %></td><td><%= locale.name %></td><td><%=locale.iso%></td><td><%=locale.main%></td><td><%=locale.updated_at%></td></tr>
<% end %>
<% for locale in @locales %>
<tr>
<th scope="row"><%= locale.name %></th>
<td><%= locale.iso %></td>
<td><%= locale.main %></td>
<td><%= locale.email_enabled %></td>
<td><%= locale.interface_enabled %></td>
<td><%= locale.updated_at %></td>
<td class="actions">
<%= link_to ts('Edit'), {controller: :locales, action: :edit, id: locale.iso} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<ul>
<% for locale in @locales %>
<li><%= locale.name%></li>
<% end %>
</ul>
<%= link_to t('.suggest_locale', :default => 'Suggest a new one!'), new_feedback_report_path %>
<ul>
<% for locale in @locales %>
<li><%= locale.name %></li>
<% end %>
</ul>
<p class="navigation actions" role="navigation">
<%= link_to t('.suggest_locale', :default => 'Suggest a Locale!'), new_feedback_report_path %>
</p>
<% end %>

<!--/content-->

<!--subnav-->
Expand Down
17 changes: 3 additions & 14 deletions app/views/locales/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<!--Descriptive page name, messages and instructions-->
<h2 class="heading"><%= t('.add_new_locale', :default => 'Add a new locale:') %></h2>
<h2 class="heading"><%= t('.add_new_locale', :default => 'New Locale') %></h2>
<%= error_messages_for :locale %>
<!--/descriptions-->

<!--subnav-->
<%= render 'navigation' %>
<!--/subnav-->

<!--main content-->
<%= form_for(@locale) do |f| %>
<dl>
<dt><%= f.label :language_id, t('.language', :default => "Language:") %></dt>
<dd><%= f.select(:language_id, @languages.collect {|l| [ l.name, l.id ] }) %></dd>

<dt><%= f.label :name, t('.name', :default => "Name:") %></dt>
<dd><%= f.text_field :name %></dd>

<dt><%= f.label :iso, t('.iso', :default => "Iso:") %></dt>
<dd><%= f.text_field :iso %></dd>
</dl>
<p class="submit actions"><%= f.submit t('.forms.submit', :default => "Submit") %></p>
<% end %>
<%= render 'locale_form' %>
<!--/content-->

37 changes: 20 additions & 17 deletions app/views/preferences/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,31 @@
<%= f.check_box :hide_freeform %>
<%= f.label :hide_freeform, ts('Hide additional tags (you can still choose to show them).') %>
</li>

<li>
<%= f.check_box :disable_work_skins %>
<%= f.label :disable_work_skins, ts('Hide work skins (you can still choose to show them).') %> <%= link_to_help 'skins-basics' %>
</li>
</ul>

<fieldset>
<dl>
<dt><%= f.label :skin_id, ts('Your site skin')%> <%= link_to_help 'skins-basics' %>:</dt>
<dd>
<span class="actions"><%= link_to ts('Public Site Skins'), skins_path %></span>
<%= f.select :skin_id, @available_skins.collect{|s| [s.title, s.id]} %>
</dd>

<dt><%= f.label :time_zone, ts('Your time zone: ')%></dt>
<dd><%= f.time_zone_select :time_zone, nil, :default => Time.zone.name %></dd>

<dt><%= f.label :work_title_format, ts('Browser page title format') %> <%= link_to_help 'work_title_format' %>:</dt>
<dd><%= f.text_field :work_title_format %></dd>
</dl>
</fieldset>
</fieldset>
<fieldset>
<dl>
<dt><%= f.label :skin_id, ts('Your site skin') %> <%= link_to_help 'skins-basics' %>:</dt>
<dd>
<span class="actions"><%= link_to ts('Public Site Skins'), skins_path %></span>
<%= f.select :skin_id, @available_skins.collect{|s| [s.title, s.id]} %>
</dd>

<dt><%= f.label :time_zone, ts('Your time zone: ') %></dt>
<dd><%= f.time_zone_select :time_zone, nil, :default => Time.zone.name %></dd>

<% if Rails.env.test? || Rails.env.development? || $rollout.active?(:set_locale_preference, @user) %>
<dt><%= f.label :preferred_locale, ts('Your locale')%> <%= link_to_help 'locale-preferences' %></dt>
<dd><%= f.select :preferred_locale, @available_locales.collect{|locale| [locale.name, locale.id]}, :default => @preference.preferred_locale %></dd>
<% end %>

<dt><%= f.label :work_title_format, ts('Browser page title format') %> <%= link_to_help 'work_title_format' %>:</dt>
<dd><%= f.text_field :work_title_format %></dd>
</dl>
</fieldset>

<fieldset>
Expand Down

This file was deleted.

86 changes: 0 additions & 86 deletions db/migrate/20101015053927_add_sanitizer_version_fields.rb

This file was deleted.

9 changes: 0 additions & 9 deletions db/migrate/20101016131743_add_inherited_to_filter_taggings.rb

This file was deleted.

9 changes: 0 additions & 9 deletions db/migrate/20101022002353_add_tag_wrangling_freeze.rb

This file was deleted.

11 changes: 0 additions & 11 deletions db/migrate/20101022160603_add_restrict_to_fandom_to_tag_set.rb

This file was deleted.

Loading

0 comments on commit b0c5942

Please sign in to comment.