Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d4e694

Browse files
committed
Make Message Translation plugable
This allows users to override the Message function in revel with their own. It defaults to the existing Message function, so there should be no compatibility issues.
1 parent 7b7b105 commit 9d4e694

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (c *Controller) Redirect(val interface{}, args ...interface{}) Result {
233233
//
234234
// The current language is set by the i18n plugin.
235235
func (c *Controller) Message(message string, args ...interface{}) (value string) {
236-
return Message(c.Request.Locale, message, args...)
236+
return MessageFunc(c.Request.Locale, message, args...)
237237
}
238238

239239
// SetAction sets the action that is being invoked in the current request.

i18n.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ var (
2424
messages map[string]*config.Config
2525
)
2626

27+
// Setting MessageFunc allows you to override the translation interface.
28+
//
29+
// Set this to your own function that translates to the current locale.
30+
// This allows you to set up your own loading and logging of translated texts.
31+
//
32+
// See Message(...) in i18n.go for example of function.
33+
var MessageFunc func(locale, message string, args ...interface{}) (value string) = Message
34+
2735
// Return all currently loaded message languages.
2836
func MessageLanguages() []string {
2937
languages := make([]string, len(messages))

template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ var (
124124
if !ok {
125125
return ""
126126
}
127-
return template.HTML(Message(str, message, args...))
127+
return template.HTML(MessageFunc(str, message, args...))
128128
},
129129

130130
// Replaces newlines with <br>

0 commit comments

Comments
 (0)