@@ -12,9 +12,11 @@ import (
1212 "strings"
1313
1414 "code.gitea.io/gitea/modules/setting"
15+
16+ "github.com/gobwas/glob"
1517)
1618
17- func searchDirs (key string ) (bool , error ) {
19+ func searchTranslationKeyInDirs (key string ) (bool , error ) {
1820 for _ , dir := range []string {
1921 "cmd" ,
2022 "models" ,
@@ -23,7 +25,7 @@ func searchDirs(key string) (bool, error) {
2325 "services" ,
2426 "templates" ,
2527 } {
26- found , err := searchLocaleFiles (dir , key )
28+ found , err := searchTranslationKeyInDir (dir , key )
2729 if err != nil {
2830 return false , err
2931 }
@@ -34,13 +36,15 @@ func searchDirs(key string) (bool, error) {
3436 return false , nil
3537}
3638
37- func searchLocaleFiles (dir , key string ) (bool , error ) {
39+ func searchTranslationKeyInDir (dir , key string ) (bool , error ) {
3840 errFound := errors .New ("found" )
3941 err := filepath .WalkDir (dir , func (path string , d os.DirEntry , err error ) error {
4042 if err != nil {
4143 return err
4244 }
43- if d .IsDir () || (! strings .HasSuffix (d .Name (), ".go" ) && ! strings .HasSuffix (d .Name (), ".tmpl" )) {
45+ if d .IsDir () ||
46+ (! strings .HasSuffix (d .Name (), ".go" ) && ! strings .HasSuffix (d .Name (), ".tmpl" )) ||
47+ strings .HasSuffix (d .Name (), "_test.go" ) { // don't search in test files
4448 return nil
4549 }
4650
@@ -60,6 +64,29 @@ func searchLocaleFiles(dir, key string) (bool, error) {
6064 return false , err
6165}
6266
67+ var whitelist = []string {
68+ "repo.signing.wont_sign.*" ,
69+ "repo.issues.role.*" ,
70+ "repo.commitstatus.*" ,
71+ "admin.dashboard.*" ,
72+ "admin.dashboard.cron.*" ,
73+ "admin.dashboard.task.*" ,
74+ "repo.migrate.*.description" ,
75+ "actions.runners.status.*" ,
76+ "projects.*.display_name" ,
77+ "admin.notices.*" ,
78+ "form.NewBranchName" , // FIXME: used in integration tests only
79+ }
80+
81+ func isWhitelisted (key string ) bool {
82+ for _ , w := range whitelist {
83+ if glob .MustCompile (w ).Match (key ) {
84+ return true
85+ }
86+ }
87+ return false
88+ }
89+
6390func main () {
6491 if len (os .Args ) != 1 {
6592 println ("usage: clean-locales" )
@@ -79,8 +106,11 @@ func main() {
79106 } else {
80107 trKey = section .Name () + "." + key .Name ()
81108 }
109+ if isWhitelisted (trKey ) {
110+ continue
111+ }
82112
83- found , err := searchDirs (trKey )
113+ found , err := searchTranslationKeyInDirs (trKey )
84114 if err != nil {
85115 panic (err )
86116 }
0 commit comments