Skip to content
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

Share HTML template renderers and create a watcher framework #20218

Merged
merged 28 commits into from
Aug 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1409281
Share HTML template renderers and create a watcher framework
zeripath Jun 28, 2022
07dc4f2
placate lint
zeripath Jul 3, 2022
f265ce5
fix windows
zeripath Jul 3, 2022
726bf7c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 4, 2022
aa90128
Init needs a ctx
zeripath Jul 4, 2022
0209fa4
make SSPI also share the templates too
zeripath Jul 4, 2022
a04e94a
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 5, 2022
7dd067b
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 6, 2022
f61f79c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 9, 2022
cbdc8bc
use todo only
zeripath Jul 10, 2022
9e63150
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
1159e0f
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
959595b
Switch to use syncthing/notify instead of fsnotify/fsnotify
zeripath Jul 16, 2022
aca2416
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Jul 16, 2022
426eb8f
Revert "Switch to use syncthing/notify instead of fsnotify/fsnotify"
zeripath Jul 17, 2022
f3b8468
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 31, 2022
eb8cf0f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 12, 2022
408a726
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 22, 2022
ab27d13
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 23, 2022
bfab646
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 24, 2022
3841573
as per review
zeripath Aug 24, 2022
2dbfc50
Fix tests
zeripath Aug 24, 2022
0ff8921
placate lint
zeripath Aug 24, 2022
a442905
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 27, 2022
c5bdfef
Update modules/templates/htmlrenderer.go
zeripath Aug 27, 2022
55c4ec6
placate lint
zeripath Aug 27, 2022
f7a5cd7
as per wxiaoguang
zeripath Aug 28, 2022
aec5c2f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 28, 2022
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
Prev Previous commit
Next Next commit
Fix tests
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Aug 24, 2022
commit 2dbfc50660bc220ed6ce204767a93e05be362889
15 changes: 11 additions & 4 deletions modules/charset/escape_test.go
Original file line number Diff line number Diff line change
@@ -133,11 +133,18 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
},
}

type nullLocale struct{}

func (nullLocale) Language() string { return "" }
func (nullLocale) Tr(key string, _ ...interface{}) string { return key }
func (nullLocale) TrN(cnt interface{}, key1, keyN string, args ...interface{}) string { return "" }

var _ (translation.Locale) = nullLocale{}

func TestEscapeControlString(t *testing.T) {
for _, tt := range escapeControlTests {
t.Run(tt.name, func(t *testing.T) {
locale := translation.NewLocale("en_US")
status, result := EscapeControlString(tt.text, locale)
status, result := EscapeControlString(tt.text, nullLocale{})
if !reflect.DeepEqual(*status, tt.status) {
t.Errorf("EscapeControlString() status = %v, wanted= %v", status, tt.status)
}
@@ -173,7 +180,7 @@ func TestEscapeControlReader(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
input := strings.NewReader(tt.text)
output := &strings.Builder{}
status, err := EscapeControlReader(input, output, translation.NewLocale("en_US"))
status, err := EscapeControlReader(input, output, nullLocale{})
result := output.String()
if err != nil {
t.Errorf("EscapeControlReader(): err = %v", err)
@@ -195,5 +202,5 @@ func TestEscapeControlReader_panic(t *testing.T) {
for i := 0; i < 6826; i++ {
bs = append(bs, []byte("—")...)
}
_, _ = EscapeControlString(string(bs), translation.NewLocale("en_US"))
_, _ = EscapeControlString(string(bs), nullLocale{})
}
19 changes: 9 additions & 10 deletions modules/translation/i18n/localestore.go
Original file line number Diff line number Diff line change
@@ -98,27 +98,26 @@ func (store *localeStore) SetDefaultLang(lang string) {
func (store *localeStore) Tr(lang, trKey string, trArgs ...interface{}) string {
l, _ := store.Locale(lang)

if l != nil {
return l.Tr(trKey, trArgs...)
}
return trKey
return l.Tr(trKey, trArgs...)
}

// Has returns whether the given language has a translation for the provided key
func (store *localeStore) Has(lang, trKey string) bool {
l, _ := store.Locale(lang)

if l != nil {
return false
}
return l.Has(trKey)
}

// Locale returns the locale for the lang or the default language
func (store *localeStore) Locale(lang string) (l Locale, found bool) {
l, found = store.localeMap[lang]
func (store *localeStore) Locale(lang string) (Locale, bool) {
l, found := store.localeMap[lang]
if !found {
l = store.localeMap[store.defaultLang]
var ok bool
l, ok = store.localeMap[store.defaultLang]
if !ok {
// no default - return an empty locale
l = &locale{store: store, idxToMsgMap: make(map[int]string)}
}
}
return l, found
}