diff --git a/app/controllers/admin/site_customization/pages_controller.rb b/app/controllers/admin/site_customization/pages_controller.rb
index 4d92a6a1e..dd65fb52e 100644
--- a/app/controllers/admin/site_customization/pages_controller.rb
+++ b/app/controllers/admin/site_customization/pages_controller.rb
@@ -38,7 +38,8 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
:content,
:more_info_flag,
:print_content_flag,
- :status
+ :status,
+ :locale
)
end
end
diff --git a/app/helpers/locales_helper.rb b/app/helpers/locales_helper.rb
index 717be9e9b..78ab25189 100644
--- a/app/helpers/locales_helper.rb
+++ b/app/helpers/locales_helper.rb
@@ -3,6 +3,8 @@ module LocalesHelper
def name_for_locale(locale)
default = I18n.t("locale", locale: locale)
I18n.backend.translate(locale, "i18n.language.name", default: default)
+ rescue
+ nil
end
-end
\ No newline at end of file
+end
diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb
index c2a9b1467..2b60dea81 100644
--- a/app/models/site_customization/page.rb
+++ b/app/models/site_customization/page.rb
@@ -6,9 +6,11 @@ class SiteCustomization::Page < ActiveRecord::Base
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
validates :title, presence: true
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
+ validates :locale, presence: true
scope :published, -> { where(status: 'published').order('id DESC') }
scope :with_more_info_flag, -> { where(status: 'published', more_info_flag: true).order('id ASC') }
+ scope :with_same_locale, -> { where(locale: I18n.locale).order('id ASC') }
def url
"/#{slug}"
diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb
index 2c0d38ba6..a8c2788b3 100644
--- a/app/views/admin/site_customization/pages/_form.html.erb
+++ b/app/views/admin/site_customization/pages/_form.html.erb
@@ -30,6 +30,10 @@
<% end %>
+
+ <%= f.label :locale %>
+ <%= f.select :locale, I18n.available_locales.map { |l| [name_for_locale(l), l.to_s] }, { include_blank: true, label: false } %>
+
<%= f.label :slug %>
<%= f.text_field :slug, label: false, size: 80, maxlength: 80 %>
diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb
index 18ba5a9b7..dd9cfd3ad 100644
--- a/app/views/admin/site_customization/pages/index.html.erb
+++ b/app/views/admin/site_customization/pages/index.html.erb
@@ -15,6 +15,7 @@
<%= t("admin.site_customization.pages.page.created_at") %> |
<%= t("admin.site_customization.pages.page.updated_at") %> |
<%= t("admin.site_customization.pages.page.status") %> |
+
<%= t("admin.site_customization.pages.page.locale") %> |
<%= t("admin.actions.actions") %> |
@@ -27,6 +28,7 @@
<%= I18n.l page.created_at, format: :short %> |
<%= I18n.l page.created_at, format: :short %> |
<%= t("admin.site_customization.pages.page.status_#{page.status}") %> |
+
<%= name_for_locale(page.locale) %> |
<% if page.status == "published" %>
diff --git a/app/views/pages/more_info/_other.html.erb b/app/views/pages/more_info/_other.html.erb
index c33f17fd6..5ed1b9f4e 100644
--- a/app/views/pages/more_info/_other.html.erb
+++ b/app/views/pages/more_info/_other.html.erb
@@ -3,7 +3,7 @@
- <%= link_to t("pages.more_info.other.how_to_use", org_name: setting['org_name']), how_to_use_path %>
- <% SiteCustomization::Page.with_more_info_flag.each do |custom_page| %>
+ <% SiteCustomization::Page.with_more_info_flag.with_same_locale.each do |custom_page| %>
- <%= link_to custom_page.title, page_path(custom_page.slug) %>
<% end %>
diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml
index d45c569d4..06ce24fd6 100644
--- a/config/locales/activerecord.en.yml
+++ b/config/locales/activerecord.en.yml
@@ -164,6 +164,7 @@ en:
updated_at: Updated at
more_info_flag: Show in more information page
print_content_flag: Print content button
+ locale: Language
site_customization/image:
name: Name
image: Image
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml
index 678053f84..d00b4ab88 100644
--- a/config/locales/activerecord.es.yml
+++ b/config/locales/activerecord.es.yml
@@ -159,6 +159,7 @@ es:
updated_at: última actualización
more_info_flag: Mostrar en la página de más información
print_content_flag: Botón de imprimir contenido
+ locale: Idioma
site_customization/image:
name: Nombre
image: Imagen
diff --git a/config/locales/activerecord.fr.yml b/config/locales/activerecord.fr.yml
index b977176ce..b588d37dc 100644
--- a/config/locales/activerecord.fr.yml
+++ b/config/locales/activerecord.fr.yml
@@ -139,6 +139,7 @@ fr:
updated_at: Mis-à-jour le
more_info_flag: Montrer dans la page Plus d'informations
print_content_flag: Bouton impression du contenu
+ locale: Langue
site_customization/image:
name: Nom
image: Image
diff --git a/config/locales/activerecord.nl.yml b/config/locales/activerecord.nl.yml
index 5e930ac65..1c8eee00e 100644
--- a/config/locales/activerecord.nl.yml
+++ b/config/locales/activerecord.nl.yml
@@ -135,7 +135,8 @@ nl:
title: Titel
updated_at: Bijgewerkt op
more_info_flag: Toon in extra informatie pagina
- print_content_flag: Print inhoud
+ print_content_flag: Print inhoud
+ locale: Taal
site_customization/image:
name: Naam
image: Beeld
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 437638d84..999689492 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -934,3 +934,4 @@ en:
updated_at: Updated at
status_draft: Draft
status_published: Published
+ locale: Language
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 39c6878fe..c77a95062 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -934,3 +934,4 @@ es:
updated_at: Última actualización
status_draft: Borrador
status_published: Publicada
+ locale: Idioma
diff --git a/config/locales/admin.fr.yml b/config/locales/admin.fr.yml
index 76bd7655d..0044a276f 100644
--- a/config/locales/admin.fr.yml
+++ b/config/locales/admin.fr.yml
@@ -740,3 +740,4 @@ fr:
updated_at: Mis-à-jour le
status_draft: Brouillon
status_published: Publié
+ locale: Langue
diff --git a/config/locales/admin.nl.yml b/config/locales/admin.nl.yml
index e18087e60..a359aebbe 100755
--- a/config/locales/admin.nl.yml
+++ b/config/locales/admin.nl.yml
@@ -737,3 +737,4 @@ nl:
updated_at: Updated at
status_draft: Draft
status_published: Published
+ locale: Taal
diff --git a/db/migrate/20170702105956_add_locale_to_site_customization_pages.rb b/db/migrate/20170702105956_add_locale_to_site_customization_pages.rb
new file mode 100644
index 000000000..2675d9fa7
--- /dev/null
+++ b/db/migrate/20170702105956_add_locale_to_site_customization_pages.rb
@@ -0,0 +1,5 @@
+class AddLocaleToSiteCustomizationPages < ActiveRecord::Migration
+ def change
+ add_column :site_customization_pages, :locale, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 48fc9accb..cb9a015e9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -795,6 +795,7 @@ ActiveRecord::Schema.define(version: 20170703120055) do
t.string "status", default: "draft"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.string "locale"
end
create_table "spending_proposals", force: :cascade do |t|
diff --git a/spec/factories.rb b/spec/factories.rb
index aafc4d82a..31ba2cec0 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -742,6 +742,7 @@ LOREM_IPSUM
more_info_flag false
print_content_flag false
status 'draft'
+ locale 'en'
trait :published do
status "published"
diff --git a/spec/features/admin/site_customization/pages_spec.rb b/spec/features/admin/site_customization/pages_spec.rb
index 3e940ea69..1b09a8f01 100644
--- a/spec/features/admin/site_customization/pages_spec.rb
+++ b/spec/features/admin/site_customization/pages_spec.rb
@@ -30,6 +30,7 @@ feature "Admin custom pages" do
fill_in "site_customization_page_subtitle", with: "Page subtitle"
fill_in "site_customization_page_slug", with: "example-page"
fill_in "site_customization_page_content", with: "This page is about..."
+ select 'English', from:"site_customization_page_locale"
click_button "Create Custom page"
diff --git a/spec/features/site_customization/custom_pages_spec.rb b/spec/features/site_customization/custom_pages_spec.rb
index 2e2fac84a..653f783cd 100644
--- a/spec/features/site_customization/custom_pages_spec.rb
+++ b/spec/features/site_customization/custom_pages_spec.rb
@@ -7,7 +7,8 @@ feature "Custom Pages" do
slug: "conditions",
title: "Custom conditions",
content: "New text for conditions page",
- print_content_flag: true
+ print_content_flag: true,
+ locale: "en"
)
visit custom_page.url
@@ -23,7 +24,8 @@ feature "Custom Pages" do
slug: "conditions",
title: "Custom conditions",
content: "New text for conditions page",
- print_content_flag: true
+ print_content_flag: true,
+ locale: "en"
)
visit custom_page.url
@@ -42,7 +44,8 @@ feature "Custom Pages" do
slug: "other-slug",
title: "Custom page",
content: "Text for new custom page",
- print_content_flag: false
+ print_content_flag: false,
+ locale: "en"
)
visit custom_page.url
@@ -57,7 +60,8 @@ feature "Custom Pages" do
slug: "other-slug",
title: "Custom page",
content: "Text for new custom page",
- print_content_flag: false
+ print_content_flag: false,
+ locale: "en"
)
visit custom_page.url
@@ -72,7 +76,8 @@ feature "Custom Pages" do
custom_page = create(:site_customization_page, :published,
slug: "another-slug", title: "Another custom page",
subtitle: "Subtitle for custom page",
- more_info_flag: true
+ more_info_flag: true,
+ locale: "en"
)
visit more_info_path
@@ -84,7 +89,8 @@ feature "Custom Pages" do
custom_page = create(:site_customization_page, :published,
slug: "another-slug", title: "Another custom page",
subtitle: "Subtitle for custom page",
- more_info_flag: false
+ more_info_flag: false,
+ locale: "en"
)
visit more_info_path
@@ -97,6 +103,25 @@ feature "Custom Pages" do
expect(page).to have_selector("h1", text: "Another custom page")
expect(page).to have_content("Subtitle for custom page")
end
+
+ scenario "Not listed in more information page due to different locale" do
+ custom_page = create(:site_customization_page, :published,
+ slug: "another-slug", title: "Ce texte est en français",
+ subtitle: "Subtitle for custom page",
+ more_info_flag: false,
+ locale: "fr"
+ )
+
+ visit more_info_path
+
+ expect(page).to_not have_content("Ce texte est en français")
+
+ visit custom_page.url
+
+ expect(page).to have_title("Ce texte est en français")
+ expect(page).to have_selector("h1", text: "Ce texte est en français")
+ expect(page).to have_content("Subtitle for custom page")
+ end
end
end
end
|