From 6f802417c6f57ad24a11ae56f6047a94e1922801 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 9 Jun 2023 00:59:46 +0200 Subject: [PATCH 1/2] Remove i18n-inflector-rails dependency There are no new releases anymore and the current version isn't compatible with ruby 3.x. As this feature wasn't really used a lot (Icelandic didn't even setup inflections properly), it's probably not worth fighting for it, so lets just drop it. Related to #8369 --- Gemfile | 1 - Gemfile.lock | 7 -- app/controllers/application_controller.rb | 25 -------- config/locales/devise/devise.is.yml | 6 +- config/locales/diaspora/pl.yml | 10 ++- config/locales/inflections/README.md | 2 - config/locales/inflections/all.yml | 44 ------------- config/locales/inflections/pl.yml | 64 ------------------- config/locales/javascript/javascript.pl.yml | 4 +- .../application_controller_spec.rb | 35 ---------- 10 files changed, 9 insertions(+), 189 deletions(-) delete mode 100644 config/locales/inflections/README.md delete mode 100644 config/locales/inflections/all.yml delete mode 100644 config/locales/inflections/pl.yml diff --git a/Gemfile b/Gemfile index 32e5d3875..8d30d3f4f 100644 --- a/Gemfile +++ b/Gemfile @@ -97,7 +97,6 @@ gem "js-routes", "2.2.4" # Localization gem "http_accept_language", "2.1.1" -gem "i18n-inflector-rails", "1.0.7" gem "rails-i18n", "6.0.0" # Map diff --git a/Gemfile.lock b/Gemfile.lock index c82d3bb83..bb7eb5083 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -362,12 +362,6 @@ GEM httpclient (2.8.3) i18n (1.12.0) concurrent-ruby (~> 1.0) - i18n-inflector (2.6.7) - i18n (>= 0.4.1) - i18n-inflector-rails (1.0.7) - actionpack (>= 3.0.0) - i18n-inflector (~> 2.6) - railties (>= 3.0.0) idn-ruby (0.1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) @@ -810,7 +804,6 @@ DEPENDENCIES hamlit (= 2.16.0) handlebars_assets (= 0.23.9) http_accept_language (= 2.1.1) - i18n-inflector-rails (= 1.0.7) jasmine (= 3.10.0) jasmine-jquery-rails (= 2.0.3) jquery-rails (= 4.5.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ec46be826..d3310079c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -21,15 +21,12 @@ class ApplicationController < ActionController::Base before_action :ensure_http_referer_is_set before_action :set_locale before_action :set_diaspora_header - before_action :set_grammatical_gender before_action :mobile_switch before_action :gon_set_current_user before_action :gon_set_appconfig before_action :gon_set_preloads before_action :configure_permitted_parameters, if: :devise_controller? - inflection_method grammatical_gender: :gender - helper_method :all_aspects, :all_contacts_count, :my_contacts_count, @@ -108,28 +105,6 @@ class ApplicationController < ActionController::Base redirect_to stream_url, notice: "you need to be an admin or moderator to do that" end - def set_grammatical_gender - if (user_signed_in? && I18n.inflector.inflected_locale?) - gender = current_user.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 - # use :mobile view for mobile and :html for everything else # (except if explicitly specified, e.g. :json, :xml) def mobile_switch diff --git a/config/locales/devise/devise.is.yml b/config/locales/devise/devise.is.yml index eeef6baae..b41e2a251 100644 --- a/config/locales/devise/devise.is.yml +++ b/config/locales/devise/devise.is.yml @@ -7,7 +7,7 @@ is: devise: confirmations: - confirmed: "Aðgangurinn þinn hefur nú verið staðfestur. Þú ert @{f:innskráð|m:innskráður|innskráð(ur)}." + confirmed: "Aðgangurinn þinn hefur nú verið staðfestur. Þú ert innskráð(ur)." new: resend_confirmation: "Endursenda leiðbeiningar um staðfestingu" send_instructions: "Þú munt fá tölvupóst innan fárra mínútna, með leiðbeiningum um hvernig þú staðfestir aðganginn þinn." @@ -23,7 +23,7 @@ is: invitations: invitation_token_invalid: "Okkur þykir það leitt, en þetta er ekki gildur boðslykill." send_instructions: "Boðið þitt hefur verið sent." - updated: "Nú er búið að stilla lykilorðið þitt og þú ert hér með @{f:innskráð|m:innskráður|innskráð(ur)}." + updated: "Nú er búið að stilla lykilorðið þitt og þú ert hér með innskráð(ur)." mailer: confirmation_instructions: confirm: "Staðfesta aðganginn minn" @@ -89,4 +89,4 @@ is: messages: already_confirmed: "var nú þegar staðfestur" not_found: "fannst ekki" - not_locked: "ólæstur" \ No newline at end of file + not_locked: "ólæstur" diff --git a/config/locales/diaspora/pl.yml b/config/locales/diaspora/pl.yml index d07c6a1c9..87c979b81 100644 --- a/config/locales/diaspora/pl.yml +++ b/config/locales/diaspora/pl.yml @@ -114,13 +114,11 @@ pl: account_closing_scheduled: "Konto należące do %{name} jest przewidziane do zamknięcia. Zostanie to wykonane w przecigu kilku chwil..." account_locking_scheduled: "Konto użytkownika %{name} oznaczone do zablokowania. Zostanie przetworzone za kilka chwil..." account_unlocking_scheduled: "Konto użytkownika %{name} oznaczone do odblokowania. Zostanie przetworzone za kilka chwil..." - add_admin: "%{name} zosta@{m:ł|f:ła|n:ło} mianowa@{m:ny|f:na|n:ne} administratorem." add_invites: "Dodaj zaproszenia" are_you_sure: "Czy na pewno chcesz zamknąć to konto?" are_you_sure_lock_account: "Na pewno zablokować to konto?" are_you_sure_unlock_account: "Na pewno odblokować to konto?" close_account: "Zamknij konto" - delete_admin: "%{name} został@{f:a|n:o} usunię@{m:ty|f:ta|n:te} z listy administratorów." does_not_exist: "Użytkownik nie istnieje!" email_to: "Zaproś przez e-mail" invite: "Zaproś" @@ -224,7 +222,7 @@ pl: edit: aspect_list_is_not_visible: "Kontakty z tego aspektu nie widzą się nawzajem." aspect_list_is_visible: "Kontakty z tego aspektu mogą zobaczyć się nawzajem." - confirm_remove_aspect: "@{m,f:Jesteś|n:Czy na}{ pew}{m:ien|f:na|n:no}{m,f:, że } chcesz usunąć ten aspekt?" + confirm_remove_aspect: "Czy na pewno chcesz usunąć ten aspekt?" rename: "Zmień nazwę" update: "Aktualizuj" updating: "Aktualizowanie" @@ -236,7 +234,7 @@ pl: contact_podmin: "Skontaktuj się z administratorem swojego poda!" do_you: "Czy:" feature_suggestion: "... masz propozycję (%{link})?" - find_a_bug: "... znal@{m:azłeś|f:azłaś|n:eziono} %{link}?" + find_a_bug: "... znaleziono %{link}?" have_a_question: "... masz %{link}?" here_to_help: "Społeczność diaspory* jest tutaj!" mail_podmin: "Adres e-mail administratora" @@ -951,7 +949,7 @@ pl: create: integrity_error: "Nie udało się przesłać zdjęcia? Czy to na pewno był plik obrazu?" runtime_error: "Nie udało się przesłać zdjęcia. Jesteś pewny, że zapiąłeś pasy bezpieczeństwa?" - type_error: "Nie udało się przesłać zdjęcia. Czy na pewno doda@{m:łeś|f:łaś|n:no} obraz?" + type_error: "Nie udało się przesłać zdjęcia. Czy na pewno dodano obraz?" destroy: notice: "Usunięto zdjęcie." new_profile_photo: @@ -1321,4 +1319,4 @@ pl: unconfirmed_email_not_changed: "Zmiana adresu e-mail nie powiodła się" will_paginate: next_label: "dalej »" - previous_label: "« wstecz" \ No newline at end of file + previous_label: "« wstecz" diff --git a/config/locales/inflections/README.md b/config/locales/inflections/README.md deleted file mode 100644 index 1bf552a3e..000000000 --- a/config/locales/inflections/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This directory contains the definitions for the [i18n-inflector gem](https://github.com/siefca/i18n-inflector). -Also, look up for our wiki on [How to contribute translations](http://wiki.diasporafoundation.org/Contribute_translations) for more information. diff --git a/config/locales/inflections/all.yml b/config/locales/inflections/all.yml deleted file mode 100644 index 3d3bf5d15..000000000 --- a/config/locales/inflections/all.yml +++ /dev/null @@ -1,44 +0,0 @@ - -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 deleted file mode 100644 index 967bdaef8..000000000 --- a/config/locales/inflections/pl.yml +++ /dev/null @@ -1,64 +0,0 @@ - -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 - - - - diff --git a/config/locales/javascript/javascript.pl.yml b/config/locales/javascript/javascript.pl.yml index 2905309b1..b87f289e4 100644 --- a/config/locales/javascript/javascript.pl.yml +++ b/config/locales/javascript/javascript.pl.yml @@ -93,7 +93,7 @@ pl: hide: "Ukryj komentarze" no_comments: "Póki co nie ma jeszcze żadnych komentarzy." show: "Pokaż wszystkie komentarze" - confirm_dialog: "Czy @{m,f:jesteś|n:na}{ pew}{m:ien|f:na|n:no}?" + confirm_dialog: "Czy na pewno?" confirm_unload: "Potwierdź, że chcesz opuścić tę stronę. Dane, które wprowadziłeś, nie zostaną zapisane." contacts: add_contact: "Dodaj kontakt" @@ -343,4 +343,4 @@ pl: other: "%d lat" unblock_failed: "Nie udało się odblokować tego użytkownika" viewer: - reshared: "Przekazano dalej" \ No newline at end of file + reshared: "Przekazano dalej" diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index c0b1c87cd..2f07505b0 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -124,39 +124,4 @@ describe ApplicationController, :type => :controller do expect(@controller.send(:after_sign_out_path_for, alice)).to eq(new_user_session_path) end end - - describe "#set_grammatical_gender" do - it "is called on page load" do - expect(@controller).to receive(:set_grammatical_gender) - get :index - end - - context "for inflected locales" do - before do - alice.language = :pl - alice.save - end - - it "returns nil for an empty gender" do - alice.person.profile.gender = "" - alice.person.profile.save - get :index - expect(assigns[:grammatical_gender]).to be_nil - end - - it "returns nil for an unrecognized gender" do - alice.person.profile.gender = "robot" - alice.person.profile.save - get :index - expect(assigns[:grammatical_gender]).to be_nil - end - - it "sets the correct grammatical gender" do - alice.person.profile.gender = "ona" - alice.person.profile.save - get :index - expect(assigns[:grammatical_gender]).to eq(:f) - end - end - end end From 5508401ed836626d48cde8f25d17db34dc40b280 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sat, 10 Jun 2023 04:07:01 +0200 Subject: [PATCH 2/2] Don't modify default translations when merging with other language `deep_merge!` modifies the hash of the default translation, and it looks like `I18n.t` always returns the same instance, so after that, the default stays translated. So lets duplicate the hash first, before modifying it, this also helps because we also add more keys below, which probably also shouldn't be added to the original. --- app/helpers/language_helper.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/helpers/language_helper.rb b/app/helpers/language_helper.rb index 3c742c2f4..11965dc60 100644 --- a/app/helpers/language_helper.rb +++ b/app/helpers/language_helper.rb @@ -12,16 +12,12 @@ module LanguageHelper end def get_javascript_strings_for(language, section) - defaults = I18n.t(section, :locale => DEFAULT_LANGUAGE) + translations = I18n.t(section, locale: DEFAULT_LANGUAGE).dup + translations.deep_merge!(I18n.t(section, locale: language)) if language != DEFAULT_LANGUAGE - if language != DEFAULT_LANGUAGE - translations = I18n.t(section, :locale => language) - defaults.deep_merge!(translations) - end - - defaults['pluralization_rule'] = I18n.t('i18n.plural.js_rule', :locale => language) - defaults['pod_name'] = pod_name - defaults + translations["pluralization_rule"] = I18n.t("i18n.plural.js_rule", locale: language) + translations["pod_name"] = pod_name + translations end def direction_for(string)