Merge pull request #1716 from MariaCheca/1647-locale_site_customization
Locale site customization
This commit is contained in:
@@ -38,7 +38,8 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
|
||||
:content,
|
||||
:more_info_flag,
|
||||
:print_content_flag,
|
||||
:status
|
||||
:status,
|
||||
:locale
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
end
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
<br>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :locale %>
|
||||
<%= f.select :locale, I18n.available_locales.map { |l| [name_for_locale(l), l.to_s] }, { include_blank: true, label: false } %>
|
||||
</div>
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :slug %>
|
||||
<%= f.text_field :slug, label: false, size: 80, maxlength: 80 %>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<th><%= t("admin.site_customization.pages.page.created_at") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.updated_at") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.status") %></th>
|
||||
<th><%= t("admin.site_customization.pages.page.locale") %></th>
|
||||
<th colspan="2"><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -27,6 +28,7 @@
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
|
||||
<td><%= name_for_locale(page.locale) %></td>
|
||||
<td class="small">
|
||||
<span class="icon-eye"></span>
|
||||
<% if page.status == "published" %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<ul class="features">
|
||||
<li><%= link_to t("pages.more_info.other.how_to_use", org_name: setting['org_name']), how_to_use_path %></li>
|
||||
|
||||
<% SiteCustomization::Page.with_more_info_flag.each do |custom_page| %>
|
||||
<% SiteCustomization::Page.with_more_info_flag.with_same_locale.each do |custom_page| %>
|
||||
<li><%= link_to custom_page.title, page_path(custom_page.slug) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -934,3 +934,4 @@ en:
|
||||
updated_at: Updated at
|
||||
status_draft: Draft
|
||||
status_published: Published
|
||||
locale: Language
|
||||
|
||||
@@ -934,3 +934,4 @@ es:
|
||||
updated_at: Última actualización
|
||||
status_draft: Borrador
|
||||
status_published: Publicada
|
||||
locale: Idioma
|
||||
|
||||
@@ -740,3 +740,4 @@ fr:
|
||||
updated_at: Mis-à-jour le
|
||||
status_draft: Brouillon
|
||||
status_published: Publié
|
||||
locale: Langue
|
||||
|
||||
@@ -737,3 +737,4 @@ nl:
|
||||
updated_at: Updated at
|
||||
status_draft: Draft
|
||||
status_published: Published
|
||||
locale: Taal
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddLocaleToSiteCustomizationPages < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :site_customization_pages, :locale, :string
|
||||
end
|
||||
end
|
||||
@@ -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|
|
||||
|
||||
@@ -742,6 +742,7 @@ LOREM_IPSUM
|
||||
more_info_flag false
|
||||
print_content_flag false
|
||||
status 'draft'
|
||||
locale 'en'
|
||||
|
||||
trait :published do
|
||||
status "published"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user