Fix: notify locale on request repository push email
What does this MR do and why?
Reason
Right now the email template for repository push 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
- Start your GDK instance locally or via gitpod or other ways
- Run rails console
project=Project.first
user=User.first
sample_image_commit=OpenStruct.new(
id: "2f63565e7aac07bcdadb654e253078b727143ec4",
sha: "2f63565e7aac07bcdadb654e253078b727143ec4",
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9',
new_blob_id: '2f63565e7aac07bcdadb654e253078b727143ec4',
message: <<eos
Modified image
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
sample_commit=OpenStruct.new(
id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
sha: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
parent_id: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
files_changed_count: 2,
line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14',
line_code_path: 'files/ruby/popen.rb',
del_line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13',
message: <<eos
Change some files
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
raw_compare=Gitlab::Git::Compare.new(project.repository.raw_repository, sample_image_commit.id, sample_commit.id)
compare=Compare.decorate(raw_compare, project)
send_from_committer_email=false
diff_refs=Gitlab::Diff::DiffRefs.new(base_sha: project.merge_base_commit(sample_image_commit.id, sample_commit.id).id, head_sha: sample_commit.id)
Notify.repository_push_email(project.id, author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare, reverse_compare: false, diff_refs: diff_refs, send_from_committer_email: send_from_committer_email).deliver
- See before version on http://127.0.0.1:3000/rails/letter_opener/
- Set
:zh_CN- Add
- I18n.locale = :zh_CNforapp/views/notify/repository_push_email.html.haml - Copy the text and paste it into
locale/zh_CN/gitlab.po
- Add
msgid "Notify|%{author_name} %{action_name} %{ref_type} %{ref_name} at %{project_link}"
msgstr "%{author_name} %{action_name} %{ref_type} %{ref_name} 在 %{project_link}"
msgid "Notify|The push did not contain any new commits, but force pushed to delete the commits and changes below."
msgstr "推送没有包含任何新的提交,而是强制推送删除下面的提交和更改。"
msgid "Deleted commits:"
msgstr "删除提交:"
msgid "Commits:"
msgstr "提交:"
msgid "Changes:"
msgstr "改变:"
msgid "Notify|pushed to"
msgstr "推送至"
msgid "Notify|%{committed_by_start} by %{author_name} %{committed_by_end} %{committed_at_start} at %{committed_date} %{committed_at_end}"
msgstr "%{committed_by_start} 作者 %{author_name} %{committed_by_end} %{committed_at_start} 时间 %{committed_date} %{committed_at_end}"
msgid "%d changed file"
msgid_plural "%d changed files"
msgstr[0] "%d 个文件"
msgid "Notify|No preview for this file type"
msgstr "此文件类型没有预览"
- Repeat 2 and 3 to see after
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by qt

