mirror of
https://codeberg.org/forgejo/forgejo
synced 2025-10-19 14:50:52 +02:00
- Move a file around to avoid a circular dependency. - Make lint-locale-usage aware of `base.Messenger`, form struct tags and `$.locale.Tr`. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9095 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Ellen Εμιλία Άννα Zscheile <fogti+devel@ytrizja.de> Co-committed-by: Ellen Εμιλία Άννα Zscheile <fogti+devel@ytrizja.de>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package lintLocaleUsage
|
|
|
|
import (
|
|
"go/token"
|
|
"strings"
|
|
)
|
|
|
|
type LocatedError struct {
|
|
Location string
|
|
Kind string
|
|
Err error
|
|
}
|
|
|
|
func (e LocatedError) Error() string {
|
|
var sb strings.Builder
|
|
|
|
sb.WriteString(e.Location)
|
|
sb.WriteString(":\t")
|
|
if e.Kind != "" {
|
|
sb.WriteString(e.Kind)
|
|
sb.WriteString(": ")
|
|
}
|
|
sb.WriteString("ERROR: ")
|
|
sb.WriteString(e.Err.Error())
|
|
|
|
return sb.String()
|
|
}
|
|
|
|
func InitLocaleTrFunctions() map[string][]uint {
|
|
ret := make(map[string][]uint)
|
|
|
|
f0 := []uint{0}
|
|
ret["Tr"] = f0
|
|
ret["TrString"] = f0
|
|
ret["TrHTML"] = f0
|
|
|
|
ret["TrPluralString"] = []uint{1}
|
|
ret["TrN"] = []uint{1, 2}
|
|
|
|
return ret
|
|
}
|
|
|
|
type Handler struct {
|
|
OnMsgid func(fset *token.FileSet, pos token.Pos, msgid string, weak bool)
|
|
OnMsgidPrefix func(fset *token.FileSet, pos token.Pos, msgidPrefix string, truncated bool)
|
|
OnUnexpectedInvoke func(fset *token.FileSet, pos token.Pos, funcname string, argc int)
|
|
OnWarning func(fset *token.FileSet, pos token.Pos, msg string)
|
|
LocaleTrFunctions map[string][]uint
|
|
}
|
|
|
|
// Truncating a message id prefix to the last dot
|
|
func PrepareMsgidPrefix(s string) (string, bool) {
|
|
index := strings.LastIndexByte(s, 0x2e)
|
|
if index == -1 {
|
|
return "", true
|
|
}
|
|
return s[:index], index != len(s)-1
|
|
}
|