i18n

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

type Bundle struct {
	*i18n.Bundle
	// contains filtered or unexported fields
}

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

func InitBundle(api PluginAPI, path string) (*Bundle, error)

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/public/plugin"
	"github.com/mattermost/mattermost/server/public/pluginapi/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
}
Output:

func (*Bundle) GetServerLocalizer

func (b *Bundle) GetServerLocalizer() *i18n.Localizer

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

func (b *Bundle) GetUserLocalizer(userID string) *i18n.Localizer

GetUserLocalizer returns a localizer that localizes in the users locale.

func (*Bundle) LocalizeDefaultMessage

func (b *Bundle) LocalizeDefaultMessage(l *Localizer, m *Message) string

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

type Localizer = i18n.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

type Message = i18n.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.

type PluginAPI

type PluginAPI interface {
	GetBundlePath() (string, error)
	GetConfig() *model.Config
	GetUser(userID string) (*model.User, *model.AppError)
	LogWarn(msg string, keyValuePairs ...interface{})
}

PluginAPI is the plugin API interface required to manage translations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL