From cdedbc158818f82ca3271f77bb2bd5f30cf76f8a Mon Sep 17 00:00:00 2001 From: yheuhtozr <84892012+yheuhtozr@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:46:46 +0900 Subject: [PATCH] views/notifications i18n (#15056) * views/notifications etc i18n * notifications PR fixes * remove ja.yml * Update en.yml * Update fr.yml * Update en.yml * Update fr.yml * Update _comment.html.erb * Update _comment.html.erb * Update notifications_helper.rb * Update notifications_helper.rb * Update notifications_helper.rb * Update notifications_helper.rb Co-authored-by: Michael Kohl --- app/helpers/notifications_helper.rb | 13 ++++ .../notifications/new_comment/send.rb | 4 +- app/views/notifications/_article.html.erb | 10 +-- .../notifications/_badgeachievement.html.erb | 11 ++- app/views/notifications/_broadcast.html.erb | 2 +- app/views/notifications/_comment.html.erb | 33 +++------ app/views/notifications/_follow.html.erb | 15 ++-- app/views/notifications/_mention.html.erb | 12 +-- app/views/notifications/_milestone.html.erb | 7 +- app/views/notifications/_nav_menu.html.erb | 24 +++--- .../_notifications_list.html.erb | 4 +- .../notifications/_tagadjustment.html.erb | 14 ++-- app/views/notifications/index.html.erb | 20 ++--- config/locales/en.yml | 40 +++++++++- config/locales/fr.yml | 40 +++++++++- config/locales/views/notifications/en.yml | 74 +++++++++++++++++++ config/locales/views/notifications/fr.yml | 74 +++++++++++++++++++ 17 files changed, 303 insertions(+), 94 deletions(-) create mode 100644 config/locales/views/notifications/en.yml create mode 100644 config/locales/views/notifications/fr.yml diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index e6f5cb628..78e98a74e 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -12,4 +12,17 @@ module NotificationsHelper def reaction_image(category) REACTION_IMAGES[category] end + + def message_user_acted_maybe_org(data, action, if_org: "") + key_to_link = ->(key) { link_to(data[key]["name"], data[key]["path"], class: "crayons-link fw-bold") } + if if_org.present? + I18n.t( + action, + user: key_to_link.call("user"), + if_org: data["organization"] ? I18n.t(if_org, org: key_to_link.call("organization")) : "", + ) + else + I18n.t(action, user: key_to_link.call("user")) + end.html_safe + end end diff --git a/app/services/notifications/new_comment/send.rb b/app/services/notifications/new_comment/send.rb index e65824b8b..944b9c25c 100644 --- a/app/services/notifications/new_comment/send.rb +++ b/app/services/notifications/new_comment/send.rb @@ -43,8 +43,8 @@ module Notifications PushNotifications::Send.call( user_ids: targets, title: "πŸ’¬ New Comment", - body: "#{comment.user.username} commented on " \ - "#{comment.commentable.title.strip}:\n" \ + body: "#{I18n.t('views.notifications.comment.commented_html', user: comment.user.username, + title: comment.commentable.title.strip)}:\n" \ "#{strip_tags(comment.processed_html).strip}", payload: { url: URL.url(comment.path), diff --git a/app/views/notifications/_article.html.erb b/app/views/notifications/_article.html.erb index 5ee39e4c7..f8647e748 100644 --- a/app/views/notifications/_article.html.erb +++ b/app/views/notifications/_article.html.erb @@ -10,15 +10,9 @@

- " class="crayons-link fw-bold"> - <%= json_data["user"]["name"] %> - - made a new post - <% if json_data["organization"] %> - under " class="crayons-link fw-bold"><%= json_data["organization"]["name"] %> - <% end %> + <%= message_user_acted_maybe_org(json_data, "views.notifications.new_post.verb_html", if_org: "views.notifications.new_post.if_org_html") %>

-

<%= time_ago_in_words json_data["article"]["published_at"] %> ago

+

<%= time_ago_in_words json_data["article"]["published_at"], scope: :"datetime.distance_in_words_ago" %>

<%= render "notifications/shared/article_preview", json_data: json_data, notification: notification, context: "default" %> diff --git a/app/views/notifications/_badgeachievement.html.erb b/app/views/notifications/_badgeachievement.html.erb index c82f47b24..5f044f7ab 100644 --- a/app/views/notifications/_badgeachievement.html.erb +++ b/app/views/notifications/_badgeachievement.html.erb @@ -2,7 +2,7 @@

- You received the <%= sanitize(json_data["badge_achievement"]["badge"]["title"]) %> badge + <%= t("views.notifications.badge.heading_html", badge: tag.strong(sanitize(json_data["badge_achievement"]["badge"]["title"]), class: "fw-bold")) %>

<%= json_data["badge_achievement"]["badge"]["description"] %>

@@ -12,10 +12,13 @@

<%= json_data["badge_achievement"]["rewarding_context_message"].to_s.html_safe %>

-

" class="crayons-btn w-100 m:w-50">Visit your profile

+

" class="crayons-btn w-100 m:w-50"><%= t("views.notifications.badge.profile") %>

<% credits_awarded = json_data["badge_achievement"]["badge"]["credits_awarded"] %> <% unless credits_awarded.present? && credits_awarded.zero? %> -

You also get <%= json_data["badge_achievement"]["badge"]["credits_awarded"] %> new credits to use for community listings if you have anything you'd like to promote. πŸŽ‰

-

More information about listings

+

+ <%= t("views.notifications.badge.awarded_html", credits: link_to(t("views.notifications.badge.credits", count: json_data["badge_achievement"]["badge"]["credits_awarded"]), "/credits", class: "crayons-link crayons-link--brand fw-bold"), + listings: link_to(t("views.notifications.badge.listings"), "/listings")) %> +

+

<%= t("views.notifications.badge.more") %>

<% end %>
diff --git a/app/views/notifications/_broadcast.html.erb b/app/views/notifications/_broadcast.html.erb index 42201fa14..508c94d4b 100644 --- a/app/views/notifications/_broadcast.html.erb +++ b/app/views/notifications/_broadcast.html.erb @@ -9,7 +9,7 @@ <%= json_data["broadcast"]["processed_html"].html_safe %> <% if notification.json_data['broadcast']['type_of'] == "Welcome" %> -

Visit Settings to manage your notifications.

+

<%= t("views.notifications.broadcast.visit_html", settings: link_to(t("views.notifications.broadcast.settings"), user_settings_path(tab: :notifications))) %>

<% end %> <% end %> diff --git a/app/views/notifications/_comment.html.erb b/app/views/notifications/_comment.html.erb index 816900fa8..5cf1a8691 100644 --- a/app/views/notifications/_comment.html.erb +++ b/app/views/notifications/_comment.html.erb @@ -8,23 +8,18 @@ <% end %>
+ <% params = { user: link_to(json_data["user"]["name"], json_data["user"]["path"], class: "crayons-link fw-bold"), title: link_to(h(json_data["comment"]["commentable"]["title"]), json_data["comment"]["commentable"]["path"], class: "crayons-link fw-bold") } %> <% if notification.action.blank? %> <% if json_data["comment"]["created_at"] %>

- " class="crayons-link fw-bold"> - <%= json_data["user"]["name"] %> - <% if json_data["comment"]["depth"] && json_data["comment"]["depth"] > 0 %> - replied to a thread in + <%= t("views.notifications.comment.replied_html", **params) %> <% else %> - commented on + <%= t("views.notifications.comment.commented_html", **params) %> <% end %> - " class="crayons-link fw-bold"> - <%= h(json_data["comment"]["commentable"]["title"]) %> -

-

" class="crayons-link fs-s crayons-link--secondary"><%= time_ago_in_words json_data["comment"]["created_at"] %> ago

+

" class="crayons-link fs-s crayons-link--secondary"><%= time_ago_in_words json_data["comment"]["created_at"], scope: :"datetime.distance_in_words_ago" %>

<% end %> @@ -33,31 +28,23 @@ <% elsif notification.action == "Moderation" %>

- " class="crayons-link fw-bold"><%= json_data["comment"]["path"].split("/")[1] %> - just left a comment on - " class="crayons-link fw-bold"> - <%= h(json_data["comment"]["commentable"]["title"]) %> - . + <%= t("views.notifications.comment.left_html", user: link_to(json_data["comment"]["path"].split("/")[1], "/#{json_data['comment']['path'].split('/')[1]}", class: "crayons-link fw-bold"), title: params[:title]) %>

-

Since they are new to the community, could you leave a nice reply to help them feel welcome? Thank you!

+

<%= t("views.notifications.comment.welcome_html") %>

<%= render "notifications/shared/comment_box", json_data: json_data, notification: notification, context: "moderation" %> -

All negative reactions are 100% private. If this comment violates the code of conduct, please downvote/report as inappropriate.

+

<%= t("views.notifications.comment.report") %>

<% elsif notification.action == "First" %>

- " class="crayons-link fw-bold"><%= json_data["user"]["name"] %> - wrote their first comment on - " class="crayons-link fw-bold"> - <%= h(json_data["comment"]["commentable"]["title"]) %> - + <%= t("views.notifications.comment.first_html", **params) %>

-

<%= time_ago_in_words notification.created_at %> ago

+

<%= time_ago_in_words notification.created_at, scope: :"datetime.distance_in_words_ago" %>

-

Give them their first reply! πŸŽ‰

+

<%= t("views.notifications.comment.first_reply") %>

<%= render "notifications/shared/comment_box", activity: activity, context: "moderation" %> diff --git a/app/views/notifications/_follow.html.erb b/app/views/notifications/_follow.html.erb index cf8d38972..08f659f0f 100644 --- a/app/views/notifications/_follow.html.erb +++ b/app/views/notifications/_follow.html.erb @@ -1,5 +1,6 @@ -
notification--middle <% else %> flex-col items-center <% end %>"> - <% if notification.json_data["aggregated_siblings"].length == 1 %> +<% siblings = notification.json_data["aggregated_siblings"].length %> +
+ <% if siblings == 1 %> <% first_notification = notification.json_data["aggregated_siblings"].first %> <% cache "activity-profile-pic-#{first_notification['id']}-#{first_notification['profile_image_90']}" do %> " class="crayons-avatar crayons-avatar--l <% if notification.json_data["aggregated_siblings"].length == 1 %>m:crayons-avatar--xl<% end %> shrink-0" tabindex="-1" aria-hidden="true"> @@ -9,7 +10,7 @@
<% cache "activity-follow-button-#{first_notification['path']}-#{first_notification['name']}" do %>
-

" class="crayons-link fw-bold"><%= first_notification["name"] %> followed you!

+

<%= t("views.notifications.follow.single_html", name: link_to(first_notification["name"], first_notification["path"], class: "crayons-link fw-bold")) %>

<%= follow_button(notification.decorate.mocked_object("user"), "follow-back") %>
<% end %> @@ -24,12 +25,10 @@ <% end %>

- <% if notification.json_data["aggregated_siblings"].length == 2 %> - " class="crayons-link fw-bold"><%= json_data_array.first["name"] %> and - " class="crayons-link fw-bold"><%= json_data_array.second["name"] %> followed you! + <% if siblings == 2 %> + <%= t("views.notifications.follow.and_html", first: link_to(json_data_array.first["name"], json_data_array.first["path"], class: "crayons-link fw-bold"), second: link_to(json_data_array.second["name"], json_data_array.second["path"], class: "crayons-link fw-bold")) %> <% else %> - " class="crayons-link fw-bold"><%= json_data_array.first["name"] %> - and <%= notification.json_data["aggregated_siblings"].size - 1 %> others followed you! + <%= t("views.notifications.follow.and_other_html", first: link_to(json_data_array.first["name"], json_data_array.first["path"], class: "crayons-link fw-bold"), others: t("views.notifications.follow.others", count: siblings - 1), count: siblings) %> <% end %>

<% end %> diff --git a/app/views/notifications/_mention.html.erb b/app/views/notifications/_mention.html.erb index 9e0966d76..e833f3087 100644 --- a/app/views/notifications/_mention.html.erb +++ b/app/views/notifications/_mention.html.erb @@ -8,21 +8,15 @@ <% if notification.json_data["article"] %>

- " class="crayons-link fw-bold"> - <%= json_data["user"]["name"] %> - - mentioned you in a post - <% if json_data["organization"] %> - under " class="crayons-link fw-bold"><%= json_data["organization"]["name"] %> - <% end %> + <%= message_user_acted_maybe_org(json_data, "views.notifications.mention.article_html", if_org: "views.notifications.mention.if_org_html") %>

-

<%= time_ago_in_words json_data["article"]["published_at"] %> ago

+

<%= time_ago_in_words json_data["article"]["published_at"], scope: :"datetime.distance_in_words_ago" %>

<%= render "notifications/shared/article_preview", json_data: json_data, notification: notification, context: "default" %> <% elsif notification.json_data["comment"] %>

- " class="crayons-link fw-bold"><%= json_data["user"]["name"] %> mentioned you in a comment + <%= message_user_acted_maybe_org(json_data, "views.notifications.mention.comment_html") %>

<%= render "notifications/shared/comment_box", json_data: json_data, notification: notification, context: "default" %> <% end %> diff --git a/app/views/notifications/_milestone.html.erb b/app/views/notifications/_milestone.html.erb index 6844ca25d..482ddec2b 100644 --- a/app/views/notifications/_milestone.html.erb +++ b/app/views/notifications/_milestone.html.erb @@ -1,9 +1,8 @@ <% json_data = notification.json_data %>
-

πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰

+

<%= t("views.notifications.milestone.intro") %>

- Your post - " class="crayons-link fw-bold"><%= h(json_data["article"]["title"]) %> passed <%= notification.milestone_count %> <%= notification.milestone_type.pluralize.downcase %>! + <%= t("views.notifications.milestone.heading_html", title: link_to(h(json_data["article"]["title"]), json_data["article"]["path"], class: "crayons-link fw-bold"), type: t("views.notifications.milestone.type.#{notification.milestone_type}", count: notification.milestone_count.to_i)) %>

" rel="noopener noreferrer" class="block my-4" target="_blank"> @@ -11,6 +10,6 @@ - Check your dashboard + <%= t("views.notifications.milestone.check") %>
diff --git a/app/views/notifications/_nav_menu.html.erb b/app/views/notifications/_nav_menu.html.erb index 07f32ea4a..419b22c50 100644 --- a/app/views/notifications/_nav_menu.html.erb +++ b/app/views/notifications/_nav_menu.html.erb @@ -4,7 +4,7 @@ <% user_comments = comments_filter && params[:org_id].blank? %> <% user_posts = params[:filter].to_s.match?(/^posts$/i) && params[:org_id].blank? %> -
<% end %> <% end %> -