Skip to content

Commit e99d0ad

Browse files
committed
add locale
1 parent dbf01b7 commit e99d0ad

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

models/git/commit_status.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/setting"
2323
api "code.gitea.io/gitea/modules/structs"
2424
"code.gitea.io/gitea/modules/timeutil"
25+
"code.gitea.io/gitea/modules/translation"
2526

2627
"xorm.io/builder"
2728
"xorm.io/xorm"
@@ -191,6 +192,11 @@ func (status *CommitStatus) APIURL(ctx context.Context) string {
191192
return status.Repo.APIURL() + "/statuses/" + url.PathEscape(status.SHA)
192193
}
193194

195+
// LocaleString returns the locale string name of the Status
196+
func (status *CommitStatus) LocaleString(lang translation.Locale) string {
197+
return lang.Tr(status.State.String())
198+
}
199+
194200
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
195201
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
196202
var lastStatus *CommitStatus

modules/structs/commit_status.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var commitStatusPriorities = map[CommitStatusState]int{
2525
CommitStatusSuccess: 3,
2626
}
2727

28+
func (css CommitStatusState) String() string {
29+
return string(css)
30+
}
31+
2832
// NoBetterThan returns true if this State is no better than the given State
2933
// This function only handles the states defined in CommitStatusPriorities
3034
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {

options/locale/locale_en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ step2 = Step 2:
112112
error = Error
113113
error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it.
114114

115+
failure = Failure
116+
pending = Pending
117+
success = Success
118+
115119
never = Never
116120
unknown = Unknown
117121

routers/web/repo/repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ func SearchRepo(ctx *context.Context) {
600600

601601
results := make([]*repo_service.WebSearchRepository, len(repos))
602602
for i, repo := range repos {
603+
latestCommitStatus := git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
604+
603605
results[i] = &repo_service.WebSearchRepository{
604606
Repository: &api.Repository{
605607
ID: repo.ID,
@@ -613,7 +615,8 @@ func SearchRepo(ctx *context.Context) {
613615
Link: repo.Link(),
614616
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
615617
},
616-
LatestCommitStatus: git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID]),
618+
LatestCommitStatus: latestCommitStatus,
619+
LocaleLatestCommitStatus: latestCommitStatus.LocaleString(ctx.Locale),
617620
}
618621
}
619622

services/repository/repository.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ import (
2828

2929
// WebSearchRepository represents a repository returned by web search
3030
type WebSearchRepository struct {
31-
Repository *structs.Repository `json:"repository"`
32-
LatestCommitStatus *git.CommitStatus `json:"latest_commit_status"`
31+
Repository *structs.Repository `json:"repository"`
32+
LatestCommitStatus *git.CommitStatus `json:"latest_commit_status"`
33+
LocaleLatestCommitStatus string `json:"locale_latest_commit_status"`
3334
}
3435

3536
// WebSearchResults results of a successful web search

web_src/js/components/DashboardRepoList.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<svg-icon name="octicon-archive" :size="16"/>
7878
</div>
7979
</a>
80-
<a class="gt-df gt-ac" v-if="repo.latest_commit_status_state" :href="repo.latest_commit_status_state_link" :data-tooltip-content="repo.latest_commit_status_state">
80+
<a class="gt-df gt-ac" v-if="repo.latest_commit_status_state" :href="repo.latest_commit_status_state_link" :data-tooltip-content="repo.locale_latest_commit_status_state">
8181
<!-- the commit status icon logic is taken from templates/repo/commit_status.tmpl -->
8282
<svg-icon :name="statusIcon(repo.latest_commit_status_state)" :class-name="'gt-ml-3 commit-status icon text ' + statusColor(repo.latest_commit_status_state)" :size="16"/>
8383
</a>
@@ -396,7 +396,14 @@ const sfc = {
396396
}
397397
398398
if (searchedURL === this.searchURL) {
399-
this.repos = json.data.map((webSearchRepo) => {return {...webSearchRepo.repository, latest_commit_status_state: webSearchRepo.latest_commit_status.State, latest_commit_status_state_link: webSearchRepo.latest_commit_status.TargetURL}});
399+
this.repos = json.data.map((webSearchRepo) => {
400+
return {
401+
...webSearchRepo.repository,
402+
latest_commit_status_state: webSearchRepo.latest_commit_status.State,
403+
locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status,
404+
latest_commit_status_state_link: webSearchRepo.latest_commit_status.TargetURL
405+
};
406+
});
400407
const count = response.headers.get('X-Total-Count');
401408
if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') {
402409
this.reposTotalCount = count;

0 commit comments

Comments
 (0)