code.gitea.io/gitea@v1.22.3/modules/translation/mock.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package translation 5 6 import ( 7 "fmt" 8 "html/template" 9 "strings" 10 ) 11 12 // MockLocale provides a mocked locale without any translations 13 type MockLocale struct { 14 Lang, LangName string // these fields are used directly in templates: ctx.Locale.Lang 15 } 16 17 var _ Locale = (*MockLocale)(nil) 18 19 func (l MockLocale) Language() string { 20 return "en" 21 } 22 23 func (l MockLocale) TrString(s string, args ...any) string { 24 return sprintAny(s, args...) 25 } 26 27 func (l MockLocale) Tr(s string, args ...any) template.HTML { 28 return template.HTML(sprintAny(s, args...)) 29 } 30 31 func (l MockLocale) TrN(cnt any, key1, keyN string, args ...any) template.HTML { 32 return template.HTML(sprintAny(key1, args...)) 33 } 34 35 func (l MockLocale) PrettyNumber(v any) string { 36 return fmt.Sprint(v) 37 } 38 39 func sprintAny(s string, args ...any) string { 40 if len(args) == 0 { 41 return s 42 } 43 return s + ":" + fmt.Sprintf(strings.Repeat(",%v", len(args))[1:], args...) 44 }