Skip to content

Add a tool to detect possible unused language keys and untranslated keys #34737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/pull-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ jobs:
GOOS: linux
GOARCH: 386

i18n-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: make i18n-check

docs:
if: needs.files-changed.outputs.docs == 'true' || needs.files-changed.outputs.actions == 'true'
needs: files-changed
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,16 @@ update-translations:
mv ./translations/*.ini ./options/locale/
rmdir ./translations

.PHONY: i18n-backport
i18n-backport:
@echo "Backport translations ..."
$(GO) run tools/i18n/backport.go

.PHONY: i18n-check
i18n-check:
@echo "Checking unused translations..."
$(GO) run tools/i18n/check.go

.PHONY: generate-gitignore
generate-gitignore: ## update gitignore files
$(GO) run build/generate-gitignores.go
Expand Down
1 change: 1 addition & 0 deletions models/actions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (r *ActionRunner) StatusName() string {
}

func (r *ActionRunner) StatusLocaleName(lang translation.Locale) string {
// i18n-check: actions.runners.status.*
return lang.TrString("actions.runners.status." + r.StatusName())
}

Expand Down
1 change: 1 addition & 0 deletions models/actions/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (s Status) String() string {

// LocaleString returns the locale string name of the Status
func (s Status) LocaleString(lang translation.Locale) string {
// i18n-check: actions.status.*
return lang.TrString("actions.status." + s.String())
}

Expand Down
1 change: 1 addition & 0 deletions models/git/commit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (status *CommitStatus) APIURL(ctx context.Context) string {

// LocaleString returns the locale string name of the Status
func (status *CommitStatus) LocaleString(lang translation.Locale) string {
// i18n-check: repo.commitstatus.*
return lang.TrString("repo.commitstatus." + status.State.String())
}

Expand Down
2 changes: 2 additions & 0 deletions models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ const (

// LocaleString returns the locale string name of the role
func (r RoleInRepo) LocaleString(lang translation.Locale) string {
// i18n-check: repo.issues.role.*
return lang.TrString("repo.issues.role." + string(r))
}

// LocaleHelper returns the locale tooltip of the role
func (r RoleInRepo) LocaleHelper(lang translation.Locale) string {
// i18n-check: repo.issues.role.*_helper
return lang.TrString("repo.issues.role." + string(r) + "_helper")
}

Expand Down
1 change: 1 addition & 0 deletions modules/auth/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func BuildComplexityError(locale translation.Locale) template.HTML {
buffer.WriteString("<ul>")
for _, c := range requiredList {
buffer.WriteString("<li>")
// i18n-check: form.password_*
buffer.WriteString(locale.TrString(c.TrNameOne))
buffer.WriteString("</li>")
}
Expand Down
1 change: 1 addition & 0 deletions modules/translation/i18n/localestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (l *locale) TrHTML(trKey string, trArgs ...any) template.HTML {
args[i] = template.HTMLEscapeString(fmt.Sprint(v))
}
}
// i18n-check: ignore
return template.HTML(l.TrString(trKey, args...))
}

Expand Down
1 change: 1 addition & 0 deletions modules/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func (l *locale) TrN(cnt any, key1, keyN string, args ...any) template.HTML {
} else if t, ok := cnt.(int64); ok {
c = t
} else {
// i18n-check: ignore
return l.Tr(keyN, args...)
}

Expand Down
2 changes: 2 additions & 0 deletions modules/web/middleware/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ func Validate(errs binding.Errors, data map[string]any, f Form, l translation.Lo

trName := field.Tag.Get("locale")
if len(trName) == 0 {
// i18n-check: form.*
trName = l.TrString("form." + field.Name)
} else {
// i18n-check: ignore
trName = l.TrString(trName)
}

Expand Down
Loading
Loading