@@ -29,7 +29,8 @@ const (
29
29
30
30
var (
31
31
// All currently loaded message configs.
32
- messages map [string ]* config.Config
32
+ messages map [string ]* config.Config
33
+ localeParameterName string
33
34
)
34
35
35
36
// MessageFunc allows you to override the translation interface.
@@ -182,19 +183,31 @@ func parseLocaleFromFileName(file string) string {
182
183
func init () {
183
184
OnAppStart (func () {
184
185
loadMessages (filepath .Join (BasePath , messageFilesDirectory ))
185
- })
186
+ localeParameterName = Config .StringDefault ("i18n.locale.parameter" , "" )
187
+ }, 0 )
186
188
}
187
189
188
190
func I18nFilter (c * Controller , fc []Filter ) {
189
- if foundCookie , cookieValue := hasLocaleCookie (c .Request ); foundCookie {
190
- TRACE .Printf ("Found locale cookie value: %s" , cookieValue )
191
- setCurrentLocaleControllerArguments (c , cookieValue )
192
- } else if foundHeader , headerValue := hasAcceptLanguageHeader (c .Request ); foundHeader {
193
- TRACE .Printf ("Found Accept-Language header value: %s" , headerValue )
194
- setCurrentLocaleControllerArguments (c , headerValue )
195
- } else {
196
- TRACE .Println ("Unable to find locale in cookie or header, using empty string" )
197
- setCurrentLocaleControllerArguments (c , "" )
191
+ foundLocale := false
192
+ // Search for a parameter first
193
+ if localeParameterName != "" {
194
+ if locale , found := c .Params .Values [localeParameterName ]; found && len (locale [0 ]) > 0 {
195
+ setCurrentLocaleControllerArguments (c , locale [0 ])
196
+ foundLocale = true
197
+ TRACE .Printf ("Found locale parameter value: %s" , locale [0 ])
198
+ }
199
+ }
200
+ if ! foundLocale {
201
+ if foundCookie , cookieValue := hasLocaleCookie (c .Request ); foundCookie {
202
+ TRACE .Printf ("Found locale cookie value: %s" , cookieValue )
203
+ setCurrentLocaleControllerArguments (c , cookieValue )
204
+ } else if foundHeader , headerValue := hasAcceptLanguageHeader (c .Request ); foundHeader {
205
+ TRACE .Printf ("Found Accept-Language header value: %s" , headerValue )
206
+ setCurrentLocaleControllerArguments (c , headerValue )
207
+ } else {
208
+ TRACE .Println ("Unable to find locale in cookie or header, using empty string" )
209
+ setCurrentLocaleControllerArguments (c , "" )
210
+ }
198
211
}
199
212
fc [0 ](c , fc [1 :])
200
213
}
0 commit comments