Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Change target parameter of link_translate to boolean

Jan Sandbrink0fe8b5ba2b3d
diff --git a/app/forms/scim_clients/form.rb b/app/forms/scim_clients/form.rb
index f6838c15378..f88d77f5194 100644
--- a/app/forms/scim_clients/form.rb
+++ b/app/forms/scim_clients/form.rb
@@ -81,9 +81,9 @@ module ScimClients
name: :jwt_sub,
label: ScimClient.human_attribute_name(:jwt_sub),
required: true,
- caption: link_translate("admin.scim_clients.form.jwt_sub_description", links: {
- docs_url: ::OpenProject::Static::Links.url_for(:sysadmin_docs, :scim_jwt_authetication_method)
- }),
+ caption: link_translate("admin.scim_clients.form.jwt_sub_description",
+ links: { docs_url: %i[sysadmin_docs scim_jwt_authetication_method] },
+ external: true),
input_width: :large
)
end
diff --git a/app/forms/work_package_types/subject_configuration_form.rb b/app/forms/work_package_types/subject_configuration_form.rb
index 724652dc39a..3a52424443e 100644
--- a/app/forms/work_package_types/subject_configuration_form.rb
+++ b/app/forms/work_package_types/subject_configuration_form.rb
@@ -87,7 +87,7 @@ module WorkPackageTypes
def pattern_input_caption
link_translate("types.edit.subject_configuration.pattern.caption", links: {
- attributes_url: ::OpenProject::Static::Links.url_for(:enterprise_features, :work_package_subject_generation)
+ attributes_url: %i[enterprise_features work_package_subject_generation]
})
end
end
diff --git a/app/views/admin/scim_clients/edit.html.erb b/app/views/admin/scim_clients/edit.html.erb
index d5d3153c94e..378ffbbdae0 100644
--- a/app/views/admin/scim_clients/edit.html.erb
+++ b/app/views/admin/scim_clients/edit.html.erb
@@ -33,9 +33,7 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { @scim_client.name }
header.with_description do
- link_translate("admin.scim_clients.form.description", links: {
- docs_url: ::OpenProject::Static::Links.url_for(:sysadmin_docs, :scim)
- })
+ link_translate("admin.scim_clients.form.description", links: { docs_url: %i[sysadmin_docs scim] }, external: true)
end
header.with_breadcrumbs(
[{ href: admin_index_path, text: t(:label_administration) },
diff --git a/app/views/admin/scim_clients/new.html.erb b/app/views/admin/scim_clients/new.html.erb
index 1f1e212eac4..5605e3025fa 100644
--- a/app/views/admin/scim_clients/new.html.erb
+++ b/app/views/admin/scim_clients/new.html.erb
@@ -33,9 +33,7 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(".title") }
header.with_description do
- link_translate("admin.scim_clients.form.description", links: {
- docs_url: ::OpenProject::Static::Links.url_for(:sysadmin_docs, :scim)
- })
+ link_translate("admin.scim_clients.form.description", links: { docs_url: %i[sysadmin_docs scim] }, external: true)
end
header.with_breadcrumbs(
[{ href: admin_index_path, text: t(:label_administration) },
diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rb
index 3cef0e4e84b..6291495e0b8 100644
--- a/lib_static/redmine/i18n.rb
+++ b/lib_static/redmine/i18n.rb
@@ -111,9 +111,9 @@ module Redmine
#
# @param i18n_key [String] The I18n key to translate.
# @param links [Hash] Link names mapped to URLs.
- # @param target [String] optional HTML target attribute for the links.
+ # @param external [Boolean] Whether the links should be opened as external links, i.e. in a new tab (default: false)
# @param underline [Boolean] Whether to underline links inserted into the text (default: true)
- def link_translate(i18n_key, links: {}, locale: ::I18n.locale, target: nil, underline: true)
+ def link_translate(i18n_key, links: {}, locale: ::I18n.locale, external: false, underline: true)
translation = ::I18n.t(i18n_key.to_s, locale:)
result = translation.scan(link_regex).inject(translation) do |t, matches|
link, text, key = matches
@@ -124,7 +124,11 @@ module Redmine
else
String(link_reference)
end
- link_tag = render(Primer::Beta::Link.new(href:, target:, underline:)) { text }
+ target = external ? "_blank" : nil
+ link_tag = render(Primer::Beta::Link.new(href:, target:, underline:)) do |l|
+ l.with_trailing_visual_icon(icon: :"link-external") if external
+ text
+ end
t.sub(link, link_tag)
end
diff --git a/lookbook/docs/patterns/04-links.md.erb b/lookbook/docs/patterns/04-links.md.erb
index 461cde25a66..819f9e93c2a 100644
--- a/lookbook/docs/patterns/04-links.md.erb
+++ b/lookbook/docs/patterns/04-links.md.erb
@@ -22,3 +22,7 @@ Links that are part of a paragraph or continuous text must be **underlined**. Th
For links in form captions and PageHeader descriptions, this is done automatically. Otherwise, it has to be done [manually](https://primer.style/view-components/lookbook/inspect/primer/beta/link/default) by setting `underline: true`.
<%= embed OpenProject::Common::LinkPreview, :inline %>
+
+## Technical notes
+
+The module `Redmine::I18n` offers a helper called `link_translate` that can be used to render inline links inside translated text. This method ensures that the guidelines above are respected.
diff --git a/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb b/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb
index e57eb4682c9..e7a6f35f594 100644
--- a/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb
+++ b/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb
@@ -55,9 +55,9 @@ module Saml
caption: link_translate(
"saml.instructions.documentation_link",
links: {
- docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:saml][:href]
+ docs_url: %i[sysadmin_docs saml]
},
- target: "_blank"
+ external: true
)
) do |list|
Saml::Defaults::ATTRIBUTE_FORMATS.each do |format|
diff --git a/modules/auth_saml/app/views/saml/providers/edit.html.erb b/modules/auth_saml/app/views/saml/providers/edit.html.erb
index 49def832e99..c00e87fdeb6 100644
--- a/modules/auth_saml/app/views/saml/providers/edit.html.erb
+++ b/modules/auth_saml/app/views/saml/providers/edit.html.erb
@@ -15,9 +15,9 @@
<%= link_translate(
"saml.instructions.documentation_link",
links: {
- docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:saml][:href]
+ docs_url: %i[sysadmin_docs saml]
},
- target: "_blank"
+ external: true
) %>
<% end %>
<% end %>
diff --git a/modules/auth_saml/app/views/saml/providers/new.html.erb b/modules/auth_saml/app/views/saml/providers/new.html.erb
index fc18b0eaea0..1b0186468a3 100644
--- a/modules/auth_saml/app/views/saml/providers/new.html.erb
+++ b/modules/auth_saml/app/views/saml/providers/new.html.erb
@@ -13,9 +13,9 @@
<%= link_translate(
"saml.instructions.documentation_link",
links: {
- docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:saml][:href]
+ docs_url: %i[sysadmin_docs saml]
},
- target: "_blank"
+ external: true
) %>
<% end %>
<% end %>
diff --git a/modules/openid_connect/app/components/openid_connect/providers/claims_form.rb b/modules/openid_connect/app/components/openid_connect/providers/claims_form.rb
index faa3b09500c..ec6872e0222 100644
--- a/modules/openid_connect/app/components/openid_connect/providers/claims_form.rb
+++ b/modules/openid_connect/app/components/openid_connect/providers/claims_form.rb
@@ -40,9 +40,7 @@ module OpenIDConnect
label: OpenIDConnect::Provider.human_attribute_name(:claims),
caption: link_translate(
"openid_connect.instructions.claims",
- links: {
- docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:oidc_claims][:href]
- }
+ links: { docs_url: %i[sysadmin_docs oidc_claims] }
),
disabled: provider.seeded_from_env?,
required: false,
@@ -54,9 +52,7 @@ module OpenIDConnect
label: OpenIDConnect::Provider.human_attribute_name(:acr_values),
caption: link_translate(
"openid_connect.instructions.acr_values",
- links: {
- docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:oidc_acr_values][:href]
- }
+ links: { docs_url: %i[sysadmin_docs oidc_acr_values] }
),
disabled: provider.seeded_from_env?,
required: false,
diff --git a/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb b/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
index 433cc7f9774..c054e58ef01 100644
--- a/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
+++ b/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
@@ -59,7 +59,8 @@ module OpenIDConnect
"openid_connect.instructions.scope",
links: {
docs_url: "https://openid.net/specs/openid-connect-basic-1_0.html#Scopes"
- }
+ },
+ external: true
),
disabled: provider.seeded_from_env?,
required: false,
diff --git a/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb b/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb
index 601845d9a1a..187f94097d1 100644
--- a/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb
+++ b/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb
@@ -70,9 +70,9 @@ module OpenIDConnect
name: :group_regexes,
rows: 5,
label: I18n.t("openid_connect.providers.label_group_regexes"),
- caption: link_translate("openid_connect.instructions.group_regexes", links: {
- docs_url: ::OpenProject::Static::Links.url_for(:sysadmin_docs, :oidc_groups)
- }),
+ caption: link_translate("openid_connect.instructions.group_regexes",
+ links: { docs_url: %i[sysadmin_docs oidc_groups] },
+ external: true),
disabled: provider.seeded_from_env?,
required: false,
input_width: :large,