diff --git a/Gemfile b/Gemfile index 14d844eba..d3f3a22f2 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,9 @@ gem 'will_paginate', '3.0.pre2' #Statistics gem 'googlecharts' +#Inflected translations +gem 'i18n-inflector-rails', '~> 1.0' + #Uncatagorized gem 'roxml', :git => 'git://github.com/Empact/roxml.git', :ref => '7ea9a9ffd2338aaef5b0' gem 'addressable', '2.2.2', :require => 'addressable/uri' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f46693f0a..7615d6b43 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,6 +13,9 @@ class ApplicationController < ActionController::Base before_filter :set_git_header before_filter :which_action_and_user prepend_before_filter :clear_gc_stats + before_filter :set_grammatical_gender + + inflection_method :grammatical_gender => :gender def set_contacts_notifications_and_status if user_signed_in? @@ -68,4 +71,40 @@ class ApplicationController < ActionController::Base redirect_to root_url end end + + def set_grammatical_gender + if (user_signed_in? && I18n.inflector.inflected_locale?) + gender = current_user.profile.gender.to_s.tr('!()[]"\'`*=|/\#.,-:', '').downcase + unless gender.empty? + i_langs = I18n.inflector.inflected_locales(:gender) + i_langs.delete I18n.locale + i_langs.unshift I18n.locale + i_langs.each do |lang| + token = I18n.inflector.true_token(gender, :gender, lang) + unless token.nil? + @grammatical_gender = token + break + end + end + end + end + end + + def grammatical_gender + @grammatical_gender || nil + end + + def similar_people contact, opts={} + opts[:limit] ||= 5 + aspect_ids = contact.aspect_ids + count = Contact.count(:user_id => current_user.id, + :person_id.ne => contact.person.id, + :aspect_ids.in => aspect_ids) + + if count > opts[:limit] + offset = rand(count-opts[:limit]) + else + offset = 0 + end + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index fdd65f21d..0ee777a83 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,6 +8,7 @@ class PostsController < ApplicationController skip_before_filter :set_invites skip_before_filter :set_locale skip_before_filter :which_action_and_user + skip_before_filter :set_grammatical_gender def show @post = Post.where(:id => params[:id], :public => true).includes(:person, :comments => :person).first diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index f34421607..64db524f6 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -11,6 +11,7 @@ class PublicsController < ApplicationController skip_before_filter :set_invites skip_before_filter :set_locale skip_before_filter :which_action_and_user + skip_before_filter :set_grammatical_gender layout false caches_page :host_meta diff --git a/config/locales/inflections/all.yml b/config/locales/inflections/all.yml new file mode 100644 index 000000000..476a2af10 --- /dev/null +++ b/config/locales/inflections/all.yml @@ -0,0 +1,44 @@ + +all: + i18n: + inflections: + gender: + f: "female" + m: "male" + n: "neuter" + masculine: @m + male: @m + man: @m + boy: @m + b: @m + he: @m + sir: @m + mr: @m + mister: @m + guy: @m + dude: @m + gentleman: @m + mal: @m + female: @f + feminine: @f + girl: @f + g: @f + lady: @f + she: @f + miss: @f + missus: @f + mrs: @f + missis: @f + mistress: @f + ms: @f + neuter: @n + neutral: @n + it: @n + they: @n + impersonal: @n + default: n + + + + + diff --git a/config/locales/inflections/pl.yml b/config/locales/inflections/pl.yml new file mode 100644 index 000000000..7d02bea80 --- /dev/null +++ b/config/locales/inflections/pl.yml @@ -0,0 +1,64 @@ + +pl: + i18n: + inflections: + gender: + f: "rodzaj żeński" + m: "rodzaj męski" + n: "rodzaj nijaki" + masculine: @m + facet: @m + chłop: @m + chłopak: @m + chłopek: @m + chłopiec: @m + chłopaczek: @m + mąż: @m + prawiczek: @m + prawik: @m + boj: @m + woj: @m + gość: @m + gostek: @m + gościu: @m + samiec: @m + samczyk: @m + kawaler: @m + mężczyzna: @m + męski: @m + pani: @f + kobieta: @f + k: @f + kobietka: @f + dziewczyna: @f + dziewczę: @f + baba: @f + babka: @f + facetka: @f + dziewczynka: @f + dziewica: @f + niewiasta: @f + samica: @f + samiczka: @f + ona: @f + panna: @f + pannica: @f + panienka: @f + żeński: @f + laska: @f + lasencja: @f + żona: @f + dziewoja: @f + neuter: @n + to: @n + ono: @n + dziecko: @n + ktoś: @n + coś: @n + impersonal: @n + nijaki: @n + default: n + + + +