The Connector
’s LoadResString
method loads and localizes strings stored in a static resource named strings.yaml
. LoadResString
extracts the request’s locale from the Accept-Language
header embedded in the context’s frame, and returns the string in the language best matching it.
func (svc *Service) Localization(w http.ResponseWriter, r *http.Request) (err error) {
ctx := r.Context()
localizedStr, _ := svc.LoadResString(ctx, "stringKey")
w.Write([]byte(localizedStr))
return nil
}
strings.yaml
is expected to have the following format:
stringKey:
default: Localized
en: Localized
en-GB: Localised
fr: Localisée
If a default is not provided, English (en) is used as the fallback language. String keys and locale names are case insensitive.