Skip to content

Commit f045e58

Browse files
Localize activity heatmap (except tooltip) (#24131)
The calculation of the total sum is moved to the backend so a full HTML string could be sent. ![image](https://user-images.githubusercontent.com/20454870/232112381-c11d896b-ba47-40f8-b2a3-71cf4b3208de.png) - Closes #10669 - 2nd attempt (the first was in #21570) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: Giteabot <teabot@gitea.io>
1 parent 5eb4c63 commit f045e58

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

models/activities/user_heatmap.go

+9
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ func getUserHeatmapData(user *user_model.User, team *organization.Team, doer *us
6969
OrderBy("timestamp").
7070
Find(&hdata)
7171
}
72+
73+
// GetTotalContributionsInHeatmap returns the total number of contributions in a heatmap
74+
func GetTotalContributionsInHeatmap(hdata []*UserHeatmapData) int64 {
75+
var total int64
76+
for _, v := range hdata {
77+
total += v.Contributions
78+
}
79+
return total
80+
}

options/locale/locale_en-US.ini

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ footer = Footer
118118
footer.software = About Software
119119
footer.links = Links
120120

121+
[heatmap]
122+
number_of_contributions_in_the_last_12_months = %s contributions in the last 12 months
123+
no_contributions = No contributions
124+
less = Less
125+
more = More
126+
121127
[editor]
122128
buttons.heading.tooltip = Add heading
123129
buttons.bold.tooltip = Add bold text

routers/web/user/home.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func Dashboard(ctx *context.Context) {
107107
return
108108
}
109109
ctx.Data["HeatmapData"] = data
110+
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
110111
}
111112

112113
feeds, count, err := activities_model.GetFeeds(ctx, activities_model.GetFeedsOptions{

routers/web/user/profile.go

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func Profile(ctx *context.Context) {
7474
return
7575
}
7676
ctx.Data["HeatmapData"] = data
77+
ctx.Data["HeatmapTotalContributions"] = activities_model.GetTotalContributionsInHeatmap(data)
7778
}
7879

7980
if len(ctx.ContextUser.Description) != 0 {

templates/user/heatmap.tmpl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{{if .HeatmapData}}
2-
<div id="user-heatmap" data-heatmap-data="{{Json .HeatmapData}}">
2+
<div id="user-heatmap"
3+
data-heatmap-data="{{Json .HeatmapData}}"
4+
data-locale-total-contributions="{{$.locale.Tr "heatmap.number_of_contributions_in_the_last_12_months" ($.locale.PrettyNumber .HeatmapTotalContributions)}}"
5+
data-locale-no-contributions="{{.locale.Tr "heatmap.no_contributions"}}"
6+
data-locale-more="{{.locale.Tr "heatmap.more"}}"
7+
data-locale-less="{{.locale.Tr "heatmap.less"}}"
8+
>
39
<div slot="loading">
410
<div class="ui active centered inline indeterminate text loader" id="loading-heatmap">{{.locale.Tr "user.heatmap.loading"}}</div>
511
</div>

web_src/js/components/ActivityHeatmap.vue

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div id="user-heatmap">
33
<div class="total-contributions">
4-
{{ sum }} contributions in the last 12 months
4+
{{ locale.contributions_in_the_last_12_months }}
55
</div>
66
<calendar-heatmap
77
:locale="locale"
@@ -41,15 +41,6 @@ export default {
4141
],
4242
endDate: new Date(),
4343
}),
44-
computed: {
45-
sum() {
46-
let s = 0;
47-
for (let i = 0; i < this.values.length; i++) {
48-
s += this.values[i].count;
49-
}
50-
return s;
51-
}
52-
},
5344
mounted() {
5445
// work around issue with first legend color being rendered twice and legend cut off
5546
const legend = document.querySelector('.vch__external-legend-wrapper');

web_src/js/features/heatmap.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ export function initHeatmap() {
1818
return {date: new Date(v), count: heatmap[v]};
1919
});
2020

21+
// last heatmap tooltip localization attempt https://github.com/go-gitea/gitea/pull/24131/commits/a83761cbbae3c2e3b4bced71e680f44432073ac8
2122
const locale = {
2223
months: new Array(12).fill().map((_, idx) => translateMonth(idx)),
2324
days: new Array(7).fill().map((_, idx) => translateDay(idx)),
2425
contributions: 'contributions',
25-
no_contributions: 'No contributions',
26+
contributions_in_the_last_12_months: el.getAttribute('data-locale-total-contributions'),
27+
no_contributions: el.getAttribute('data-locale-no-contributions'),
28+
more: el.getAttribute('data-locale-more'),
29+
less: el.getAttribute('data-locale-less'),
2630
};
2731

2832
const View = createApp(ActivityHeatmap, {values, locale});

0 commit comments

Comments
 (0)