From ce295cecfcf129039491e3a14039dca9dcf7298f Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 30 Sep 2018 16:24:19 -0400 Subject: [PATCH 01/14] application_controller.rb: Adjust set_locale logic Adds a :locale parameter (which should come from the URL, e.g.: `refugerestrooms.org/?locale=en` or something like that.) --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 103cf92c..f401a503 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,7 +10,7 @@ def mobile_filter_header end def set_locale - I18n.locale = http_accept_language.language_region_compatible_from(I18n.available_locales) + I18n.locale = params[:locale] || http_accept_language.language_region_compatible_from(I18n.available_locales) end end From f68362593715147832e7f6cacbc3076a130acb62 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 30 Sep 2018 19:13:43 -0400 Subject: [PATCH 02/14] application_controller.rb: set up default_url_options Allows URLs auto-generated by Rails to automatically be expanded to include "?locale=xyz" or "&locale=xyz" See: https://guides.rubyonrails.org/v5.2.4/i18n.html#setting-the-locale-from-url-params For example, this affects URLs made with ActionView URL helpers ('button_to', 'link_to', etc.) See: https://api.rubyonrails.org/v5.2.4/classes/ActionView/Helpers/UrlHelper.html (Hard-coded URLS will generally not get the parameter added.) --- app/controllers/application_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f401a503..d0ee37ba 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,4 +13,8 @@ def set_locale I18n.locale = params[:locale] || http_accept_language.language_region_compatible_from(I18n.available_locales) end + def default_url_options + { locale: I18n.locale } + end + end From c94f6ebea4d5e87ea671afdfbf3b19b9edf13555 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 30 Sep 2018 21:14:50 -0400 Subject: [PATCH 03/14] header: Use link_to helper for homepage link Use a link_to helper to dynamically create the homepage link, because URL helpers now automatically include the 'locale=' parameter. --- app/views/layouts/_navigation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index af1795d1..a493ad8f 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -4,7 +4,7 @@ %nav.nav.navbar-default{:role => "navigation"} / Brand and toggle get grouped for better mobile display .navbar-header - %a#logo.toiletLogo{:href => "/"} + = link_to root_path, id: "logo", class: "toiletLogo" do .navbar-brand Refuge Restrooms %button.navbar-toggle{"data-target" => "#bs-example-navbar-collapse-1", "data-toggle" => "collapse", :type => "button"} %span.sr-only= t('.toggle-navigation-button-label') From fbf2a731d5c03d300b8755a7be7716367f82452f Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Fri, 10 Apr 2020 13:22:42 -0400 Subject: [PATCH 04/14] _navigation.html.haml: Un-hard-code the api docs link Use the 'api_docs_path' helper, rather than hard-coding '/api/docs'. (This is for the navigation header, under the "Resources" drop-down.) --- app/views/layouts/_navigation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index a493ad8f..84a91d27 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -21,5 +21,5 @@ %b.caret %ul.dropdown-menu %li= link_to t('.download-unisex-restroom-signs-hyperlink-label'), page_path('signs') - %li= link_to t('.public-api-hyperlink-label'), '/api/docs/' + %li= link_to t('.public-api-hyperlink-label'), api_docs_path / /.navbar-collapse From 85f19985e92573d433fd061550266ff01706d76c Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Fri, 10 Apr 2020 12:41:19 -0400 Subject: [PATCH 05/14] config/routes.rb: Add (optional) locale scope to all pages Adds an optional locale prefix for almost every page in the app. See: https://guides.rubyonrails.org/v5.2.4/i18n.html#setting-the-locale-from-url-params You can now visit e.g. '/es/restrooms/new' and you will see the "Submit a New Restroom" page in Spanish. All links in the app auto-generate this locale prefix, so users can specify a locale via visiting a specific locale prefix, and the links in the app will not misdirect them into another locale. (You can still visit URLs without a locale prefix, like '/restrooms/new', and the app will simply auto-detect the locale based on the preferred languages in your browser settings.) This preserves the existing URLs in working order, and any links out there on the web, or in people's bookmarks, will still work.) The home page does not always get the prefix: - The home page link in nav is just '/?locale=[I18n.locale]' - You can visit '/?locale=es' to see the homepage in Spanish. - The homepage link in the nav are auto-generated as '/?locale=[I18n.locale]'; This is equivalent in functionality to the locale prefixes (e.g. '/es/'). - The homepage links in the footer are auto-generated as '/[I18n.locale]/'. - You can visit '/es/' to see the homepage in Spanish. --- config/routes.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 47a7974f..273d8d6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,18 +2,27 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :admin_users, ActiveAdmin::Devise.config + get '/:locale' => 'pages#index' + root 'pages#index' + ActiveAdmin.routes(self) - resources :restrooms, except: [:edit, :destroy] + scope "(:locale)" do + resources :restrooms, except: [:edit, :destroy] + end namespace :api do - resources :docs, only: [:index] + scope "(:locale)" do + resources :docs, only: [:index] + end end mount API::Base => '/api' + scope "(:locale)" do + get '/contact', to: 'contacts#new' + get "/*id" => 'pages#show', as: :page, format: false + end - get '/contact', to: 'contacts#new' - get "/*id" => 'pages#show', as: :page, format: false - root 'pages#index' - - resources "contacts", only: [:new, :create] + scope "(:locale)" do + resources "contacts", only: [:new, :create] + end end From 3992bc4cfdf9f4bf40612621908fd9ff9e8d943e Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Fri, 10 Apr 2020 15:30:21 -0400 Subject: [PATCH 06/14] _footer.html.haml: Add locale switcher links Adds locale switcher links in the footer, which displays at the bottom of every page. These links dynamically link to the current page the user is viewing, but with the current locale overridden with a specific, new locale. Uses the Rails API's "ActionDispatch::Request" feature to get a string containing the last requested page, (i.e. the page the user is currently viewing). This includes query parameters, such as "?lat=[num]&long=[num]" See: https://api.rubyonrails.org/v5.2.4/classes/ActionDispatch/Request.html#method-i-GET (Parameters can also be derived from the URL, such as the "es/" in "/es/restrooms/new", if routed properly.) See: https://guides.rubyonrails.org/routing.html See these StackOverflow answers/this Wikipedia article for details: - https://stackoverflow.com/questions/3762430/rails-preserving-get-query-string-parameters-in-link-to - https://stackoverflow.com/questions/6885990/rails-params-explained - https://en.wikipedia.org/wiki/Query_string --- app/views/layouts/_footer.html.haml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 422b5898..a26c735a 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -16,4 +16,13 @@ %a{:href => "https://patreon.com/refugerestrooms"} #{t('.on-patreon')} %br/ = "\© #{t('.copyleft')} #{Date.today.year} #{t('.refuge-restrooms')}".html_safe - + %br/ + %br/ + = link_to 'English', request.query_parameters.merge({:locale => 'en'}) + = link_to 'Español', request.query_parameters.merge({:locale => 'es'}) + = link_to 'Filipino/Tagalog', request.query_parameters.merge({:locale => 'fil'}) + = link_to 'Français', request.query_parameters.merge({:locale => 'fr'}) + = link_to 'हिन्दी', request.query_parameters.merge({:locale => 'hi'}) + = link_to 'Italiano', request.query_parameters.merge({:locale => 'it'}) + = link_to 'polski', request.query_parameters.merge({:locale => 'pl'}) + = link_to 'Português do Brasil', request.query_parameters.merge({:locale => 'pt-BR'}) From 7e9d164fafa5d056f08f4d59adf7d0b850de5ee8 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Fri, 10 Apr 2020 15:47:36 -0400 Subject: [PATCH 07/14] CSS: Better styling of the locale-switcher links Spaced out the links a bit, and added bullet-point separators. --- app/assets/stylesheets/components/common.scss | 4 ++++ app/views/layouts/_footer.html.haml | 23 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/components/common.scss b/app/assets/stylesheets/components/common.scss index 020bf413..07854368 100644 --- a/app/assets/stylesheets/components/common.scss +++ b/app/assets/stylesheets/components/common.scss @@ -145,3 +145,7 @@ footer { color: #BE1E2D; } } + +.locale_link { + margin: 0px 5px; +} diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index a26c735a..2266faef 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -18,11 +18,18 @@ = "\© #{t('.copyleft')} #{Date.today.year} #{t('.refuge-restrooms')}".html_safe %br/ %br/ - = link_to 'English', request.query_parameters.merge({:locale => 'en'}) - = link_to 'Español', request.query_parameters.merge({:locale => 'es'}) - = link_to 'Filipino/Tagalog', request.query_parameters.merge({:locale => 'fil'}) - = link_to 'Français', request.query_parameters.merge({:locale => 'fr'}) - = link_to 'हिन्दी', request.query_parameters.merge({:locale => 'hi'}) - = link_to 'Italiano', request.query_parameters.merge({:locale => 'it'}) - = link_to 'polski', request.query_parameters.merge({:locale => 'pl'}) - = link_to 'Português do Brasil', request.query_parameters.merge({:locale => 'pt-BR'}) + = link_to 'English', request.query_parameters.merge({:locale => 'en'}), class: "locale_link" + • + = link_to 'Español', request.query_parameters.merge({:locale => 'es'}), class: "locale_link" + • + = link_to 'Filipino/Tagalog', request.query_parameters.merge({:locale => 'fil'}), class: "locale_link" + • + = link_to 'Français', request.query_parameters.merge({:locale => 'fr'}), class: "locale_link" + • + = link_to 'हिन्दी', request.query_parameters.merge({:locale => 'hi'}), class: "locale_link" + • + = link_to 'Italiano', request.query_parameters.merge({:locale => 'it'}), class: "locale_link" + • + = link_to 'polski', request.query_parameters.merge({:locale => 'pl'}), class: "locale_link" + • + = link_to 'Português do Brasil', request.query_parameters.merge({:locale => 'pt-BR'}), class: "locale_link" From 905aa8e4288561f79054523e91dcf5178f35d402 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Tue, 14 Apr 2020 12:43:17 -0400 Subject: [PATCH 08/14] spec: Fix a path construction, test passes now Passing the whole array of restroom data was causing the whole array to be erroneously interpreted as if it was the :locale prefix in the path. Explicitly pass :id, and only :id, to the `restroom_path` route helper for this test. (We only need the :id from the newly-constructed test restroom in order to visit the correct path. Other restroom data isn't needed here anyhow.) Co-authored-by: Mikena Wood --- spec/features/contacts_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/contacts_spec.rb b/spec/features/contacts_spec.rb index 3752214c..3a53d8cc 100644 --- a/spec/features/contacts_spec.rb +++ b/spec/features/contacts_spec.rb @@ -4,7 +4,7 @@ it 'should show a generic contact when contact is not from restroom form' do restroom = create(:restroom, name: "Mission Creek Cafe") - visit restroom_path restroom + visit restroom_path(:id => restroom.id) click_link 'Contact' expect(page).to_not have_content('Mission Creek Cafe') From 814519a5bfe15d5d64f2fb3793cc3db4403c301f Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 1 Nov 2020 14:56:49 -0500 Subject: [PATCH 09/14] spec/features/contacts_spec.rb: Fix rubocop lint --- spec/features/contacts_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/contacts_spec.rb b/spec/features/contacts_spec.rb index 78e8ee3e..d30d3bfb 100644 --- a/spec/features/contacts_spec.rb +++ b/spec/features/contacts_spec.rb @@ -4,7 +4,7 @@ it 'shows a generic contact when contact is not from restroom form' do restroom = create(:restroom, name: "Mission Creek Cafe") - visit restroom_path(:id => restroom.id) + visit restroom_path(id: restroom.id) click_link 'Contact' expect(page).not_to have_content('Mission Creek Cafe') From 4b5262a43e5eeb094745413781b62fe1a8428dc1 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 1 Nov 2020 14:59:55 -0500 Subject: [PATCH 10/14] Revert "config/routes.rb: Add (optional) locale scope to all pages" This reverts commit 85f19985e92573d433fd061550266ff01706d76c. Try this pull request again, without the `locale/` URL prefix feature. --- config/routes.rb | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 273d8d6b..47a7974f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,27 +2,18 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :admin_users, ActiveAdmin::Devise.config - get '/:locale' => 'pages#index' - root 'pages#index' - ActiveAdmin.routes(self) - scope "(:locale)" do - resources :restrooms, except: [:edit, :destroy] - end + resources :restrooms, except: [:edit, :destroy] namespace :api do - scope "(:locale)" do - resources :docs, only: [:index] - end + resources :docs, only: [:index] end mount API::Base => '/api' - scope "(:locale)" do - get '/contact', to: 'contacts#new' - get "/*id" => 'pages#show', as: :page, format: false - end - scope "(:locale)" do - resources "contacts", only: [:new, :create] - end + get '/contact', to: 'contacts#new' + get "/*id" => 'pages#show', as: :page, format: false + root 'pages#index' + + resources "contacts", only: [:new, :create] end From 3e976ba2cb52de3c724532c484539a401f531cce Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Mon, 2 Nov 2020 19:31:04 -0500 Subject: [PATCH 11/14] Dynamically compose About and Business FAQ links Dynamically compose the "Business FAQ" link on the "About" page and the "About Page" link on the "Business FAQ" page using Rails link helpers, so that the locale (and any other default URL parameters) are automatically added to these links. In other words, "un-hard-code" these links. (In this commit, updated the Haml source of the About and Business FAQ pages, and only the English internationalization (I18n) strings.) --- app/views/pages/about.html.haml | 4 ++-- app/views/pages/business_info.html.haml | 3 ++- config/locales/en/about.en.yml | 4 +++- config/locales/en/business_info.yml | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/views/pages/about.html.haml b/app/views/pages/about.html.haml index fd433330..c5f6d93d 100644 --- a/app/views/pages/about.html.haml +++ b/app/views/pages/about.html.haml @@ -34,5 +34,5 @@ %h3 = t('about.p6header') %p - = t('about.p6').html_safe - + - @business_faq_link = link_to t('about.p6.business_faq'), page_path('business_info') + = t('about.p6.text', business_faq_variable: @business_faq_link).html_safe diff --git a/app/views/pages/business_info.html.haml b/app/views/pages/business_info.html.haml index 2d9a3895..690950fc 100644 --- a/app/views/pages/business_info.html.haml +++ b/app/views/pages/business_info.html.haml @@ -5,7 +5,8 @@ %h3 = t('business_info.p1header') %p - = t('business_info.p1').html_safe + - @about_link_helper = link_to t('business_info.p1.about_page'), page_path('about') + = t('business_info.p1.text', about_page_variable: @about_link_helper).html_safe %h3 = t('business_info.p2header') %p diff --git a/config/locales/en/about.en.yml b/config/locales/en/about.en.yml index 1d5f8a49..475ac182 100644 --- a/config/locales/en/about.en.yml +++ b/config/locales/en/about.en.yml @@ -18,5 +18,7 @@ en: third: "Thirdly: If you know how to code, visit GitHub and let us know about a bug, suggest an improvement, or even contribute a little bit of code and help out the project. REFUGE is open source and we can't do it without you." fourth: "Fourthly: Donate. Keep your eyes peeled for an upcoming crowd funding campaign to fund some of the technology we need to use as well as to pay our fabulous designers and engineers a little bit of money for their hard and tireless work. They have been working for free to bring this service to you and we don't want anybody to work for free. Most of the core team are transgender and underemployed at this time." p6header: "Why is my business or organization listed?" - p6: "Find out more on our Business FAQ!" + p6: + text: "Find out more on our %{business_faq_variable}!" + business_faq: "Business FAQ" contribute: 'Fork us and contribute on GitHub!' diff --git a/config/locales/en/business_info.yml b/config/locales/en/business_info.yml index 1fa2384b..c90915df 100644 --- a/config/locales/en/business_info.yml +++ b/config/locales/en/business_info.yml @@ -2,7 +2,9 @@ en: business_info: title: "Refuge Restrooms Business Info" p1header: "1) What is Refuge Restrooms?" - p1: "REFUGE is a web application that seeks to provide safe restroom access for transgender, intersex, and gender nonconforming individuals. Read more about us on our About Page." + p1: + text: "REFUGE is a web application that seeks to provide safe restroom access for transgender, intersex, and gender nonconforming individuals. Read more about us on our %{about_page_variable}." + about_page: "About Page" p2header: "2) How did my facility get on this list?" p2: "Someone used your restroom and wanted to submit your location as a resource. All our data is crowd-sourced and user-submitted." p3header: "3) How can I be a good host?" @@ -21,4 +23,3 @@ en: p5: "Reviews help visitors share experiences with each other about the location. We encourage visitors to share as much information as we have about each location on the map." p6header: "6) How do I remove my listing?" p6: "We hope you'll consider keeping your listing; it can mean a lot for people's health and wellbeing. However, if you'd rather not be listed, use our contact form to request a removal and our volunteers will work on it as soon as we can (this is an open source project so all work is done by volunteers)." - From 54380c9a74821eecc2d0bdf215f65e78b2fe6f22 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Mon, 2 Nov 2020 20:32:14 -0500 Subject: [PATCH 12/14] locales: Update "About" and "Business FAQ" text Update the formatting of the "About" and "Business FAQ" links in the various locales other than English. --- config/locales/es/about.es.yml | 4 +++- config/locales/es/business_info.es.yml | 4 +++- config/locales/fil/about.fil.yml | 4 +++- config/locales/fil/business_info.fil.yml | 4 +++- config/locales/fr/about.fr.yml | 4 +++- config/locales/fr/business_info.yml | 4 +++- config/locales/hi/about.hi.yml | 4 +++- config/locales/hi/business_info.yml | 5 +++-- config/locales/it/about.it.yml | 4 +++- config/locales/it/business_info.yml | 5 +++-- config/locales/pl/about.pl.yml | 6 ++++-- config/locales/pl/business_info.pl.yml | 6 ++++-- config/locales/pt-BR/about.pt-BR.yml | 4 +++- config/locales/pt-BR/business_info.pt-BR.yml | 5 +++-- 14 files changed, 44 insertions(+), 19 deletions(-) diff --git a/config/locales/es/about.es.yml b/config/locales/es/about.es.yml index 7aff4a38..75c995f6 100644 --- a/config/locales/es/about.es.yml +++ b/config/locales/es/about.es.yml @@ -18,5 +18,7 @@ es: third: "Tercero: Sí sabe de programación, puedes visitar GitHub para avisarnos sobre un problema técnico (bug), para añadir un issue, o puede constribuir código para ayudarnos con el proyecto. REFUGE es de código abierto y no podemos hacerlo sin usted." fourth: "Cuarto: Donar. Mantente en alerta, proxímamente habra una campaña de financiamiento masiva, para poder acceder a la tecnología que necesitamos usar y para poder pagarle un poco a quienes diseñan y desarrollan nuestra tecnología por su gran esfuerzo incansable. Han estado trabajando gratuitamente para traerte este servicio y no queremos que trabajen gratis. La mayoría de nuesto equipo principal son personas trans y están con bajo empleo en este momento." p6header: "¿Por qué aparece mi organización o empresa en su listado?" - p6: "Obtenga más información sobre nuestras preguntas frecuentes para organizaciones y empresas!" + p6: + text: "Obtenga más información sobre nuestras %{business_faq_variable}!" + business_faq: "preguntas frecuentes para organizaciones y empresas" contribute: 'Haz un Fork para contribuir en GitHub!' diff --git a/config/locales/es/business_info.es.yml b/config/locales/es/business_info.es.yml index 9b6f3932..ddd1541e 100644 --- a/config/locales/es/business_info.es.yml +++ b/config/locales/es/business_info.es.yml @@ -2,7 +2,9 @@ es: business_info: title: "Preguntas frecuentes para organizaciones y empresas sobre Refuge Restrooms" p1header: "1) ¿Qué es Refuge Restrooms?" - p1: "REFUGE es una aplicación web que busca proveer acceso seguro a baños para personas trans, intersexo, y personas género no conformes. Puedes leer más en Acerca de REFUGE." + p1: + text: "REFUGE es una aplicación web que busca proveer acceso seguro a baños para personas trans, intersexo, y personas género no conformes. Puedes leer más en %{about_page_variable}." + about_page: "Acerca de REFUGE" p2header: "2) ¿Cómo llegó mi instalación a esta lista?" p2: "Alguien usó su baño y quizo enviar su ubicación como recurso. Todos nuestros datos son de fuentes múltiples y enviados por el usuario" p3header: "3) ¿Cómo puedo ser un buen anfitrión?" diff --git a/config/locales/fil/about.fil.yml b/config/locales/fil/about.fil.yml index ee4a6f63..a323233c 100644 --- a/config/locales/fil/about.fil.yml +++ b/config/locales/fil/about.fil.yml @@ -18,5 +18,7 @@ fil: third: "Ikatlo: Kung alam mo kun paano mag-code, bumisita sa GitHub at ipaalam sa amin ang tungkol sa bug, magmungkahi ng mga pagpapahusay, o kaya mag-ambag ng kunting code at tumulong sa proyektong ito. Ang REFUGE ay isang open source at hindi namin ito magagawa kung wala kayo." fourth: "Ikaapat: Mag-ambag. Maging mapagmatyag sa darating na pangangalap ng pondo mula sa mga tao para makapaglikha ng pondo sa iilang teknolohiya na kinakailangan gamitin pati narin ang pagbayad sa mga taga-desinyo at mga inhinyero kahit sa maliit na halaga para sa kanilang sipag at walang pagud na paggawa. Sila ay nagtratrabaho ng walang bayad para makapaghatid ng serbisyo sa inyo at hindi namin gusto na magtratrabaho ang sinuman ng libre. Karamihan sa aming grupo ay transgender at mga walang trabaho sa ngayon." p6header: "Bakit nakalista ang aking negosyo o organisasyon?" - p6: "Alamin ang higit pa sa aming Impormasyon tungkol sa aming ginagawa!" + p6: + text: "Alamin ang higit pa sa aming %{business_faq_variable}!" + business_faq: "Impormasyon tungkol sa aming ginagawa" contribute: 'I-fork mo kami at mag-ambag sa GitHub!' diff --git a/config/locales/fil/business_info.fil.yml b/config/locales/fil/business_info.fil.yml index e5315559..b1d8dcc0 100644 --- a/config/locales/fil/business_info.fil.yml +++ b/config/locales/fil/business_info.fil.yml @@ -2,7 +2,9 @@ fil: business_info: title: "Impormasyon tungkol sa ginagawa ng Refuge Restrooms" p1header: "1) Ano ang Refuge Restrooms?" - p1: "Ang REFUGE ay isang web application na naglalayong magbigay ng ligtas na akses sa banyo para sa mga transgender, intersex, at mga indibidwal na di-magkatulad na kasarian. Magbasa nang higit pa tungkol sa amin sa aming Tungkol sa Pahina." + p1: + text: "Ang REFUGE ay isang web application na naglalayong magbigay ng ligtas na akses sa banyo para sa mga transgender, intersex, at mga indibidwal na di-magkatulad na kasarian. Magbasa nang higit pa tungkol sa amin sa aming %{about_page_variable}." + about_page: "Tungkol sa Pahina" p2header: "2) Paano napalista ang aking pasilidad sa listahang ito?" p2: "Mayroong gumamit ang iyong banyo at isinumite ang iyong lokasyon bilang mapagkukunan. Ang lahat ng aming data ay isinumite ng iba't ibang taong mga gumagamit nito." p3header: "3) Paano ako magiging isang mahusay na host?" diff --git a/config/locales/fr/about.fr.yml b/config/locales/fr/about.fr.yml index c1f12fa9..f9e9b050 100644 --- a/config/locales/fr/about.fr.yml +++ b/config/locales/fr/about.fr.yml @@ -18,5 +18,7 @@ fr: third: "3. Si vous savez coder, visitez GitHub et informez-nous d'un bug, suggérez une amélioration, ou ajoutez un peu de code et aidez le projet. REFUGE est open source et nous ne pouvons pas le faire sans vous." fourth: "4. Faites un don. Gardez les yeux ouverts pour une campagne de crowdfunding à venir pour financer une partie de la technologie dont nous avons besoin et pour payer un peu nos fabuleux designers et développeurs pour leur travail acharné et inlassable. Ils ont travaillé gratuitement pour vous offrir ce service et nous pensons que tout travail mérite salaire. La plupart des membres de l'équipe de base sont transgenres et sous-employés en ce moment." p6header: "Pourquoi mon entreprise ou organisation est-elle répertoriée ?" - p6: "En savoir plus sur notre Business FAQ!" + p6: + text: "En savoir plus sur notre %{business_faq_variable}!" + business_faq: "Business FAQ" contribute: 'Contribuez sur GitHub!' diff --git a/config/locales/fr/business_info.yml b/config/locales/fr/business_info.yml index fe167139..d6530a3e 100644 --- a/config/locales/fr/business_info.yml +++ b/config/locales/fr/business_info.yml @@ -2,7 +2,9 @@ fr: business_info: title: "Questions fréquentes des organisations et entreprises à propos de Refuge Restrooms" p1header: "1) Qu'est ce que Refuge Restrooms ?" - p1: "REFUGE est une application web visant à fournir un accès sécurisé à des toilettes aux personnes transgenres, intersexuées et non conformes dans le genre. En lire plus à propos de nous sur notre page À Propos." + p1: + text: "REFUGE est une application web visant à fournir un accès sécurisé à des toilettes aux personnes transgenres, intersexuées et non conformes dans le genre. En lire plus à propos de nous sur notre %{about_page_variable}." + about_page: "page À Propos" p2header: "2) Comment mon établissement est-il entré dans cette liste ?" p2: "Quelqu'un a utilisé vos toilettes et voulait soumettre votre emplacement en tant que ressource. Toutes nos données sont fournies par l'utilisateur et soumises par l'utilisateur." p3header: "3) Comment puis-je être un bon hôte ?" diff --git a/config/locales/hi/about.hi.yml b/config/locales/hi/about.hi.yml index 48ab1d92..eef5eed9 100644 --- a/config/locales/hi/about.hi.yml +++ b/config/locales/hi/about.hi.yml @@ -18,5 +18,7 @@ hi: third: " तीसरा: यदि आप कोड करना जानते हैं, तो गिटहब (github) पर जाएं और हमें बग के बारे में बताएं, सुधार का सुझाव दें, या यहां तक ​​कि थोड़ा सा कोड भी योगदान दें और परियोजना की सहायता करें। रिफ्यूज खुला स्रोत है और हम आपके बिना यह नहीं कर सकते हैं। " fourth: " चौथा: दान करें। आने वाली फंडिंग अभियान के लिए अपनी आंखों को खुला रखे। व्यवस्था को चालू रखने के लिए हमे कुछ तकनीकों के प्रयोग के लिए धनराशि की आवशयकता हैं , उसके साथ-साथ हमारे शानदार डिजाइनरों और इंजीनियरों को थोड़ी सी धनराशि का भुगतान करे उनकी कड़ी और अथक म्हणत के लिए । वे इस सेवा को आपके पास लाने के लिए स्वतंत्र रूप से काम कर रहे हैं और हम नहीं चाहते कि कोई भी मुफ्त में काम करे। अधिकांश कोर टीम इस समय ट्रांसजेंडर और बेरोजगार हैं। " p6header: "मेरा व्यवसाय या संगठन क्यों सूचीबद्ध है?" - p6: "हमारे व्यवसाय पूछे जाने वाले प्रश्न पर और जानें!" + p6: + text: "हमारे %{business_faq_variable} पर और जानें!" + business_faq: "व्यवसाय पूछे जाने वाले प्रश्न" contribute: 'हमें फोर्क करें और गिटहब पर योगदान दें!' diff --git a/config/locales/hi/business_info.yml b/config/locales/hi/business_info.yml index 7b3efff0..464313b6 100644 --- a/config/locales/hi/business_info.yml +++ b/config/locales/hi/business_info.yml @@ -2,7 +2,9 @@ hi: business_info: title: "रेफ्यूज रेस्टरूम व्यापार जानकारी" p1header: "1) रेफ्यूज रेस्टरूम क्या हैं ?" - p1: "रेफ्यूज रेस्टरूम एक वेब एप्लिकेशन है जो ट्रांसजेंडर, इंटरसेक्स और लिंग गैर-अनुरूप व्यक्तियों के लिए सुरक्षित रेस्टरूम पहुंच प्रदान करना चाहता है। हमारे पृष्ठ पर हमारे बारे में और पढ़ें।" + p1: + text: "रेफ्यूज रेस्टरूम एक वेब एप्लिकेशन है जो ट्रांसजेंडर, इंटरसेक्स और लिंग गैर-अनुरूप व्यक्तियों के लिए सुरक्षित रेस्टरूम पहुंच प्रदान करना चाहता है। हमारे %{about_page_variable} पर हमारे बारे में और पढ़ें।" + about_page: "पृष्ठ" p2header: "2)इस सूची पर मेरी सुविधा कैसे मिली?" p2: "किसी ने आपके रेस्टरूम का इस्तेमाल किया और संसाधन के रूप में अपना स्थान जमा करना चाहता था। हमारा सभी डेटा उपयोगकर्ता द्वारा सबमिट किया गया है।" p3header: "3) मैं एक अच्छा मेजबान कैसे हो सकता हूं?" @@ -21,4 +23,3 @@ hi: p5: "समीक्षा आगंतुकों को स्थान के बारे में एक-दूसरे के साथ अनुभव साझा करने में मदद करती है। हम आगंतुकों के मानचित्र पर प्रत्येक स्थान के बारे में अधिक से अधिक जानकारी साझा करने के लिए प्रोत्साहित करते हैं।" p6header: "6) मैं अपनी लिस्टिंग कैसे हटा सकता हूं?" p6: "हमें उम्मीद है कि आप अपनी लिस्टिंग रखने पर विचार करेंगे; इसका मतलब लोगों के स्वास्थ्य और कल्याण के लिए बहुत मायने रख सकता है। हालांकि, अगर आप सूचीबद्ध नहीं होंगे, तो हटाने के अनुरोध के लिए हमारे संपर्क फ़ॉर्म का उपयोग करें और हमारे स्वयंसेवक इस पर काम करेंगे जैसे ही हम कर सकते हैं (यह एक ओपन सोर्स प्रोजेक्ट है इसलिए सभी काम स्वयंसेवकों द्वारा किया जाता है)।" - diff --git a/config/locales/it/about.it.yml b/config/locales/it/about.it.yml index fa72e1b2..392b7c07 100644 --- a/config/locales/it/about.it.yml +++ b/config/locales/it/about.it.yml @@ -18,5 +18,7 @@ it: third: "Tre: Se sai programmare, visita GitHub e facci sapere riguardo a bug, suggerimenti e miglioramenti, o contribuisci anche solo un po' al codice e aiuta il progetto. REFUGE è open source e non possiamo farlo senza di te." fourth: "Quattro: Fai una donazione. Tieni gli occhi aperti per la campagna di crowdfunding in arrivo per finanziare parte della tecnologia che necessitiamo di utilizzare così come per dare ai nostri favolosi designer e ingegneri un po' di soldi per il loro duro e instancabile lavoro. Hanno lavorato gratuitamente per portare a voi questo servizio e noi vogliamo che nessuno lavori gratuitamente. La maggior parte del team principale è transgender e sottoccupato al momento." p6header: "Perchè la mia attività o la mia organizzazione è in lista?" - p6: "Scopri di più sulla nostra FAQ commerciale!" + p6: + text: "Scopri di più sulla nostra %{business_faq_variable}!" + business_faq: "FAQ commerciale" contribute: 'Fai un fork e contribuisci su GitHub!' diff --git a/config/locales/it/business_info.yml b/config/locales/it/business_info.yml index 6be3627c..c40fe6ed 100644 --- a/config/locales/it/business_info.yml +++ b/config/locales/it/business_info.yml @@ -2,7 +2,9 @@ it: business_info: title: "Informazioni commerciali di Refuge Restrooms" p1header: "1) Cos'è Refuge Restrooms?" - p1: "REFUGE è una web application che punta a fornire l'accesso sicuro a servizi igienici per individui transgender, intersex, e genere non conforme. Leggi di più su di noi nulla nostra pagina About." + p1: + text: "REFUGE è una web application che punta a fornire l'accesso sicuro a servizi igienici per individui transgender, intersex, e genere non conforme. Leggi di più su di noi nulla nostra %{about_page_variable}." + about_page: "pagina About" p2header: "2) Come ha fatto la mia struttura a finire su questa lista?" p2: "Qualcuno ha usato i tuoi servizi igienici e ha voluto proporre la tua località come una risorsa. Tutti i nostri dati sono crowd-sourced e sottoposti dagli utenti." p3header: "3) Come posso essere un buon padrone di casa?" @@ -21,4 +23,3 @@ it: p5: "Le recensioni aiutano i visitatori a condividere le esperienze tra di loro riguardo al luovo. Noi incoraggiamo i visitatori a condividere quanto più informazioni hanno riguardo ogni località sulla mappa." p6header: "6) Come rimuovo il mio annuncio?" p6: "Speriamo che tu considererai di lasciare il tuo annuncio; può significare molto per la salute ed il benessere delle persone. Ad ogni modo, se preferisci non essere in lista, usa il nostro form di contatto per richiedere una rimozione e i nostri volontari la prenderanno in carico il prima possibile (questo è un progetto open source, quindi tutto il lavoro è fatto da volontari)." - diff --git a/config/locales/pl/about.pl.yml b/config/locales/pl/about.pl.yml index a83ba06e..cd85bcaf 100644 --- a/config/locales/pl/about.pl.yml +++ b/config/locales/pl/about.pl.yml @@ -18,5 +18,7 @@ pl: third: "Po trzecie: Jeżeli programujesz, zajrzyj na naszego GitHuba i poinformuj nas o napotkanych bugach, zasugeruj poprawki albo napisz własny kod aby wspomóc projekt. REFUGE jest open source i nie mogłoby istnieć bez pomocy współtwórców." fourth: "Po czwarte: Dokonaj wpłaty. Organizujemy zbiórki i kampanie crowdfundingowe, aby mieć za co kupować sprzęt i płacić twórcom aplikacji za ich pracę, aby nie była to już praca wolontariacka, jak początkowo. Większość twórców jest transpłciowa i obecnie zatrudniona poniżej kwalifikacji." p6header: "Dlaczego moja placówka znajduje się w bazie danych?" - p6: "Dowiedz się więcej w Business FAQ." - contribute: 'Zajrzyj na naszego GitHuba!' \ No newline at end of file + p6: + text: "Dowiedz się więcej w %{business_faq_variable}." + business_faq: "Business FAQ" + contribute: 'Zajrzyj na naszego GitHuba!' diff --git a/config/locales/pl/business_info.pl.yml b/config/locales/pl/business_info.pl.yml index 1779200d..d339a2e5 100644 --- a/config/locales/pl/business_info.pl.yml +++ b/config/locales/pl/business_info.pl.yml @@ -2,7 +2,9 @@ pl: business_info: title: "Refuge Restrooms Business Info" p1header: "1) Czym jest Refuge Restrooms?" - p1: "Refuge Restrooms to aplikacja ułatwiająca osobom transpłciowym i interpłciowym bezpieczny dostęp do łazienek publicznych. Przeczytaj więcej na tej stronie." + p1: + text: "Refuge Restrooms to aplikacja ułatwiająca osobom transpłciowym i interpłciowym bezpieczny dostęp do łazienek publicznych. Przeczytaj więcej %{about_page_variable}." + about_page: "na tej stronie" p2header: "2) Dlaczego moja placówka znajduje się w bazie danych?" p2: "Ktoś dodał lokalizację łazienki, aby poinformować o niej innych. Wszystkie zamieszczone lokalizacje są dodane przez użytkowników." p3header: "3) Jak mogę pomóc?" @@ -20,4 +22,4 @@ pl: p5header: "5) Co oznaczają recenzje?" p5: "Recenzje pomagają odwiedzającym dzielić się nawzajem doświadczeniami dotyczącymi placówki. Zachęcamy użytkowników do dzielenia się jak największą liczbą informacji odnośnie placówek i lokalizacji." p6header: "6) Jak mogę usunąć moją placówkę z bazy danych?" - p6: "Liczymy, że rozważysz pozostawienie placówki w bazie danych: może to mieć rzeczywisty wpływ na czyjeś zdrowie i bezpieczeństwo. Jeżeli jednak nie chcesz, by placówka widniała w aplikacji, skontaktuj się przez formularz kontaktowy, a nasi wolontariusze odpowiedzą Ci tak szybko, jak to możliwe (REFUGE to projekt open source i cała praca jest wykonywana przez wolontariuszy)." \ No newline at end of file + p6: "Liczymy, że rozważysz pozostawienie placówki w bazie danych: może to mieć rzeczywisty wpływ na czyjeś zdrowie i bezpieczeństwo. Jeżeli jednak nie chcesz, by placówka widniała w aplikacji, skontaktuj się przez formularz kontaktowy, a nasi wolontariusze odpowiedzą Ci tak szybko, jak to możliwe (REFUGE to projekt open source i cała praca jest wykonywana przez wolontariuszy)." diff --git a/config/locales/pt-BR/about.pt-BR.yml b/config/locales/pt-BR/about.pt-BR.yml index bea9e01f..6066c82a 100644 --- a/config/locales/pt-BR/about.pt-BR.yml +++ b/config/locales/pt-BR/about.pt-BR.yml @@ -18,5 +18,7 @@ pt-BR: third: "Terceiro: Se você sabe programar, visite o GitHub e informe um bug, sugira uma melhoria, o ainda contribua com um pouco de código e ajude o projeto. REFUGE é código aberto e não podemos fazê-lo sem você." fourth: "Quarto: Doe. Fique ligado em uma campanha futura de crowdfunding para financiar alguma tecnologia que precisamos usar e também pagar nossa equipe de design e engenharia com um pouco de dinheiro pelo seu trabalho árduo e incansável. Essas pessoas têm trabalhado de graça para trazer esse serviço para vocês e não queremos que ninguém trabalhe de graça. Muitas pessoas do time principal são transgêneras e com subempregos no momento." p6header: "Por que minha empresa ou organização está listada?" - p6: "Descubra mais no nosso FAQ para empresas!" + p6: + text: "Descubra mais no nosso %{business_faq_variable}!" + business_faq: "FAQ para empresas" contribute: 'Faça fork e contribua no GitHub!' diff --git a/config/locales/pt-BR/business_info.pt-BR.yml b/config/locales/pt-BR/business_info.pt-BR.yml index f93c815a..711151ba 100644 --- a/config/locales/pt-BR/business_info.pt-BR.yml +++ b/config/locales/pt-BR/business_info.pt-BR.yml @@ -2,7 +2,9 @@ pt-BR: business_info: title: "Refuge Restrooms - Informações para Empresas" p1header: "1) O que é Refuge Restrooms?" - p1: "REFUGE é uma aplicação web que busca fornecer acesso a banheiros seguros para indivíduos transgêneros, intersexo ou não-conformantes de gênero. Leia mais sobre nós na nossa página Sobre." + p1: + text: "REFUGE é uma aplicação web que busca fornecer acesso a banheiros seguros para indivíduos transgêneros, intersexo ou não-conformantes de gênero. Leia mais sobre nós na nossa página %{about_page_variable}." + about_page: "Sobre" p2header: "2) Como meu estabelecimento entrou nesta lista?" p2: "Alguém usou seu banheiro e quis cadastrar seu estabelecimento como recurso. Todos os nossos dados são fornecidos e cadastrados por usuários." p3header: "3) Como posso ser um bom anfitrião?" @@ -21,4 +23,3 @@ pt-BR: p5: "Avaliações ajudam visitantes a compartilhar experiências com outras pessoas sobre um lugar. Nós encorajamos visitantes a compartilhar o máximo de informações possível sobre cada lugar no mapa." p6header: "6) Como posso remover meu cadastro?" p6: "Nós esperamos que você considere manter seu cadastro; ele pode significar muito para a saúde e o bem estar das pessoas. No entanto, se você preferir não ser listado, use o nosso formulário de contato para requisitar a remoção e nosso voluntariado irá trabalhar nisso assim que possível (este é um projeto de código aberto, portanto nosso trabalho é feito voluntariamente)." - From 6be9580cc85b04e1ac2200802357d9b1bc3061dd Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Wed, 4 Nov 2020 18:46:23 -0500 Subject: [PATCH 13/14] Follow rubocop style for Ruby embedded in Haml Co-authored-by: Bruno Casali --- app/views/layouts/_footer.html.haml | 16 ++++++++-------- app/views/layouts/_navigation.html.haml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 2266faef..8bc32574 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -18,18 +18,18 @@ = "\© #{t('.copyleft')} #{Date.today.year} #{t('.refuge-restrooms')}".html_safe %br/ %br/ - = link_to 'English', request.query_parameters.merge({:locale => 'en'}), class: "locale_link" + = link_to 'English', request.query_parameters.merge(locale: 'en'), class: 'locale_link' • - = link_to 'Español', request.query_parameters.merge({:locale => 'es'}), class: "locale_link" + = link_to 'Español', request.query_parameters.merge(locale: 'es'), class: 'locale_link' • - = link_to 'Filipino/Tagalog', request.query_parameters.merge({:locale => 'fil'}), class: "locale_link" + = link_to 'Filipino/Tagalog', request.query_parameters.merge(locale: 'fil'), class: 'locale_link' • - = link_to 'Français', request.query_parameters.merge({:locale => 'fr'}), class: "locale_link" + = link_to 'Français', request.query_parameters.merge(locale: 'fr'), class: 'locale_link' • - = link_to 'हिन्दी', request.query_parameters.merge({:locale => 'hi'}), class: "locale_link" + = link_to 'हिन्दी', request.query_parameters.merge(locale: 'hi'), class: 'locale_link' • - = link_to 'Italiano', request.query_parameters.merge({:locale => 'it'}), class: "locale_link" + = link_to 'Italiano', request.query_parameters.merge(locale: 'it'), class: 'locale_link' • - = link_to 'polski', request.query_parameters.merge({:locale => 'pl'}), class: "locale_link" + = link_to 'polski', request.query_parameters.merge(locale: 'pl'), class: 'locale_link' • - = link_to 'Português do Brasil', request.query_parameters.merge({:locale => 'pt-BR'}), class: "locale_link" + = link_to 'Português do Brasil', request.query_parameters.merge(locale: 'pt-BR'), class: 'locale_link' diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 84a91d27..7d7a6695 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -4,7 +4,7 @@ %nav.nav.navbar-default{:role => "navigation"} / Brand and toggle get grouped for better mobile display .navbar-header - = link_to root_path, id: "logo", class: "toiletLogo" do + = link_to root_path, id: 'logo', class: 'toiletLogo' do .navbar-brand Refuge Restrooms %button.navbar-toggle{"data-target" => "#bs-example-navbar-collapse-1", "data-toggle" => "collapse", :type => "button"} %span.sr-only= t('.toggle-navigation-button-label') From 06854662e3b46fcc6f3c13779f32286e215feaeb Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 9 Mar 2021 19:03:41 -0300 Subject: [PATCH 14/14] Add a way to keep locale querystring when click on search (#657) * Create a LocaleService to centralize locale logic * Create a way to keep track of current_locale even between actions --- app/controllers/application_controller.rb | 17 ++++++--- app/services/locale_service.rb | 17 +++++++++ app/views/layouts/_search.html.haml | 1 + spec/features/restrooms_spec.rb | 40 +++++++++++++++++++++ spec/services/locale_service_spec.rb | 43 +++++++++++++++++++++++ 5 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 app/services/locale_service.rb create mode 100644 spec/services/locale_service_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 47c4d8c1..55aeeb66 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,13 +11,22 @@ def mobile_filter_header end def switch_locale(&action) - locale = params[:locale] || http_accept_language.language_region_compatible_from(I18n.available_locales) - locale ||= I18n.default_locale - - I18n.with_locale(locale, &action) + I18n.with_locale(current_locale, &action) end def default_url_options { locale: I18n.locale } end + + def current_locale + LocaleService.call(params[:locale], http_accept_locale) + end + + helper_method :current_locale + + private + + def http_accept_locale + http_accept_language.language_region_compatible_from(I18n.available_locales) + end end diff --git a/app/services/locale_service.rb b/app/services/locale_service.rb new file mode 100644 index 00000000..3163050f --- /dev/null +++ b/app/services/locale_service.rb @@ -0,0 +1,17 @@ +class LocaleService + def self.call(param_locale, browser_locale) + new(param_locale, browser_locale).perform + end + + def initialize(param_locale, browser_locale) + @param_locale = param_locale + @browser_locale = browser_locale + @default = I18n.default_locale + end + + def perform + return @param_locale if @param_locale.present? + + @browser_locale || @default + end +end diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index 95de084d..4f5b3aaa 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -4,6 +4,7 @@ = form_tag restrooms_path, class: "search-restrooms-form", method: :get do = hidden_field_tag :lat, "" = hidden_field_tag :long, "" + = hidden_field_tag :locale, current_locale .input-group = text_field_tag :search, params[:search], class: "form-control search-bar", aria: {label: t("search_bar.enter_location")} .input-group-btn diff --git a/spec/features/restrooms_spec.rb b/spec/features/restrooms_spec.rb index 6298be5c..e79d4fd8 100644 --- a/spec/features/restrooms_spec.rb +++ b/spec/features/restrooms_spec.rb @@ -86,6 +86,46 @@ # expect(page).to have_css('#mapArea.loaded') # expect(page).to have_css('#mapArea .numberCircleText') end + + context 'with browser accept language header' do + before { page.driver.headers = { 'ACCEPT-LANGUAGE' => 'es' } } + + it 'sets browser locale to the url after search' do + create(:restroom, :geocoded, name: 'Mission Creek Cafe') + + visit root_path + expect(page.current_url).not_to match(/locale=es/) + + fill_in 'search', with: 'San Francisco' + find('.submit-search-button').click + + expect(page).to have_content 'Mission Creek Cafe' + expect(page.current_url).to match(/locale=es/) + end + + it "translates page based on url not browser's" do + create(:restroom, :geocoded, name: 'Mission Creek Cafe') + + visit root_path(locale: 'pt-BR') + + expect(find('.submit-search-button').value).to eq('Buscar') + expect(page.current_url).to match(/locale=pt-BR/) + end + end + + context 'with locale in url' do + it 'sets new locale to the url after search' do + create(:restroom, :geocoded, name: 'Mission Creek Cafe') + + visit root_path(locale: :es) + + fill_in 'search', with: 'San Francisco' + find('.submit-search-button').click + + expect(page).to have_content 'Mission Creek Cafe' + expect(page.current_url).to match(/locale=es/) + end + end end describe 'preview' do diff --git a/spec/services/locale_service_spec.rb b/spec/services/locale_service_spec.rb new file mode 100644 index 00000000..343bf571 --- /dev/null +++ b/spec/services/locale_service_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +RSpec.describe LocaleService do + before { allow(I18n).to receive(:default_locale).and_return('fr') } + + describe '.call' do + subject(:service) { described_class.call(param_locale, http_locale) } + + let(:param_locale) { nil } + let(:http_locale) { nil } + + context 'when @param_locale is valid' do + let(:param_locale) { 'pt-BR' } + + it 'responds with @locale' do + expect(service).to eq('pt-BR') + end + end + + context 'when @param_locale is nil' do + let(:http_locale) { 'es' } + + it 'responds with @http_locale' do + expect(service).to eq('es') + end + end + + context 'when @param_locale is blank' do + let(:param_locale) { ' ' } + let(:http_locale) { 'en' } + + it 'responds with @http_locale' do + expect(service).to eq('en') + end + end + + context 'when both @param_locale and @http_locale is nil' do + it 'responds with I18n.default_locale' do + expect(service).to eq('fr') + end + end + end +end