Go Server (GopherSauce) localization extension.
Add the following tag within your .gxml
file :
<import src="github.com/cheikhshift/locale/gos.xml" />
Use the following command to download this package :
go get github.com/cheikhshift/locale
The setup of this package is in Go. Feel free to use a go file to specify the translation of a particular phrase. You may add localizations of your strings within your .gxml
's main tag as well.
Use the following function to add a new localized phrase.
func Add(local, base, localized string)
For example to add a new localization of string FOO
to local en-US
the call would be :
locale.Add("en-US", "FOO", "Huh")
Use the following function to get a localized phrase.
Str(localename, lookup string) (localized string)
For example to get the localization of string FOO
with local en-US
the call would be :
locale.Str("en-US", "Foo")
Adjust your user's local with the following endpoint :
$(HOST_WITH_PROTOCOL):$(port)/set_local/$(desired_locale)
For example to set your website to wf-SN
(Wolof senegal) to request would be (To your application...) :
GET /set_local/wf-SN
Here is a list of methods used to localize and update localization settings :
{{ SetLoc $arg1 $arg2 }}
$arg1
: Validsessions.Session
object. With templates in yourweb/
folder use the field.Session
.$arg2
: Local to set for user.
{{ Loc $arg1 $arg2 }}
$arg1
: Validsessions.Session
object. With templates in yourweb/
folder use the field.Session
.$arg2
: String to localize with current settings
The following template snippet will localize string "Hello"
to the current user setting
{{ $session := .Session }}
{{ with "Hello" }}
{{ Loc $session . }}
{{ end }}
{{ with "World" }}
{{ Loc $session . }}
{{ end }}
{{ Locale $arg1 $arg2 }}
$arg1
: Local setting to use.$arg2
: String to localize with current settings
The following template snippet will localize string "Hello"
to the current user setting
{{ with "Hello" }}
{{ Locale "en-US" . }}
{{ end }}
{{ with "World" }}
{{ Locale "wf-SN" . }}
{{ end }}
var (
//disable to remove error messages.
DevMode = true
//map of string localizations
LocaleMap map[string]map[string]string
)