Skip to content

Commit

Permalink
Multilingual organization name (decidim#12681)
Browse files Browse the repository at this point in the history
* Initial commit

* More mailers fixed

* Fix more specs

* Lint

* Fix more specs

* refactor

* Fix Specs

* Fix specs

* Fix more specs

* Fix specs

* lint

* Remove helper methods

* Add organization uniqueness validator

* mark name as translattable

* Fix more specs

* Fix specs

* Running lint

* Fix specs

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* use current_organization_name helper

* Fis current_organization_name usage

* Apply review recommendations

* Update decidim-core/db/migrate/20240401192628_change_name_on_decidim_organizations.rb

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Apply review recommendation

* Apply review recommendations

* Lint

* Fix specs

* Update decidim-system/app/forms/decidim/system/update_organization_form.rb

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Fix failing specs

* Fix edge case when Organization name is empty in update

* Fix edge case

---------

Co-authored-by: Andrés Pereira de Lucena <[email protected]>
  • Loading branch information
alecslupu and andreslucena authored May 21, 2024
1 parent 8afa643 commit cb466cb
Show file tree
Hide file tree
Showing 146 changed files with 662 additions and 351 deletions.
4 changes: 2 additions & 2 deletions decidim-admin/app/forms/decidim/admin/organization_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class OrganizationForm < Form

mimic :organization

attribute :name, String
translatable_attribute :name, String
attribute :reference_prefix, String
attribute :time_zone, String
attribute :twitter_handler, String
Expand All @@ -37,7 +37,7 @@ class OrganizationForm < Form

validates :welcome_notification_subject, :welcome_notification_body, translatable_presence: true, if: proc { |form| form.customize_welcome_notification }

validates :name, presence: true
validates :name, translatable_presence: true
validates :time_zone, presence: true
validates :time_zone, time_zone: true
validates :default_locale, :reference_prefix, presence: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def reportable_author_name(reportable)
decidim_sanitize_translated(author.title)
end
end
when Decidim::Organization
content_tag :li, organization_name(author)
else
content_tag(:li, author.name)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t "decidim.admin.titles.dashboard" %> <%= current_organization.name %>
<%= t "decidim.admin.titles.dashboard" %> <%= current_organization_name %>
</h1>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card-section">
<div class="row column">
<div class="columns">
<%= form.text_field :name %>
<%= form.translated :text_field, :name %>
</div>

<div class="columns">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% add_decidim_page_title(t("titles.panel", scope: "decidim.admin")) %>
<% add_decidim_page_title(current_organization.name) %>
<% add_decidim_page_title(current_organization_name) %>
<!doctype html>
<html class="no-js" lang="<%= I18n.locale %>" dir="<%= rtl_direction %>">
<head>
Expand All @@ -21,9 +21,9 @@
</div>
<div class="relative md:flex grow min-h-max w-full">
<div class="layout-nav">
<%= link_to decidim_admin.root_path, class: "logo hidden md:block", data: { "external-link": false }, aria: { label: t("decidim.accessibility.logo", organization: current_organization.name) } do %>
<%= link_to decidim_admin.root_path, class: "logo hidden md:block", data: { "external-link": false }, aria: { label: t("decidim.accessibility.logo", organization: current_organization_name) } do %>
<% if current_organization.logo.present? %>
<%= image_tag current_organization.attached_uploader(:logo).path, alt: current_organization.name %>
<%= image_tag current_organization.attached_uploader(:logo).path, alt: current_organization_name %>
<% else %>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 134 109">
<g fill="#fff">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="title-bar">
<div class="layout-content__container">
<span class="font-semibold text-sm">
<%= current_organization.name %>
<%= current_organization_name %>
</span>
<div class="tool-bar">
<%= link_to decidim.root_path, class: "button__site", target: "_blank", data: { "external-link": false } do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="layout-content__container">
<a href="#menu" class="menu-trigger"><%= icon "menu-line", class: "fill-black" %></a>
<span class="font-semibold text-sm">
<%= current_organization.name %>
<%= current_organization_name %>
</span>
<div class="tool-bar">
<%= link_to decidim.root_path, class: "button__site", target: "_blank", data: { "external-link": false } do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Decidim::Admin
let(:params) do
{
organization: {
name: "My super organization",
name: { en: "My super organization" },
reference_prefix: "MSO",
time_zone: "Hawaii",
default_locale: "en",
Expand Down Expand Up @@ -48,7 +48,7 @@ module Decidim::Admin
command.call
organization.reload

expect(organization.name).not_to eq("My super organization")
expect(translated(organization.name)).not_to eq("My super organization")
end
end

Expand All @@ -74,7 +74,7 @@ module Decidim::Admin
expect { command.call }.to broadcast(:ok)
organization.reload

expect(organization.name).to eq("My super organization")
expect(translated(organization.name)).to eq("My super organization")
expect(organization.rich_text_editor_in_public_views).to be(true)
expect(organization.enable_machine_translations).to be(true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Admin
)
end

let(:name) { "My super organization" }
let(:name) { { ca: "", en: "My super organization", es: "" } }
let(:reference_prefix) { "MSO" }
let(:time_zone) { "UTC" }
let(:twitter_handler) { "My twitter awesome handler" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="content">
<div class="version">Decidim <%= Decidim.version %></div>

<h1><%= current_organization.name %> API documentation</h1>
<h1><%= current_organization_name %> API documentation</h1>
<% if defined?(graphiql_path) %>
<%= link_to "Explore the API interactively with GraphiQL", graphiql_path %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title><%= current_organization.name %> - API Documentation</title>
<title><%= current_organization_name %> - API Documentation</title>
<%= stylesheet_pack_tag("decidim_api_docs") %>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion decidim-api/spec/system/documentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
visit decidim_api.documentation_path

within "h1" do
expect(page).to have_content(organization.name)
expect(page).to have_content(translated(organization.name))
end
expect(page).to have_content("About the GraphQL API")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def post_description_admin(post, max_length = 100)

def post_author_select_field(form, name, _options = {})
select_options = [
[current_organization.name, ""],
[current_organization_name, ""],
[current_user.name, current_user.id]
]
current_user_groups = Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= decidim_sanitize_editor post_description_admin(post) %>
</td>
<td>
<%= post.try(:author).try(:name) %>
<%= translated_attribute(post.try(:author).try(:name)) %>
</td>
<% publish_data = publish_data(post.published_at) %>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ module Decidim::Blogs::Admin

let(:all_fields) do
[
[organization.name, ""],
[translated(organization.name), ""],
[user.name, user.id],
[user_group.name, user_group.id]
]
end

let(:extra_user_fields) do
[
[organization.name, ""],
[translated(organization.name), ""],
[user.name, user.id],
[user_group.name, user_group.id],
[another_user.name, another_user.id]
Expand All @@ -37,7 +37,7 @@ module Decidim::Blogs::Admin

let(:extra_group_fields) do
[
[organization.name, ""],
[translated(organization.name), ""],
[user.name, user.id],
[user_group.name, user_group.id],
[another_user_group.name, another_user_group.id]
Expand All @@ -46,7 +46,7 @@ module Decidim::Blogs::Admin

let(:basic_fields) do
[
[organization.name, ""],
[translated(organization.name), ""],
[user.name, user.id]
]
end
Expand Down
12 changes: 6 additions & 6 deletions decidim-blogs/spec/shared/manage_posts_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

within ".edit_post" do
expect(page).to have_select("post_decidim_author_id", selected: author.name)
expect(page).to have_select("post_decidim_author_id", selected: translated(author.name))

fill_in_i18n(
:post_title,
Expand All @@ -40,7 +40,7 @@
within "table" do
expect(page).to have_content("My new title")
expect(page).to have_content("Post title 2")
expect(page).to have_content(author.name)
expect(page).to have_content(translated(author.name))
end
end

Expand Down Expand Up @@ -158,7 +158,7 @@
it "can set organization as posts author" do
click_on "New post"

select organization.name, from: "post_decidim_author_id"
select translated(organization.name), from: "post_decidim_author_id"

fill_in_i18n(
:post_title,
Expand All @@ -183,7 +183,7 @@
expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content(author.name)
expect(page).to have_content(translated(organization.name))
expect(page).to have_content("My post")
expect(page).to have_content("Post title 1")
expect(page).to have_content("Post title 2")
Expand All @@ -196,14 +196,14 @@
end

within ".edit_post" do
select organization.name, from: "post_decidim_author_id"
select translated(organization.name), from: "post_decidim_author_id"
find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "tr", text: translated(post1.title) do
expect(page).to have_content(author.name)
expect(page).to have_content(translated(organization.name))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-blogs/spec/system/explore_posts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
it "show post info" do
expect(page).to have_i18n_content(post.title)
expect(page).to have_i18n_content(post.body)
expect(page).to have_content(post.author.name)
expect(page).to have_content(translated(post.author.name))
expect(page).to have_content(post.created_at.strftime("%d/%m/%Y %H:%M"))
end

Expand Down
6 changes: 3 additions & 3 deletions decidim-blogs/spec/types/integration_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"id" => endo.author.id.to_s,
"name" => endo.author.name,
"nickname" => "@#{endo.author.nickname}",
"organizationName" => endo.author.organization.name,
"organizationName" => { "translation" => translated(endo.author.organization.name) },
"profilePath" => "/profiles/#{endo.author.nickname}"
}
end,
Expand Down Expand Up @@ -98,7 +98,7 @@
deleted
name
nickname
organizationName
organizationName { translation(locale:"#{locale}") }
profilePath
__typename
}
Expand Down Expand Up @@ -278,7 +278,7 @@
deleted
name
nickname
organizationName
organizationName { translation(locale:"#{locale}") }
profilePath
__typename
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Decidim::Budgets
end

it "includes the organization data" do
expect(mail.body.encoded).to include(user.organization.name)
expect(mail.body.encoded).to include(translated(user.organization.name))
end

it "includes the budget title" do
Expand Down
2 changes: 1 addition & 1 deletion decidim-budgets/spec/system/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@

expect(page).to have_content "€25,000,000"

page.find("header a", text: organization.name).click
page.find("header a", text: translated(organization.name)).click

expect(page).to have_content "You have not yet voted"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", email: @user.name) %></p>

<p class="email-instructions">
<%= t ".invited_existing_user_to_join_a_conference", invited_by: @invited_by.name, application: @user.organization.name %>
<%= t ".invited_existing_user_to_join_a_conference", invited_by: @invited_by.name, application: organization_name(@user.organization) %>
</p>

<p class="email-button email-button__cta cta-decline">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p class="email-greeting"><%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %></p>

<p class="email-instructions">
<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: organization_name(@user.organization)) %>
</p>

<p class="email-button email-button__cta"><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:conference]).conference_registration_type_conference_registration_path(conference_slug: @opts[:conference], registration_type_id: @opts[:registration_type]), host: @resource.organization.host) %></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= t("devise.mailer.invitation_instructions.hello", email: @resource.name) %>

<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_existing_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: @resource.organization.name) %>
<%= t("decidim.conferences.admin.invite_join_conference_mailer.invite.invited_existing_user_to_join_a_conference", invited_by: @resource.invited_by.name, application: organization_name(@user.organization)) %>

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token, invite_redirect: Decidim::EngineRouter.main_proxy(@opts[:conference]).conference_registration_type_conference_registration_path(conference_slug: @opts[:conference], registration_type_id: @opts[:registration_type]), host: @resource.organization.host) %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section id="footer_sub_hero" class="home__section text-center">
<div class="flex justify-center mb-12">
<h2 class="title-decorator">
<%= t("decidim.pages.home.footer_sub_hero.footer_sub_hero_headline", organization: current_organization.name) %>
<%= t("decidim.pages.home.footer_sub_hero.footer_sub_hero_headline", organization: current_organization_name) %>
</h2>
</div>
<p class="text-lg text-gray-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="hero">
<h1 class="hero__title">
<% if translated_welcome_text.blank? %>
<%= t("decidim.pages.home.hero.welcome", organization: current_organization.name) %>
<%= t("decidim.pages.home.hero.welcome", organization: current_organization_name) %>
<% else %>
<%= decidim_sanitize_admin translated_welcome_text %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</div>
</div>
<%= link_to decidim.pages_path, class: "button button__sm md:button__lg button__secondary mt-6" do %>
<%= t("more_info", scope: "decidim.pages.home.extended", resource_name: translated_attribute(current_organization.name, current_organization)) %>
<%= t("more_info", scope: "decidim.pages.home.extended", resource_name: current_organization_name) %>
<%= icon "arrow-right-line", class: "fill-current" %>
<% end %>
</section>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section id="statistics" class="home__section home__section-content-block">
<h2 class="home__section-title mb-8">
<%= t("decidim.pages.home.statistics.headline", organization: current_organization.name) %>
<%= t("decidim.pages.home.statistics.headline", organization: current_organization_name) %>
</h2>

