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

Issue 4099 add a preference for the preferred locale for a user. #1866

Merged
merged 40 commits into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c6668cc
Add fields for locales to allow emails to be sent and the user interf…
zz9pzza Oct 3, 2014
756b9c7
Make test not go bang
zz9pzza Oct 3, 2014
89d8037
The ability to change the prefered locale is now controlled by roll out
zz9pzza Oct 4, 2014
da94fdf
If the user has a locale preference then honor it in the FAQ's
zz9pzza Oct 4, 2014
34fe64d
remove debugging code
zz9pzza Oct 4, 2014
4367bd5
Make the preference visible in the testing enviroment
zz9pzza Oct 5, 2014
8be49cf
Update text used in label
zz9pzza Oct 5, 2014
fdecc60
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza Nov 6, 2014
29347a2
Merge branch 'issue_4099' of git://github.com/zz9pzza/otwarchive into…
sarken Nov 16, 2014
1c09f7e
4099 Locales front end suggestions
sarken Nov 17, 2014
753b43f
Following Sarken's comments
zz9pzza Nov 18, 2014
ad92811
Merge branch 'issue_4099' of https://github.com/sarken/otwarchive int…
zz9pzza Nov 18, 2014
fb64249
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza Nov 18, 2014
b68ac08
I think that is what saren wished
zz9pzza Nov 21, 2014
9277259
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza Nov 21, 2014
26bbffd
fix merge conflict
zz9pzza Nov 21, 2014
f7ebf13
opening in <li> removed
zz9pzza Nov 21, 2014
d1453a3
fix from Sarken
zz9pzza Nov 21, 2014
6ffc135
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza Jan 11, 2015
d04cac4
Listen to the hound
zz9pzza Jan 11, 2015
c21c43b
Fix conflict
zz9pzza Apr 26, 2015
3e6d0f0
Follow the hound
zz9pzza Apr 26, 2015
6e8c6db
language not l
zz9pzza Apr 30, 2015
2c6788f
Fix spaces
zz9pzza Apr 30, 2015
9c26565
s/L/l/;
zz9pzza Apr 30, 2015
4056207
locale not l
zz9pzza Apr 30, 2015
07080f2
Change the text
zz9pzza Apr 30, 2015
81d76a7
Clear up tests
zz9pzza Apr 30, 2015
066f36d
preferred not prefered
zz9pzza Apr 30, 2015
ccfd466
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza May 3, 2015
f6cecc3
One last typo
zz9pzza May 6, 2015
e5754af
Ensure the database is correct
zz9pzza May 7, 2015
9e4509c
Merge branch 'master' of https://github.com/otwcode/otwarchive into i…
zz9pzza May 7, 2015
d45b418
Update the sructure
zz9pzza May 7, 2015
cbc201e
Put the db files back
zz9pzza May 8, 2015
f72f979
Get travis to delete the current db state to make the files not used …
zz9pzza May 8, 2015
a38edb4
Try this travis
zz9pzza May 8, 2015
4f9b118
Try this travis
zz9pzza May 8, 2015
826804a
We need to do the migrations
zz9pzza May 8, 2015
8e6c0c8
Roll up the migrations properly
zz9pzza May 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} %>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a remaining ts() in a file that seems to otherwise use t()

</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
5 changes: 5 additions & 0 deletions db/migrate/20141003204623_add_interface_enabled_to_locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInterfaceEnabledToLocale < ActiveRecord::Migration
def change
add_column :locales, :interface_enabled, :boolean, default: false, null: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20141003205439_add_email_enabled_to_locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmailEnabledToLocale < ActiveRecord::Migration
def change
add_column :locales, :email_enabled, :boolean, default: false, null: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20141004123421_add_locale_to_preferences.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLocaleToPreferences < ActiveRecord::Migration
def change
add_column :preferences, :preferred_locale, :integer, default: 1, null: false
end
end
17 changes: 10 additions & 7 deletions features/other_a/admin_tasks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,27 @@ Feature: Admin tasks
When I edit known issues
Then I should see "Known issue was successfully updated"

Scenario: Add a locale
Scenario: Add and edit a locale
Given the following language exists
| name | short |
| Dutch | nl |
And I am logged in as an admin
When I go to the locales page
Then I should see "English (US)"
And I follow "Add a new one"
When I follow "New Locale"
And I select "Dutch" from "Language"
And I fill in "locale_name" with "Dutch - Netherlands"
And I fill in "locale_iso" with "nl-nl"
And I press "Submit"
Then I should see "Dutch"
And I follow "Edit"
And I check "Use this locale to send email"
And I press "Create Locale"
Then I should see "Dutch"
When I follow "Edit"
And I select "English" from "Language"
And I fill in "locale_name" with "English (GB)"
And I fill in "locale_iso" with "en-gb"
And I press "Submit"
Then I should see "Your locale was successfully updated."
And I check "Use this locale to send email"
And I check "Use this locale for the interface"
And I press "Update Locale"
Then I should see "Your locale was successfully updated."


8 changes: 8 additions & 0 deletions public/help/locale-preferences.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h4>Locale Preferences</h4>

<dl id="help">
<dt>Set preferred locale</dt>
<dd>
This preference allows you to select your prefered language for email messages that the Archive sends to you. The templates for these messages are currently being updated and translated by our volunteers. This is a work in progress; not all messages will be available in languages other than English at this time. If the template for that email has not yet been translated to your language, it will be sent in English.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be "preferred." Also, a couple little phrasing tweaks: "This option allows you to select your preferred language for email messages the Archive sends you." and "If the template for an email has not yet been translated"

Copy link
Collaborator

Choose a reason for hiding this comment

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

One last "prefered" snuck in here.

</dd>
</dl>