From bb8433f4fe7911032a076e65004681f651462726 Mon Sep 17 00:00:00 2001 From: sentientwaffle Date: Tue, 30 Nov 2010 18:06:49 -0800 Subject: [PATCH 1/8] Added features for posting to all or single aspects --- features/posts.feature | 32 ++++++++++++++++++++++++ features/step_definitions/posts_steps.rb | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 features/posts.feature create mode 100644 features/step_definitions/posts_steps.rb diff --git a/features/posts.feature b/features/posts.feature new file mode 100644 index 000000000..2cb6e9220 --- /dev/null +++ b/features/posts.feature @@ -0,0 +1,32 @@ +Feature: posting + In order to enlighten humanity for the good of society + As a rock star + I want to tell the world I am eating a yogurt + + Scenario: post to all aspects + Given I am signed in + And I have an aspect called "Family" + And I am on the home page + When I click share across aspects + And I fill in "status_message_message" with "I am eating a yogurt" + And I press "Share" + + And I follow "Family" + Then I should see "I am eating a yogurt" + + Scenario Outline: post to one aspect + Given I am signed in + And I have an aspect called "PostTo" + And I have an aspect called "DidntPostTo" + And I am on the home page + When I follow "PostTo" + And I fill in "status_message_message" with "I am eating a yogurt" + And I press "Share" + + And I follow "" + Then I should "I am eating a yogurt" + + Examples: + | aspect | see | + | PostTo | see | + | DidntPostTo | not see | diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb new file mode 100644 index 000000000..78e932678 --- /dev/null +++ b/features/step_definitions/posts_steps.rb @@ -0,0 +1,3 @@ +When /^I click share across aspects$/ do + find("#content_creation_button").click +end From ecd1d2ecd64683b3a3f6bfc915521adc1e1bc193 Mon Sep 17 00:00:00 2001 From: Josh Lubaway Date: Tue, 30 Nov 2010 21:18:14 -0800 Subject: [PATCH 2/8] Bug #624 Can't unset birthday This change allows users to "unset" their birthday. Previously the logic checked to see if all values for birthday were present (year, month, day). If all values were present the update would proceed. Now, there is another condition. If all values are empty, then also proceed with the update. Thus, allowing a user to "unset" their birthday. --- app/controllers/people_controller.rb | 7 ------ app/models/profile.rb | 12 +++++++++- app/views/people/edit.html.haml | 2 +- spec/models/profile_spec.rb | 33 ++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f7e35c779..0e28c3fb8 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -61,13 +61,6 @@ class PeopleController < ApplicationController end def update - # convert date selector into proper timestamp - - if birthday = params[:date] - unless [:month, :day, :year].any?{|x| birthday[x].blank?} - params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}") - end - end # upload and set new profile photo params[:person][:profile] ||= {} diff --git a/app/models/profile.rb b/app/models/profile.rb index 7794c287e..c87c97f46 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -36,7 +36,8 @@ class Profile before_save :strip_names - attr_accessible :first_name, :last_name, :image_url, :image_url_medium, :image_url_small, :birthday, :gender, :bio, :searchable + attr_accessible :first_name, :last_name, :image_url, :image_url_medium, + :image_url_small, :birthday, :gender, :bio, :searchable, :date def person @@ -86,6 +87,15 @@ class Profile end end + def date= params + if ['year', 'month', 'day'].all? { |key| params[key].present? } + date = Date.new(params['year'].to_i, params['month'].to_i, params['day'].to_i) + self.birthday = date + elsif ['year', 'month', 'day'].all? { |key| params[key] == '' } + self.birthday = nil + end + end + protected def strip_names diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index 61c2f4cdc..ce9a733e0 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -34,7 +34,7 @@ %h4 = t('.your_birthday') %br - = select_date @person.profile.birthday, :prompt => true, + = select_date @person.profile.birthday, :prompt => true, :prefix => 'person[profile][date]', :default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1904 %h4 diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index e74a08c78..a7b9abe86 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -73,4 +73,37 @@ describe Profile do xml.should_not include person.id.to_s end end + + describe 'date=' do + let(:profile) { make_user.profile } + + it 'accepts form data' do + profile.birthday.should == nil + profile.date = { 'year' => '2000', 'month' => '01', 'day' => '01' } + profile.birthday.year.should == 2000 + profile.birthday.month.should == 1 + profile.birthday.day.should == 1 + end + + it 'unsets the birthday' do + profile.birthday = Date.new(2000, 1, 1) + profile.date = { 'year' => '', 'month' => '', 'day' => ''} + profile.birthday.should == nil + end + + it 'does not change with one or more blank values' do + profile.birthday = Date.new(2000, 1, 1) + profile.date = { 'year' => '2001', 'month' => '', 'day' => ''} + profile.birthday.year.should == 2000 + profile.birthday.month.should == 1 + profile.birthday.day.should == 1 + end + + it 'accepts blank initial vallues' do + profile.birthday.should == nil + profile.date = { 'year' => '2001', 'month' => '', 'day' => ''} + profile.birthday.should == nil + end + end + end From 279b08ae4a8f6d22a10449c7b8d93289d6fac190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 05:03:35 +0100 Subject: [PATCH 3/8] Added inflection of nouns by the grammatical gender for some languages. - New module I18n::Backend::Genderize keeps configuration and adds :gender option to translate(). - Module methods in Genderize allow fast checking if language needs gender and guessing gender. - jQuery in views/users/edit.html.haml shows and hides grammatical gender select list when needed. - Span and select list in views/users/edit.html.haml allows to choose grammatical gender. - Key :grammatical_gender in User model keeps grammatical gender information. - Added some methods to language_helper.rb. - UsersController is aware of grammatical gender and is able to guess it when "getting started". --- app/controllers/users_controller.rb | 12 +++- app/helpers/language_helper.rb | 28 ++++++++- app/models/user.rb | 4 +- app/views/users/edit.html.haml | 33 ++++++++--- config/initializers/locale.rb | 89 +++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e3129760d..6d36e3ac4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,6 +28,7 @@ class UsersController < ApplicationController params[:user].delete(:password) if params[:user][:password].blank? params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? params[:user].delete(:language) if params[:user][:language].blank? + params[:user].delete(:grammatical_gender) if params[:user][:grammatical_gender].blank? if params[:user][:password] && params[:user][:password_confirmation] if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation]) @@ -37,7 +38,15 @@ class UsersController < ApplicationController end elsif params[:user][:language] if @user.update_attributes(:language => params[:user][:language]) - flash[:notice] = I18n.t 'users.update.language_changed' + if params[:user][:grammatical_gender] + if @user.update_attributes(:grammatical_gender => params[:user][:grammatical_gender]) + flash[:notice] = I18n.t 'users.update.language_changed' + else + flash[:error] = I18n.t 'users.update.language_not_changed' + end + else + flash[:notice] = I18n.t 'users.update.language_changed' + end else flash[:error] = I18n.t 'users.update.language_not_changed' end @@ -80,6 +89,7 @@ class UsersController < ApplicationController @step ||= 1 if @step == 4 + @user.grammatical_gender = I18n::Backend::Genderize.guess(@profile.gender) @user.getting_started = false @user.save end diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index 20a0db902..7bd5b3975 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -6,4 +6,30 @@ module LanguageHelper end options.sort_by { |o| o[0] } end -end \ No newline at end of file + + def options_for_gender_select(user) + grammatical_gender = user.grammatical_gender + genders_list = I18n::Backend::Genderize.known_genders.map do |gender| + [t("#{gender}"), gender] + end + if grammatical_gender.blank? + grammatical_gender = I18n::Backend::Genderize.guess(user.profile.gender) + end + options_for_select(genders_list, grammatical_gender.to_s) + end + + def gender_select_disabled(user) + not I18n::Backend::Genderize.supports?(user.language) + end + + def grammatical_gender_languages + @glang_cache ||= array_or_string_for_javascript(I18n::Backend::Genderize::SupportedLanguages) + end + + def options_for_grammatical_gender_block(user) + enabled = I18n::Backend::Genderize.supports? user.language + {:style => 'display: ' + (enabled ? 'inline' : 'none') + ';' + + ' margin-left: 1em; margin-right: 0.5em;' + } + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 039f7225c..8974e0be0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -29,6 +29,7 @@ class User key :getting_started, Boolean, :default => true key :language, String + key :grammatical_gender, String before_validation :strip_and_downcase_username, :on => :create before_validation :set_current_language, :on => :create @@ -38,6 +39,7 @@ class User validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/ validates_length_of :username, :maximum => 32 validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES + validates_inclusion_of :grammatical_gender, :in => I18n::Backend::Genderize::known_genders + [nil] validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?} validates_associated :person @@ -61,7 +63,7 @@ class User person.save if person end - attr_accessible :getting_started, :password, :password_confirmation, :language, + attr_accessible :getting_started, :password, :password_confirmation, :language, :grammatical_gender def strip_and_downcase_username if username.present? diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 9ecf06be0..d631c6df8 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -3,13 +3,29 @@ -# the COPYRIGHT file. :javascript - $("#settings_nav li > a").live("click", function() { - var target = "#"+$(this).attr('class'); - if( !$(target).is(":visible") ) { - $(".settings_pane").fadeOut(200, function() { - $(target).delay(200).fadeIn(200); - }); - } + var genderized_languages = #{grammatical_gender_languages} + + $(document).ready(function(){ + + $("#settings_nav li > a").live("click", function() { + var target = "#"+$(this).attr('class'); + if( !$(target).is(":visible") ) { + $(".settings_pane").fadeOut(200, function() { + $(target).delay(200).fadeIn(200); + }); + } + }); + + $("#user_language").change(function () { + var gselected = $("#user_language option:selected").val(); + if ( $.inArray(gselected, genderized_languages) < 0 ) { + $("#grammatical_gender_block").hide(800); + $("#user_grammatical_gender").attr("disabled", "disabled"); + } else { + $("#user_grammatical_gender").removeAttr("disabled"); + $("#grammatical_gender_block").show(800); + } + }); }); #section_header @@ -67,6 +83,9 @@ %p = f.select :language, available_language_options + %span#grammatical_gender_block{options_for_grammatical_gender_block(current_user)} + = " " + t('.address_me_as') + = select_tag 'user[grammatical_gender]', options_for_gender_select(current_user), :disabled => gender_select_disabled(current_user) = f.submit t('.change_language') %br diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 86ae3c07b..93a99e5d1 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,3 +1,5 @@ +# Encoding: utf-8 +# # Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. @@ -14,3 +16,90 @@ AVAILABLE_LANGUAGE_CODES.each do |c| I18n.fallbacks[c.to_sym] = [c.to_sym, DEFAULT_LANGUAGE.to_sym, :en] end end + +# Languages that require to specify biological gender (sex) +# in order to inflect properly when using nouns with second +# person in past tense. +module I18n + module Backend + module Genderize + + # Languages that need and support inflection. + SupportedLanguages = [ :ar, :lt, :pl, :ru, :sr, :uk ] + + # Genders table helps to initialize grammatical gender + # by looking at sociological gender entered by user. + Genders = { + :feminine => %w( f fem female feminine k kobieta pani woman + laska girl dziewczyna dziewucha chick lady mrs mrs. + miss missus missis mistress ms panna panienka ﺳﻴﺪۃ + dziewczynka żona zena sayyidah Пані Госпожа Г-жа ), + + :masculine => %w( m mal male masculine man dude guy gentleman + mr mister pan chłopak boy chłopiec koleś gość + lasek gostek monsieur hr herr Пан mr. سيد سادة + mężczyzna mąż chłopaczek facet sayyid Господин Г-н maleman ), + } + + Genders.default = :neuter + + end + end +end + +# Grammatical gender aware translate. +module I18n + module Backend + module Genderize + + def translate(locale, key, options = {}) + g = options.delete(:gender) + if not (g.nil? || key.is_a?(Enumerable)) + g = g.to_sym + subkey = Genders[g.to_sym] + key = "#{key}.#{subkey}".to_sym + end + super(locale, key, options) + end + + # Initialize fast mapping table using data from Genders. + def included(m) + return if instance_variable_defined?(:@genders_guesser) + @genders_guesser = {} + @known_genders = [] + Genders.each_pair do |gname,gtable| + @known_genders.push gname + gtable.each do |word| + @genders_guesser[word.to_sym] = gname + end + end + @genders_guesser.default = Genders.default + @known_genders.push Genders.default + @known_genders.map! { |g| g.to_s } + nil + end + module_function :included + + # Does language needs and supports inflection by gender? + def supports?(l=nil) + SupportedLanguages.include? l.nil? ? I18n.locale.to_sym : l.to_sym + end + module_function :supports? + + # Deduce grammatical gender using given gender and mapping. + def guess(gender_description="") + @genders_guesser[gender_description.downcase.to_sym] + end + module_function :guess + + # Array of strings with known grammatical genders. + def known_genders + @known_genders + end + module_function :known_genders + + end + end +end + +I18n::Backend::Simple.send(:include, I18n::Backend::Genderize) From 65c796572d79fba3f26faab6bf0c44e0014b63fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 05:09:06 +0100 Subject: [PATCH 4/8] Added translation scaffold for inflection of nouns by grammatical gender in some languages. --- app/helpers/language_helper.rb | 2 +- config/locales/diaspora/en.yml | 61 +++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index 7bd5b3975..17066ded9 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -10,7 +10,7 @@ module LanguageHelper def options_for_gender_select(user) grammatical_gender = user.grammatical_gender genders_list = I18n::Backend::Genderize.known_genders.map do |gender| - [t("#{gender}"), gender] + [t(".#{gender}"), gender] end if grammatical_gender.blank? grammatical_gender = I18n::Backend::Genderize.guess(user.profile.gender) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 624779db1..c63ad0986 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -21,7 +21,10 @@ en: email: "Email" password: "Password" password_confirmation: "Password confirmation" - are_you_sure: "Are you sure?" + are_you_sure: + masculine: "Are you sure?" + feminine: "Are you sure?" + neuter: "Are you sure?" fill_me_out: "Fill me out" back: "Back" the_world: "the world" @@ -103,7 +106,10 @@ en: your_diaspora_username_is: "Your Diaspora username is: %{diaspora_handle}" create_request: "Find by Diaspora handle" diaspora_handle: "diaspora@handle.org" - know_email: "Know their email address? You should invite them" + know_email: + masculine: "Know their email address? You should invite them" + feminine: "Know their email address? You should invite them" + neuter: "Know their email address? You should invite them" invitations: invite_someone: "Invite someone" invitations_left: "(%{count} left)" @@ -183,6 +189,10 @@ en: download_photos: "download my photos" your_handle: "Your diaspora handle" your_email: "Your email" + address_me_as: "Address me as" + masculine: "a man" + feminine: "a woman" + neuter: "a neuter" destroy: "Account successfully closed." getting_started: welcome: "Welcome to Diaspora!" @@ -241,9 +251,18 @@ en: back_to_list: "Back to List" post_it: "post it!" create: - runtime_error: "Photo upload failed. Are you sure that your seatbelt is fastened?" - integrity_error: "Photo upload failed. Are you sure that was an image?" - type_error: "Photo upload failed. Are you sure an image was added?" + runtime_error: + masculine: "Photo upload failed. Are you sure that your seatbelt is fastened?" + feminine: "Photo upload failed. Are you sure that your seatbelt is fastened?" + neuter: "Photo upload failed. Are you sure that your seatbelt is fastened?" + integrity_error: + masculine: "Photo upload failed. Are you sure that was an image?" + feminine: "Photo upload failed. Are you sure that was an image?" + neuter: "Photo upload failed. Are you sure that was an image?" + type_error: + masculine: "Photo upload failed. Are you sure an image was added?" + feminine: "Photo upload failed. Are you sure an image was added?" + neuter: "Photo upload failed. Are you sure an image was added?" update: notice: "Photo successfully updated." error: "Failed to edit photo." @@ -272,11 +291,20 @@ en: sent: "Invitations have been sent to: " rejected: "The following email addresses had problems: " no_more: "You have no more invitations." - already_sent: "You already invited this person." - already_contacts: "You are already connected with this person" + already_sent: + masculine: "You already invited this person." + feminine: "You already invited this person." + neuter: "You already invited this person." + already_contacts: + masculine: "You are already connected with this person." + feminine: "You are already connected with this person." + neuter: "You are already connected with this person." new: invite_someone_to_join: "Invite someone to join Diaspora!" - if_they_accept_info: "if they accept, they will be added to the aspect you invited them." + if_they_accept_info: + masculine: "if they accept, they will be added to the aspect you invited them." + feminine: "if they accept, they will be added to the aspect you invited them." + neuter: "if they accept, they will be added to the aspect you invited them." comma_seperated_plz: "You can enter multiple email addresses separated by commas." to: "To" message: "Message:" @@ -307,10 +335,16 @@ en: incoming_request: "You have an incoming request from this person." return_to_aspects: "Return to your aspects page" to_accept_or_ignore: "to accept or ignore it." - request_people: "If you'd like, you can request to place him/her in one of your aspects." - already_requested: "You have already sent a request to %{name}." + request_people: "If you'd like, you can request to place him in one of your aspects." + already_requested: + masculine: "You have already sent a request to %{name}." + feminine: "You have already sent a request to %{name}." + neuter: "You have already sent a request to %{name}." does_not_exist: "Person does not exist!" - not_connected: "You are not connected with this person" + not_connected: + masculine: "You are not connected with this person" + feminine: "You are not connected with this person" + neuter: "You are not connected with this person" edit: info_available_to: "This info will be available to whomever you connect with on Diaspora." your_profile: "Your profile" @@ -350,7 +384,10 @@ en: ignore: "Ignored contact request." create: sending: "Sending" - sent: "You've asked to share with %{name}. They should see it next time they log in to Diaspora." + sent: + masculine: "You've asked to share with %{name}. They should see it next time they log in to Diaspora." + feminine: "You've asked to share with %{name}. They should see it next time they log in to Diaspora." + neuter: "You've asked to share with %{name}. They should see it next time they log in to Diaspora." new_request_to_person: sent: "sent!" services: From eb2d186a12db3a1ad6e974eb7abb43f5b4c42c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 06:26:06 +0100 Subject: [PATCH 5/8] Genderize#translate fixed and enhanced (now it accepts User objects to fix the gender). --- config/initializers/locale.rb | 8 ++++---- config/locales/diaspora/en.yml | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 93a99e5d1..61723ff8f 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -53,10 +53,10 @@ module I18n module Genderize def translate(locale, key, options = {}) - g = options.delete(:gender) - if not (g.nil? || key.is_a?(Enumerable)) - g = g.to_sym - subkey = Genders[g.to_sym] + subkey = options.delete(:gender) + if not (subkey.nil? || key.is_a?(Enumerable)) + subkey = subkey.grammatical_gender if subkey.respond_to?(:grammatical_gender) + subkey = Genders.default unless Genders.has_key?(subkey.to_sym) key = "#{key}.#{subkey}".to_sym end super(locale, key, options) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index c63ad0986..f95d0abbe 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -165,7 +165,10 @@ en: helper: remove: "remove" aspect_not_empty: "Aspect not empty" - are_you_sure: "Are you sure you want to delete this aspect?" + are_you_sure: + masculine: "Are you sure you want to delete this aspect?" + feminine: "Are you sure you want to delete this aspect?" + neuter: "Are you sure you want to delete this aspect?" remove_from_aspect: success: "Successfully removed person from aspect" failure: "Failed to remove person from aspect" From 017251fef952d68071204244a39861b995b4b256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 06:28:17 +0100 Subject: [PATCH 6/8] Added genderized variants of t() to views, controllers and helpers. --- app/controllers/invitations_controller.rb | 4 ++-- app/controllers/photos_controller.rb | 6 +++--- app/controllers/requests_controller.rb | 2 +- app/helpers/aspects_helper.rb | 2 +- app/helpers/language_helper.rb | 12 ++++++------ app/helpers/people_helper.rb | 2 +- app/views/invitations/_new.haml | 2 +- app/views/people/show.html.haml | 4 ++-- app/views/photos/show.html.haml | 2 +- app/views/registrations/edit.html.haml | 2 +- app/views/shared/_add_contact.html.haml | 2 +- app/views/shared/_stream_element.html.haml | 2 +- app/views/shared/_stream_element.mobile.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- app/views/users/edit.html.haml | 6 +++--- app/views/users/getting_started.html.haml | 2 +- 16 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index e4560c0a3..2259204b5 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -30,9 +30,9 @@ class InvitationsController < Devise::InvitationsController if e.message == "You have no invites" flash[:error] = I18n.t 'invitations.create.no_more' elsif e.message == "You already invited this person" - flash[:error] = I18n.t 'invitations.create.already_sent' + flash[:error] = I18n.t('invitations.create.already_sent', :gender => current_user) elsif e.message == "You are already connected to this person" - flash[:error] = I18n.t 'invitations.create.already_contacts' + flash[:error] = I18n.t('invitations.create.already_contacts', :gender => current_user) else raise e end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 5c29913cb..9388690d1 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -55,15 +55,15 @@ class PhotosController < ApplicationController end rescue TypeError - message = I18n.t 'photos.create.type_error' + message = I18n.t('photos.create.type_error', :gender => current_user) respond_with :location => photos_path, :error => message rescue CarrierWave::IntegrityError - message = I18n.t 'photos.create.integrity_error' + message = I18n.t('photos.create.integrity_error', :gender => current_user) respond_with :location => photos_path, :error => message rescue RuntimeError => e - message = I18n.t 'photos.create.runtime_error' + message = I18n.t('photos.create.runtime_error', :gender => current_user) respond_with :location => photos_path, :error => message raise e end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index a3c9ca48c..beb0212b2 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -45,7 +45,7 @@ class RequestsController < ApplicationController :into => aspect) if @request.save current_user.dispatch_request(@request) - flash.now[:notice] = I18n.t('requests.create.sent') + flash.now[:notice] = I18n.t('requests.create.sent', :gender => current_user) redirect_to :back else flash.now[:error] = @request.errors.full_messages.join(', ') diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index ad3b9ab48..c79f0ef84 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -9,7 +9,7 @@ module AspectsHelper def remove_link( aspect ) if aspect.contacts.size == 0 - link_to I18n.t('aspects.helper.remove'), aspect, :method => :delete, :confirm => I18n.t('aspects.helper.are_you_sure') + link_to I18n.t('aspects.helper.remove'), aspect, :method => :delete, :confirm => I18n.t('aspects.helper.are_you_sure', :gender => current_user) else "#{I18n.t('aspects.helper.remove')}" end diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index 17066ded9..f4889266a 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -7,8 +7,8 @@ module LanguageHelper options.sort_by { |o| o[0] } end - def options_for_gender_select(user) - grammatical_gender = user.grammatical_gender + def options_for_gender_select + grammatical_gender = current_user.grammatical_gender genders_list = I18n::Backend::Genderize.known_genders.map do |gender| [t(".#{gender}"), gender] end @@ -18,16 +18,16 @@ module LanguageHelper options_for_select(genders_list, grammatical_gender.to_s) end - def gender_select_disabled(user) - not I18n::Backend::Genderize.supports?(user.language) + def gender_select_disabled + not I18n::Backend::Genderize.supports?(current_user.language) end def grammatical_gender_languages @glang_cache ||= array_or_string_for_javascript(I18n::Backend::Genderize::SupportedLanguages) end - def options_for_grammatical_gender_block(user) - enabled = I18n::Backend::Genderize.supports? user.language + def options_for_grammatical_gender_block + enabled = I18n::Backend::Genderize.supports? current_user.language {:style => 'display: ' + (enabled ? 'inline' : 'none') + ';' + ' margin-left: 1em; margin-right: 0.5em;' } diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index c3fbf7b1f..35cdca888 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -22,7 +22,7 @@ module PeopleHelper def action_link(person, is_contact) if is_contact - link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete + link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure', :gender => current_user), :method => :delete elsif person == current_user.person link_to t('people.profile_sidebar.edit_my_profile'), edit_person_path(person) end diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index cc4c1ca49..b7659ed06 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -3,7 +3,7 @@ %h4 = t('.invite_someone_to_join') %i - = t('.if_they_accept_info') + = t('.if_they_accept_info', :gender => current_user) %br = t('.comma_seperated_plz') = form_for User.new, :url => invitation_path(User) do |invite| diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 7615a63ac..153ebb220 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -47,7 +47,7 @@ - else .floating %h3 - = t('.not_connected', :name => @person.name) + = t('.not_connected', :name => @person.real_name, :gender => current_user) - unless pending_request_for(@person) %h3 @@ -59,5 +59,5 @@ - else %h3 .description - = t('.already_requested', :name => @person.name) + = t('.already_requested', :name => @person.real_name, :gender => current_user) diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 9df98828b..45bd8fb55 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -33,7 +33,7 @@ = p.text_field :caption, :value => @photo.caption = p.submit t('.update_photo') %p - = button_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete + = button_to t('.delete_photo'), @photo, :confirm => t('are_you_sure', :gender => current_user), :method => :delete .span-9.last - if @photo.status_message_id diff --git a/app/views/registrations/edit.html.haml b/app/views/registrations/edit.html.haml index a71cd97c7..882a30b8f 100644 --- a/app/views/registrations/edit.html.haml +++ b/app/views/registrations/edit.html.haml @@ -24,5 +24,5 @@ = f.submit t('.update') %h3 t('.cancel_my_account') %p - = t('.unhappy') #{link_to t('.cancel_my_account'), registration_path(resource_name), :confirm => t('are_you_sure'), :method => :delete}. + = t('.unhappy') #{link_to t('.cancel_my_account'), registration_path(resource_name), :confirm => t('are_you_sure', :gender=>:neuter), :method => :delete}. = link_to t('back'), :back diff --git a/app/views/shared/_add_contact.html.haml b/app/views/shared/_add_contact.html.haml index f09014bc6..34e323d1e 100644 --- a/app/views/shared/_add_contact.html.haml +++ b/app/views/shared/_add_contact.html.haml @@ -21,7 +21,7 @@ %ul#request_result{:aspect_id => aspect_id} %li.error.hidden #message - = link_to t('.know_email'), "#invite_user_pane", :class => "invite_user_button" + = link_to t('.know_email', :gender => current_user), "#invite_user_pane", :class => "invite_user_button" %br .yo{ :style => "display:none;"} #invite_user_pane diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index e2280eb93..e21f7fb4d 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -23,7 +23,7 @@ - reshare_aspects = aspects_without_post(aspects, post) - unless reshare_aspects.empty? = render 'shared/reshare', :aspects => reshare_aspects, :post => post - = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" + = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure', :gender => current_user), :method => :delete, :remote => true, :class => "delete" = render 'status_messages/status_message', :post => post, :photos => photos diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml index 08b6e6a40..6f509cd5a 100644 --- a/app/views/shared/_stream_element.mobile.haml +++ b/app/views/shared/_stream_element.mobile.haml @@ -23,6 +23,6 @@ - if current_user.owns?(post) .right - = link_to t('delete'), photo_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" + = link_to t('delete'), photo_path(post), :confirm => t('are_you_sure', :gender => current_user), :method => :delete, :remote => true, :class => "delete" /= render "comments/comments", :post => post diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 58a08214d..2c688be31 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -16,7 +16,7 @@ .time = how_long_ago(@status_message) - if current_user.owns? @status_message - = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure'), :method => :delete + = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure', :gender => current_user), :method => :delete .span-9.last %h4{:style=>"margin-bottom:5px;"}= t('_comments') diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index d631c6df8..c71290674 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -83,9 +83,9 @@ %p = f.select :language, available_language_options - %span#grammatical_gender_block{options_for_grammatical_gender_block(current_user)} + %span#grammatical_gender_block{options_for_grammatical_gender_block} = " " + t('.address_me_as') - = select_tag 'user[grammatical_gender]', options_for_gender_select(current_user), :disabled => gender_select_disabled(current_user) + = select_tag 'user[grammatical_gender]', options_for_gender_select, :disabled => gender_select_disabled = f.submit t('.change_language') %br @@ -102,5 +102,5 @@ %h3 = t('.close_account') = link_to t('.close_account'), current_user, - :confirm => t('are_you_sure'), :method => :delete, + :confirm => t('are_you_sure', :gender => current_user), :method => :delete, :class => "button" diff --git a/app/views/users/getting_started.html.haml b/app/views/users/getting_started.html.haml index 503d437bf..3540e6dbf 100644 --- a/app/views/users/getting_started.html.haml +++ b/app/views/users/getting_started.html.haml @@ -12,7 +12,7 @@ $(".aspects li").find(".delete").live("click", function(){ var aspectElement = $(this).parent("li"); - if (confirm("#{t('are_you_sure')}")){ + if (confirm("#{t('are_you_sure', :gender => current_user)}")){ aspectElement.fadeOut(300, function(){aspectElement.remove();}); } }); From 1295417224bb06deeaba2b983484f30440862232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 17:24:56 +0100 Subject: [PATCH 7/8] Added some specs for grammatical_gender (User model and Users controller). --- spec/controllers/users_controller_spec.rb | 26 ++++++++++++++++++++++- spec/models/user_spec.rb | 16 ++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 13699c59b..b5e506e20 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -11,7 +11,8 @@ describe UsersController do let!(:old_password) { user.encrypted_password } let!(:old_language) { user.language } - + let!(:old_gender) { user.grammatical_gender } + before do sign_in :user, user end @@ -59,5 +60,28 @@ describe UsersController do user.language.should_not == old_language end end + + describe 'grammatical_gender' do + it 'should allow user to change his grammatical gender for some languages' do + user.language = 'pl' + user.grammatical_gender = 'masculine' + user.save + old_gender = user.grammatical_gender + put("update", :id => user.id, "user" => {"language" => "ru", "grammatical_gender" => "neuter"}) + user.reload + user.grammatical_gender.should_not == old_gender + old_gender = user.grammatical_gender + put("update", :id => user.id, "user" => {"language" => "ru", "grammatical_gender" => ""}) + user.reload + user.grammatical_gender.should == old_gender + put("update", :id => user.id, "user" => {"language" => "ru", "grammatical_gender" => "feminine"}) + user.reload + old_gender = user.grammatical_gender + put("update", :id => user.id, "user" => {"language" => "en"}) + user.reload + user.grammatical_gender.should == old_gender + end + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 464787133..a0758709c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -167,6 +167,22 @@ describe User do end end + describe "of grammatical gender" do + after do + I18n.locale = :en + end + it "requires availability" do + user = Factory.build(:user, :grammatical_gender => 'some invalid string') + user.should_not be_valid + end + + it "should save with empty grammatical gender if blank" do + I18n.locale = :pl + user = Factory(:user, :grammatical_gender => nil) + user.grammatical_gender.should == nil + end + end + end describe ".build" do From 76edca136674d77c73809c7130c03ff44939c4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilk?= Date: Wed, 1 Dec 2010 18:23:21 +0100 Subject: [PATCH 8/8] View fixed after rebase according to latest changes. --- app/views/people/show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 153ebb220..12cce8cfc 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -47,7 +47,7 @@ - else .floating %h3 - = t('.not_connected', :name => @person.real_name, :gender => current_user) + = t('.not_connected', :name => @person.name, :gender => current_user) - unless pending_request_for(@person) %h3 @@ -59,5 +59,5 @@ - else %h3 .description - = t('.already_requested', :name => @person.real_name, :gender => current_user) + = t('.already_requested', :name => @person.name, :gender => current_user)