<%= cell("decidim/statistics", stats.highlighted + stats.not_highlighted) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
<th class="small-12 first columns cityhall-bar">
<div class="decidim-logo" style="float: right; text-align: right; padding-right: 16px">
<% if custom_url_for_mail_root.present? %>
<%= link_to organization.name.html_safe, custom_url_for_mail_root %>
<%= link_to organization_name(organization).html_safe, custom_url_for_mail_root %>
<% else %>
<%= link_to organization.name.html_safe, decidim.root_url(host: organization.host) %>
<%= link_to organization_name(organization).html_safe, decidim.root_url(host: organization.host) %>
<% end %>
</div>
</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ table.button table td {
<th class="small-12 first columns cityhall-bar">
<div class="decidim-logo" style="float: right; text-align: right; padding-right: 16px">
<% if custom_url_for_mail_root.present? %>
<%= link_to organization.name.html_safe, custom_url_for_mail_root %>
<%= link_to organization_name(organization).html_safe, custom_url_for_mail_root %>
<% else %>
<%= link_to organization.name.html_safe, decidim.root_url(host: organization.host) %>
<%= link_to organization_name(organization).html_safe, decidim.root_url(host: organization.host) %>
<% end %>
</div>
</th>
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/pad_iframe/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
src="<%= iframe_url %>"
style="border: solid 4px #fff; border-radius: 4px; box-shadow: 0 0 0 1px #e8e8e8; width: 100%; height: 600px">
</iframe>
<p><%= t("decidim.pad_iframe.disclaimer", organization: current_organization.name) %></p>
<p><%= t("decidim.pad_iframe.disclaimer", organization: current_organization_name) %></p>
</div>
</div>
</div>
Loading

0 comments on commit cb466cb

Please sign in to comment.