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

Skip to content

Commit a83447f

Browse files
committed
Merge pull request revel#768 from klauspost/i18n-plugable-message
i18n: Make Message translation function pluggable
2 parents fa40607 + 9d4e694 commit a83447f

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
@@ -260,7 +260,7 @@ func (c *Controller) Redirect(val interface{}, args ...interface{}) Result {
260260
//
261261
// The current language is set by the i18n plugin.
262262
func (c *Controller) Message(message string, args ...interface{}) (value string) {
263-
return Message(c.Request.Locale, message, args...)
263+
return MessageFunc(c.Request.Locale, message, args...)
264264
}
265265

266266
// 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
@@ -25,6 +25,14 @@ var (
2525
messages map[string]*config.Config
2626
)
2727

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

template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var (
126126
if !ok {
127127
return ""
128128
}
129-
return template.HTML(Message(str, message, args...))
129+
return template.HTML(MessageFunc(str, message, args...))
130130
},
131131

132132
// Replaces newlines with <br>

0 commit comments

Comments
 (0)