From f2123d942dea8770bf57f7798283b079d6cbdf9f Mon Sep 17 00:00:00 2001 From: Lennart Prelle Date: Sun, 16 Oct 2011 17:13:21 +0200 Subject: [PATCH] make language for email-invitation available --- app/controllers/invitations_controller.rb | 4 +- app/models/invitation.rb | 5 +- app/models/jobs/mail/invite_user_by_email.rb | 4 +- .../devise/mailer/invitation_instructions.erb | 48 +++++++++---------- app/views/invitations/new.html.haml | 7 +++ config/locales/devise/devise.en.yml | 24 ++++++++++ config/locales/diaspora/en.yml | 1 + ...11016145626_add_language_to_invitations.rb | 9 ++++ spec/models/invitation_spec.rb | 29 +++++++---- 9 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 db/migrate/20111016145626_add_language_to_invitations.rb diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index ef6a0b0f6..3f4e95435 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -22,8 +22,10 @@ class InvitationsController < Devise::InvitationsController emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */) #NOTE should we try and find users by email here? probs aspect = current_user.aspects.find(aspect_id) + + language = params[:user][:language] - invites = Invitation.batch_invite(emails, :message => message, :sender => current_user, :aspect => aspect, :service => 'email') + invites = Invitation.batch_invite(emails, :message => message, :sender => current_user, :aspect => aspect, :service => 'email', :language => language) flash[:notice] = extract_messages(invites) diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 3465211df..3be97a991 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -8,7 +8,7 @@ class Invitation < ActiveRecord::Base belongs_to :recipient, :class_name => 'User' belongs_to :aspect - attr_accessible :sender, :recipient, :aspect, :service, :identifier, :admin, :message + attr_accessible :sender, :recipient, :aspect, :language, :service, :identifier, :admin, :message before_validation :set_email_as_default_service @@ -47,7 +47,8 @@ class Invitation < ActiveRecord::Base end emails end - + + # Downcases the incoming service identifier and assigns it # # @param ident [String] Service identifier diff --git a/app/models/jobs/mail/invite_user_by_email.rb b/app/models/jobs/mail/invite_user_by_email.rb index 37b403d34..e1e348a3f 100644 --- a/app/models/jobs/mail/invite_user_by_email.rb +++ b/app/models/jobs/mail/invite_user_by_email.rb @@ -9,7 +9,9 @@ module Jobs @queue = :mail def self.perform(invite_id) invite = Invitation.find(invite_id) - invite.send! + I18n.with_locale(invite.language) do + invite.send! + end end end end diff --git a/app/views/devise/mailer/invitation_instructions.erb b/app/views/devise/mailer/invitation_instructions.erb index fc8256187..f3fe8a240 100644 --- a/app/views/devise/mailer/invitation_instructions.erb +++ b/app/views/devise/mailer/invitation_instructions.erb @@ -3,7 +3,7 @@ <%=invite_email_title %> -

Email not displaying correctly? View it in your browser

+

<%= t('.displaying_correctly', :link => link_to(t('.view_in'), invite_email_url(:invitation_token => @resource.invitation_token), :style => "color: #3F8FBA; text-decoration: none;")).html_safe %>

@@ -20,7 +20,7 @@ @@ -30,10 +30,10 @@ @@ -43,7 +43,7 @@ @@ -59,7 +59,7 @@ @@ -77,7 +77,7 @@ + 1. <%= t('.get_connected') %>
- Finally - it's here.
+ <%= t('.finally') %>
- The social network you have been waiting for has arrived. Revamped, more secure, and more fun, DIASPORA* is ready to help you share and explore the web in a whole new way. + <%= t('.arrived', :strong_diaspora => content_tag(:strong, "DIASPORA*")).html_safe %>

- Sign up now → + <%= link_to(t('.sign_up_now').html_safe, accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :style => "color: #3F8FBA; text-decoration: underline; font-weight: bold; font-size: 20px;", :target => "_blank").html_safe %>

- What your friends are saying...
+ <%= t('.friends_saying') %>

