Documentation
¶
Overview ¶
package i18n provides methods to read translations files and localize strings.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
Bundle stores a set of messages and pluralization rules. Most plugins only need a single bundle that is initialized on activation. It is not goroutine safe to modify the bundle while Localizers are reading from it.
func InitBundle ¶
InitBundle loads all localization files from a given path into a bundle and return this. path is a relative path in the plugin bundle, e.g. assets/i18n. Every file except the ones named active.*.json. The default language is English.
Example ¶
package main
import (
"path/filepath"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/mattermost/mattermost-plugin-api/i18n"
)
func main() {
type Plugin struct {
plugin.MattermostPlugin
b *i18n.Bundle
}
p := Plugin{}
b, err := i18n.InitBundle(p.API, filepath.Join("assets", "i18n"))
if err != nil {
panic(err)
}
p.b = b
}
func (*Bundle) GetServerLocalizer ¶
GetServerLocalizer returns a localizer that localizes in the default server locale.
This is useful for situations where a messages is shown to every user, independent of the users locale.
func (*Bundle) GetUserLocalizer ¶
GetUserLocalizer returns a localizer that localizes in the users locale.
func (*Bundle) LocalizeDefaultMessage ¶
LocalizeDefaultMessage localizer the provided message. An empty string is returned when the localization fails.
func (*Bundle) LocalizeWithConfig ¶
func (b *Bundle) LocalizeWithConfig(l *Localizer, lc *LocalizeConfig) string
LocalizeWithConfig localizer the provided localize config. An empty string is returned when the localization fails.
type LocalizeConfig ¶
type LocalizeConfig = i18n.LocalizeConfig
LocalizeConfig configures a call to the Localize method on Localizer.
See https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/i18n?tab=doc#LocalizeConfig for more details.
type Localizer ¶
Localizer provides Localize and MustLocalize methods that return localized messages.
See https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/i18n?tab=doc#Localizer for more details.
type Message ¶
Message is a string that can be localized.
See https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2/i18n?tab=doc#Message for more details.