Page context handling in i18n

This is a workaround. We need to improve on this, but not today.

Fixes #10782
This commit is contained in:
Bjørn Erik Pedersen
2023-03-04 14:43:23 +01:00
parent ec1c97e7e9
commit 6c798eba60
6 changed files with 115 additions and 9 deletions

View File

@@ -14,6 +14,7 @@
package i18n
import (
"context"
"fmt"
"path/filepath"
"testing"
@@ -408,9 +409,10 @@ other = "{{ . }} miesiąca"
c.Assert(d.LoadResources(), qt.IsNil)
f := tp.t.Func(test.lang)
ctx := context.Background()
for _, variant := range test.variants {
c.Assert(f(test.id, variant.Key), qt.Equals, variant.Value, qt.Commentf("input: %v", variant.Key))
c.Assert(f(ctx, test.id, variant.Key), qt.Equals, variant.Value, qt.Commentf("input: %v", variant.Key))
c.Assert(int(depsCfg.Logger.LogCounters().WarnCounter.Count()), qt.Equals, 0)
}
@@ -422,7 +424,7 @@ other = "{{ . }} miesiąca"
func doTestI18nTranslate(t testing.TB, test i18nTest, cfg config.Provider) string {
tp := prepareTranslationProvider(t, test, cfg)
f := tp.t.Func(test.lang)
return f(test.id, test.args)
return f(context.Background(), test.id, test.args)
}
type countField struct {
@@ -542,7 +544,7 @@ func BenchmarkI18nTranslate(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := tp.t.Func(test.lang)
actual := f(test.id, test.args)
actual := f(context.Background(), test.id, test.args)
if actual != test.expected {
b.Fatalf("expected %v got %v", test.expected, actual)
}