Skip to content

Fix: notify locale on push to merge request email

What does this MR do and why?

Reason

Right now the email template for push to merge request email notification can only be sent in English

Result

in this MR I updated the template with i18n enabled strings instead of hardcoded strings. After this MR it will be able to send languages the user prefers.

How to test locally

  1. Start your GDK instance locally or via gitpod or other ways
  2. Run rails console
    recipient=User.find(1)
    merge_request=MergeRequest.find(1)
    push_user=recipient
    existing_commits=[merge_request.commits.first]
    Notify.push_to_merge_request_email(
             recipient.id, merge_request.id, push_user.id,
             new_commits: merge_request.commits, total_new_commits_count: merge_request.commits.length+3,
             existing_commits: existing_commits, total_existing_commits_count: existing_commits.length
           ).deliver
  3. See before version on http://127.0.0.1:3000/rails/letter_opener/
  4. Set :zh_CN
    • Add - I18n.locale = :zh_CN for app/views/notify/push_to_merge_request_email.html.haml
    • Copy the text and paste it into locale/zh_CN/gitlab.po
      msgid "Notify|%{updated_by_user_name} pushed new commits to merge request %{mr_link}"
      msgstr "%{updated_by_user_name} 将新提交推送到合并请求 %{mr_link}"
      
      msgid "#%d commit"
      msgid_plural "#%d commits"
      msgstr[0] "%d 个提交"
      
      msgid "%{commits_text} from branch `%{target_branch}`"
      msgstr "%{commits_text} 来自分支 `%{target_branch}`"
      
      msgid "Notify|And %{total_stripped_new_commits_count} more"
      msgstr "还有 %{total_stripped_new_commits_count} 个"
  5. Repeat 2 and 3 to see after

/cc @prajnamas @orozot @qk44077907 @JeremyWuuuuu

Screenshots or screen recordings

Before After
Snipaste_2022-09-05_11-07-09 Snipaste_2022-09-05_11-07-17

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by qt

Merge request reports