Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(plugin): remove plugin translator context

LinkinStars822a96721a97
diff --git a/plugin/plugin.go b/plugin/plugin.go
index 6643b5a1..43fef87f 100644
--- a/plugin/plugin.go
+++ b/plugin/plugin.go
@@ -2,6 +2,7 @@ package plugin
import (
"encoding/json"
+
"github.com/answerdev/answer/internal/base/handler"
"github.com/answerdev/answer/internal/base/translator"
"github.com/gin-gonic/gin"
@@ -114,8 +115,7 @@ type TranslateFn func(ctx *GinContext) string
// Translator contains a function that translates the key to the current language of the context
type Translator struct {
- fn TranslateFn
- ctx *GinContext
+ fn TranslateFn
}
// MakeTranslator generates a translator from the key
@@ -123,32 +123,13 @@ func MakeTranslator(key string) Translator {
t := func(ctx *GinContext) string {
return Translate(ctx, key)
}
-
return Translator{fn: t}
}
-// SetContext sets the context of the multi translators
-func SetContext(ctx *GinContext, ts ...Translator) {
- for _, t := range ts {
- t.SetContext(ctx)
- }
-}
-
// Translate translates the key to the current language of the context
func (t Translator) Translate(ctx *GinContext) string {
if &t == nil || t.fn == nil {
return ""
}
-
return t.fn(ctx)
}
-
-// SetContext sets the context of the translator
-func (t Translator) SetContext(ctx *GinContext) {
- t.ctx = ctx
-}
-
-// String returns the translated string through the context
-func (t Translator) String() string {
- return t.Translate(t.ctx)
-}
diff --git a/plugin/sample/connector.go b/plugin/sample/connector.go
index 4c26886a..55d4bfec 100644
--- a/plugin/sample/connector.go
+++ b/plugin/sample/connector.go
@@ -9,7 +9,7 @@ func init() {
plugin.Register(&Connector{})
}
-func (g *Connector) Info() plugin.Info {
+func (c *Connector) Info() plugin.Info {
return plugin.Info{
Name: plugin.MakeTranslator("plugin.connector.name"),
SlugName: "connector",