mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:11:08 -06:00
FIX: Localize text in github oneboxes (#25327)
This commit is contained in:
parent
f4e51e0789
commit
d401502834
@ -5235,6 +5235,22 @@ en:
|
||||
onebox:
|
||||
discourse:
|
||||
user_joined_community: "Joined %{date}"
|
||||
gitlab:
|
||||
truncated_file: "This file has been truncated."
|
||||
show_original: "show original"
|
||||
github:
|
||||
binary_file: "This file is binary."
|
||||
truncated_file: "This file has been truncated."
|
||||
show_original: "show original"
|
||||
requires_iframe: "Viewer requires iframe."
|
||||
committed: "committed"
|
||||
more_than_three_files: "There are more than three files."
|
||||
opened: "opened"
|
||||
closed: "closed"
|
||||
commit_by: "Commit by"
|
||||
comment_by: "Comment by"
|
||||
review_by: "Review by"
|
||||
pr_summary: "%{commits} commits changed %{changed_files} files with %{additions} additions and %{deletions} deletions"
|
||||
|
||||
discourse_push_notifications:
|
||||
popup:
|
||||
|
@ -15,6 +15,15 @@ module Onebox
|
||||
|
||||
include Onebox::Mixins::GitBlobOnebox
|
||||
|
||||
def i18n
|
||||
{
|
||||
binary_file: I18n.t("onebox.github.binary_file"),
|
||||
truncated_file: I18n.t("onebox.github.truncated_file"),
|
||||
show_original: I18n.t("onebox.github.show_original"),
|
||||
requires_iframe: I18n.t("onebox.github.requires_iframe"),
|
||||
}
|
||||
end
|
||||
|
||||
def raw_regexp
|
||||
%r{github\.com/(?<user>[^/]+)/(?<repo>[^/]+)/blob/(?<sha1>[^/]+)/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?}mi
|
||||
end
|
||||
|
@ -47,6 +47,7 @@ module Onebox
|
||||
result["link"] = link
|
||||
ulink = URI(link)
|
||||
result["domain"] = "#{ulink.host}/#{ulink.path.split("/")[1]}/#{ulink.path.split("/")[2]}"
|
||||
result["i18n"] = { committed: I18n.t("onebox.github.committed") }
|
||||
|
||||
result
|
||||
end
|
||||
|
@ -24,6 +24,15 @@ module Onebox
|
||||
link: link,
|
||||
gist_files: gist_files.take(MAX_FILES),
|
||||
truncated_files?: truncated_files?,
|
||||
i18n: i18n,
|
||||
}
|
||||
end
|
||||
|
||||
def i18n
|
||||
{
|
||||
truncated_file: I18n.t("onebox.github.truncated_file"),
|
||||
more_than_three_files: I18n.t("onebox.github.more_than_three_files"),
|
||||
show_original: I18n.t("onebox.github.show_original"),
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -30,6 +30,10 @@ module Onebox
|
||||
)
|
||||
end
|
||||
|
||||
def i18n
|
||||
{ opened: I18n.t("onebox.github.opened"), closed: I18n.t("onebox.github.closed") }
|
||||
end
|
||||
|
||||
def data
|
||||
created_at = Time.parse(raw["created_at"])
|
||||
closed_at = Time.parse(raw["closed_at"]) if raw["closed_at"]
|
||||
@ -54,6 +58,7 @@ module Onebox
|
||||
closed_by: raw["closed_by"],
|
||||
avatar: "https://avatars1.githubusercontent.com/u/#{raw["user"]["id"]}?v=2&s=96",
|
||||
domain: "#{ulink.host}/#{ulink.path.split("/")[1]}/#{ulink.path.split("/")[2]}",
|
||||
i18n: i18n,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -50,10 +50,29 @@ module Onebox
|
||||
else
|
||||
result["pr"] = true
|
||||
end
|
||||
result["i18n"] = i18n
|
||||
result["i18n"]["pr_summary"] = I18n.t(
|
||||
"onebox.github.pr_summary",
|
||||
{
|
||||
commits: result["commits"],
|
||||
changed_files: result["changed_files"],
|
||||
additions: result["additions"],
|
||||
deletions: result["deletions"],
|
||||
},
|
||||
)
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def i18n
|
||||
{
|
||||
opened: I18n.t("onebox.github.opened"),
|
||||
commit_by: I18n.t("onebox.github.commit_by"),
|
||||
comment_by: I18n.t("onebox.github.comment_by"),
|
||||
review_by: I18n.t("onebox.github.review_by"),
|
||||
}
|
||||
end
|
||||
|
||||
def load_commit(link)
|
||||
if commit_match = link.match(%r{commits/(\h+)})
|
||||
load_json(
|
||||
|
@ -15,6 +15,13 @@ module Onebox
|
||||
|
||||
include Onebox::Mixins::GitBlobOnebox
|
||||
|
||||
def i18n
|
||||
{
|
||||
truncated_file: I18n.t("onebox.gitlab.truncated_file"),
|
||||
show_original: I18n.t("onebox.gitlab.show_original"),
|
||||
}
|
||||
end
|
||||
|
||||
def raw_regexp
|
||||
%r{gitlab\.com/(?<user>[^/]+)/(?<repo>[^/]+)/blob/(?<sha1>[^/]+)/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?}mi
|
||||
end
|
||||
|
@ -220,6 +220,7 @@ module Onebox
|
||||
@data ||= {
|
||||
title: title,
|
||||
link: link,
|
||||
i18n: i18n,
|
||||
# IMPORTANT NOTE: All of the other class variables are populated
|
||||
# as *side effects* of the `raw` method! They must all appear
|
||||
# AFTER the call to `raw`! Don't get bitten by this like I did!
|
||||
|
@ -4,7 +4,7 @@
|
||||
{{^has_lines}}
|
||||
{{#model_file}}
|
||||
<iframe class="render-viewer" width="{{width}}" height="{{height}}" src="{{content}}" sandbox="allow-scripts allow-same-origin allow-top-navigation ">
|
||||
Viewer requires iframe.
|
||||
{{i18n.requires_iframe}}
|
||||
</iframe>
|
||||
{{/model_file}}
|
||||
|
||||
@ -51,9 +51,9 @@
|
||||
{{/binary}}
|
||||
|
||||
{{#binary}}
|
||||
This file is binary. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
|
||||
{{i18n.binary_file}} <a href="{{link}}" target="_blank" rel="noopener">{{i18n.show_original}}</a>
|
||||
{{/binary}}
|
||||
|
||||
{{#truncated}}
|
||||
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
|
||||
{{i18n.truncated_file}} <a href="{{link}}" target="_blank" rel="noopener">{{i18n.show_original}}</a>
|
||||
{{/truncated}}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
<div class="github-info">
|
||||
<div class="date">
|
||||
committed <span class="discourse-local-date" data-format="ll" data-date="{{committed_at_date}}" data-time="{{committed_at_time}}" data-timezone="UTC">{{committed_at}}</span>
|
||||
{{i18n.committed}} <span class="discourse-local-date" data-format="ll" data-date="{{committed_at_date}}" data-time="{{committed_at_time}}" data-timezone="UTC">{{committed_at}}</span>
|
||||
</div>
|
||||
|
||||
<div class="user">
|
||||
|
@ -4,12 +4,12 @@
|
||||
<h5>{{filename}}</h5>
|
||||
<pre><code class="{{language}}">{{content}}</code></pre>
|
||||
{{#truncated?}}
|
||||
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
|
||||
{{i18n.truncated_file}} <a href="{{link}}" target="_blank" rel="noopener">{{i18n.show_original}}</a>
|
||||
{{/truncated?}}
|
||||
{{/gist_files}}
|
||||
|
||||
<p>
|
||||
{{#truncated_files?}}
|
||||
There are more than three files. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
|
||||
{{i18n.more_than_three_files}} <a href="{{link}}" target="_blank" rel="noopener">{{i18n.show_original}}</a>
|
||||
{{/truncated_files?}}
|
||||
</p>
|
||||
|
@ -10,12 +10,12 @@
|
||||
|
||||
<div class="github-info">
|
||||
<div class="date">
|
||||
opened <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
|
||||
{{i18n.opened}} <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
|
||||
</div>
|
||||
|
||||
{{#closed_at}}
|
||||
<div class="date">
|
||||
closed <span class="discourse-local-date" data-format="ll" data-date="{{closed_at_date}}" data-time="{{closed_at_time}}" data-timezone="UTC">{{closed_at}}</span>
|
||||
{{i18n.closed}} <span class="discourse-local-date" data-format="ll" data-date="{{closed_at_date}}" data-time="{{closed_at_time}}" data-timezone="UTC">{{closed_at}}</span>
|
||||
</div>
|
||||
{{/closed_at}}
|
||||
|
||||
|
@ -31,38 +31,32 @@
|
||||
|
||||
<div class="github-info">
|
||||
<span>
|
||||
Commit by
|
||||
{{i18n.commit_by}}
|
||||
<a href="{{author.html_url}}" target="_blank" rel="noopener">
|
||||
<img alt="{{author.login}}" src="{{author.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
|
||||
{{author.login}}
|
||||
</a>
|
||||
in
|
||||
<a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</a> - <a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</span>
|
||||
</div>
|
||||
{{/commit}}
|
||||
|
||||
{{#comment}}
|
||||
<h4>
|
||||
Comment by
|
||||
{{i18n.comment_by}}
|
||||
<a href="{{user.html_url}}" target="_blank" rel="noopener">
|
||||
<img alt="{{user.login}}" src="{{user.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
|
||||
{{user.login}}
|
||||
</a>
|
||||
to
|
||||
<a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</a> - <a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</h4>
|
||||
{{/comment}}
|
||||
|
||||
{{#discussion}}
|
||||
<h4>
|
||||
Review by
|
||||
{{i18n.review_by}}
|
||||
<a href="{{user.html_url}}" target="_blank" rel="noopener">
|
||||
<img alt="{{user.login}}" src="{{user.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
|
||||
{{user.login}}
|
||||
</a>
|
||||
in
|
||||
<a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</a> - <a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
|
||||
</h4>
|
||||
{{/discussion}}
|
||||
|
||||
@ -79,7 +73,7 @@
|
||||
{{#pr}}
|
||||
<div class="github-info">
|
||||
<div class="date">
|
||||
opened <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
|
||||
{{i18n.opened}} <span class="discourse-local-date" data-format="ll" data-date="{{created_at_date}}" data-time="{{created_at_time}}" data-timezone="UTC">{{created_at}}</span>
|
||||
</div>
|
||||
|
||||
<div class="user">
|
||||
@ -89,7 +83,7 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="lines" title="{{commits}} commits changed {{changed_files}} files with {{additions}} additions and {{deletions}} deletions">
|
||||
<div class="lines" title="{{i18n.pr_summary}}">
|
||||
<a href="{{html_url}}/files" target="_blank" rel="noopener">
|
||||
<span class="added">+{{additions}}</span>
|
||||
<span class="removed">-{{deletions}}</span>
|
||||
|
@ -17,5 +17,5 @@
|
||||
{{/has_lines}}
|
||||
|
||||
{{#truncated}}
|
||||
This file has been truncated. <a href="{{link}}" target="_blank" rel="noopener">show original</a>
|
||||
{{i18n.truncated_file}} <a href="{{link}}" target="_blank" rel="noopener">{{i18n.show_original}}</a>
|
||||
{{/truncated}}
|
||||
|
Loading…
Reference in New Issue
Block a user