- Even more people are excited to see you!
+ <%= t('.more_people') %>
- 1. Get Connected
@@ -85,7 +85,7 @@ @@ -94,14 +94,14 @@ + 2. <%= t('.be_yourself') %>
- An international movement with a shared vision for a better web, DIASPORA*'s #1 feature is its community. Meet new people, connect with friends, and join the fun. + <%= t('.get_connected_paragraph', :strong_diaspora => content_tag(:strong, "DIASPORA*")).html_safe %>
- 2. Be Yourself
@@ -115,7 +115,7 @@ + 3. <%= t('.have_fun') %>
- The Internet has created unique new ways for us to express ourselves. - DIASPORA* lets you be yourself and share however you want, with or without your real name. + <%= t('.be_yourself_paragraph', :strong_diaspora => content_tag(:strong, "DIASPORA*")).html_safe %> +
- 3. Have Fun
@@ -123,11 +123,8 @@ @@ -139,7 +136,7 @@ @@ -151,9 +148,8 @@ @@ -161,12 +157,14 @@
- DIASPORA* is all about discovering amazing new content and people online. - - Cubbi.es, - the world's first DIASPORA* application is just the begining. - Collect and share the web in all of its glory. + + <%= t('.have_fun_paragraph', :strong_diaspora => content_tag(:strong, "DIASPORA*"), :link => link_to(t('.cubbies'), "https://cubbi.es", :style => "color: #3F8FBA; text-decoration: underline; font-weight: bold; font-size: 20px;", :target => "_blank")).html_safe %>
- Sign up now → + <%= link_to(t('.sign_up_now').html_safe, accept_invitation_url(@resource, :invitation_token => @resource.invitation_token), :style => "color: #3F8FBA; text-decoration: underline; font-weight: bold; font-size: 20px;", :target => "_blank").html_safe %>
- DIASPORA* is made by people who love the Internet as much as you do. - Join our team, or - help fund Diaspora! + <%= t('.made_by_people', :strong_diaspora => content_tag(:strong, "DIASPORA*"), :jointeam => link_to(t('.join_team'), "https://github.com/diaspora/diaspora/wiki/Become-a-Contributor", :style =>"color: #3F8FBA; text-decoration: underline; font-weight: bold; font-size: 18px;", :target => "_blank"), :helpfund => link_to(t('.help_fund'), "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QG4L6VYD8YGPU", :style =>"color: #3F8FBA; text-decoration: underline; font-weight: bold; font-size: 18px;", :target => "_blank")).html_safe %> +
- Love,
- Team Diaspora
+ <%= t('.love') %>
+ <%= t('.team_diaspora') %>
- To unsubscribe please click here. - For general inquiries or support with your Diaspora account, please email us at questions@joindiaspora.com. + <% if AppConfig[:pod_uri].host.match(/joindiaspora.com/) %> + <%= t('.unsubscribe', :link => link_to(t('.here'), "http://joindiaspora.us1.list-manage.com/unsubscribe?u=d759919b94f9cdcf39d204f3f&id=7b5ceb2f8b", :style => "color: #3F8FBA; text-decoration: none;")).html_safe %> + <% end %> + <%= t('.email_us', :email => link_to(t('.email_address'), "mailto:questions@joindiaspora.com", :style => "color: #3F8FBA; text-decoration: none;")).html_safe %>
diff --git a/app/views/invitations/new.html.haml b/app/views/invitations/new.html.haml index 82abcf855..2a55bf40c 100644 --- a/app/views/invitations/new.html.haml +++ b/app/views/invitations/new.html.haml @@ -23,6 +23,13 @@ %br %br + %h4 + = t('.language') + = invite.select(:language, available_language_options, :selected => current_user.language) + + %br + %br + %h4 = t('.personal_message') = invite.text_area :invite_messages, :rows => 3, :value => "" diff --git a/config/locales/devise/devise.en.yml b/config/locales/devise/devise.en.yml index fcca12c35..83ad2a20a 100644 --- a/config/locales/devise/devise.en.yml +++ b/config/locales/devise/devise.en.yml @@ -73,6 +73,30 @@ en: click_to_unlock: "Click the link below to unlock your account:" unlock: "Unlock my account" invitation_instructions: + displaying_correctly: "Email not displaying correctly? %{link} in your browser" + view_in: "View in" + finally: "Finally - it's here" + arrived: "The social network you have been waiting for has arrived. Revamped, more secure, and more fun, %{strong_diaspora} is ready to help you share and explore the web in a whole new way." + sign_up_now: "Sign up now →" + friends_saying: "What your friends are saying..." + more_people: "Even more people are excited to see you!" + get_connected: "Get Connected" + get_connected_paragraph: "An international movement with a shared vision for a better web, %{strong_diaspora}'s #1 feature is its community. Meet new people, connect with friends, and join the fun." + be_yourself: "Be Yourself" + be_yourself_paragraph: "The Internet has created unique new ways for us to express ourselves. %{strong_diaspora} lets you be yourself and share however you want, with or without your real name." + have_fun: "Have Fun" + cubbies: "Cubbi.es" + have_fun_paragraph: "%{strong_diaspora} is all about discovering amazing new content and people online. %{link}, the world's first %{strong_diaspora} application is just the begining. Collect and share the web in all of its glory." + made_by_people: "%{strong_diaspora} is made by people who love the Internet as much as you do. %{jointeam}, or %{helpfund}!" + join_team: "Join our Team" + or: "or" + help_fund: "help fund Diaspora" + unsubscribe: "To unsubscribe please click %{link}." + here: "here" + love: "Love," + team_diaspora: "Team Diaspora" + email_us: "For general inquiries or support with your Diaspora account, please email us at %{email}." + email_address: "questions@joindiaspora.com" subject: "You've been invited to join Diaspora!" accept: "Accept invitation" ignore: "If you don't want to accept the invitation, please ignore this email." diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 3d3728fef..bd915ca2f 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -318,6 +318,7 @@ en: already_contacts: "You are already connected with this person" own_address: "You can't send an invitation to your own address." new: + language: "Language" 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." comma_seperated_plz: "You can enter multiple email addresses separated by commas." diff --git a/db/migrate/20111016145626_add_language_to_invitations.rb b/db/migrate/20111016145626_add_language_to_invitations.rb new file mode 100644 index 000000000..4f9129f40 --- /dev/null +++ b/db/migrate/20111016145626_add_language_to_invitations.rb @@ -0,0 +1,9 @@ +class AddLanguageToInvitations < ActiveRecord::Migration + def self.up + add_column :invitations, :language, :string, :default => "en" + end + + def self.down + remove_column :invitations, :language + end +end diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 11c2cc82d..8837700f7 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -13,13 +13,14 @@ describe Invitation do end describe 'validations' do before do - @invitation = Factory.build(:invitation, :sender => user, :recipient => nil, :aspect => user.aspects.first) + @invitation = Factory.build(:invitation, :sender => user, :recipient => nil, :aspect => user.aspects.first, :language => "de") end it 'is valid' do @invitation.sender.should == user @invitation.recipient.should == nil @invitation.aspect.should == user.aspects.first + @invitation.language.should == "de" @invitation.should be_valid end @@ -29,20 +30,30 @@ describe Invitation do end end + describe '#language' do + it 'returns the correct language if the language is set' do + @invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => "de") + @invitation.language.should == "de" + end + + it 'returns en if no language is set' do + @invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first) + @invitation.language.should == "en" + end + end + it 'has a message' do - @invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first) + @invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => user.language) @invitation.message = "!" @invitation.message.should == "!" end - - describe 'the invite process' do before do end it 'works for a new user' do - invite = Invitation.new(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'foo@bar.com') + invite = Invitation.new(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'foo@bar.com', :language => alice.language) lambda { invite.save invite.send! @@ -50,7 +61,7 @@ describe Invitation do end it 'works for a current user(with the right email)' do - invite = Invitation.create(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => bob.email) + invite = Invitation.create(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => bob.email, :language => alice.language) lambda { invite.send! }.should_not change(User, :count) @@ -80,7 +91,7 @@ describe Invitation do describe '.batch_invite' do before do @emails = ['max@foo.com', 'bob@mom.com'] - @opts = {:aspect => eve.aspects.first, :sender => eve, :service => 'email'} + @opts = {:aspect => eve.aspects.first, :sender => eve, :service => 'email', :language => eve.language} end it 'returns an array of invites based on the emails passed in' do @@ -102,7 +113,7 @@ describe Invitation do describe 'send' do before do - @invitation = Factory(:invitation, :sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'a@a.com') + @invitation = Factory(:invitation, :sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'a@a.com' , :language => alice.language) end it 'sends an email' do @@ -133,7 +144,7 @@ describe Invitation do describe '#recipient_identifier' do it 'calls email if the invitation_service is email' do email = 'abc@abc.com' - invitation = Factory(:invitation, :sender => alice, :service => 'email', :identifier => email, :aspect => alice.aspects.first) + invitation = Factory(:invitation, :sender => alice, :service => 'email', :identifier => email, :aspect => alice.aspects.first, :language => alice.language) invitation.recipient_identifier.should == email end