i18n

package
v4.4.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package i18n wraps go-i18n lib for manipulating bundles

Index

Constants

This section is empty.

Variables

View Source
var (
	// AvailableLanguages stores a manually maintained maps with all languages
	// that are currently supported by Cells front-end and can be chosen via the interface.
	AvailableLanguages = map[string]string{
		"de":    "Deutsch",
		"en-us": "English",
		"es-es": "Español",
		"fr":    "Français",
		"it":    "Italiano",
		"lv":    "Latv",
		"pt-br": "Português do Brasil",
		"ru":    "русский",
		"vi-vn": "Tiếng Việt",
		"zh-cn": "简体中文",
	}

	// LoadingStrings have to be hard-coded to be loaded first. When not defined, we fall back to "loading..." message (in English).
	LoadingStrings = map[string]string{
		"ar":    "نحميل...",
		"cs":    "Načítání...",
		"de":    "Wird geladen...",
		"en-us": "Loading...",
		"es-en": "Cargando...",
		"fr":    "Chargement...",
		"fr-ca": "Chargement...",
		"hu":    "Betöltés...",
		"it":    "Caricamento...",
		"ja":    "読み込んでいます...",
		"ko":    "로드 중 ...",
		"lv":    "Ielādē...",
		"nl":    "Bezig met laden...",
		"pl":    "Ładowanie...",
		"pt-br": "Carregando...",
		"pt-pt": "Carregando...",
		"ru":    "Загружается ...",
		"sk":    "Načítavanie...",
		"sv-se": "Läser in...",
		"vi-vn": "Đang tải...",
		"zh-cn": "载入中...",
		"zh-tw": "載入中...",
	}

	// WipLanguages lists languages that are only partially translated and only exposed
	// in the end-user web UI when CELLS_ENABLE_WIP_LANGUAGES env variable is set to true.
	WipLanguages = map[string]string{
		"ar":    "عربى",
		"cs":    "Česky",
		"fr-ca": "Canadien",
		"hu":    "Magyar",
		"ja":    "日本人",
		"ko":    "한국어",
		"nl":    "Nederlands",
		"pl":    "Polski",
		"pt-pt": "Português",
		"sk":    "Slovensky",
		"sv-se": "Svenska",
		"zh-tw": "中國傳統的",
	}

	LanguagesLegacyNames = map[string]string{
		"en":    "en-us",
		"fr":    "fr",
		"es":    "es-es",
		"it":    "it",
		"pt":    "pt-pt",
		"pt-br": "pt-br",
		"de":    "de",

		"ru":    "ru",
		"ca":    "ca",
		"cs":    "cs",
		"da":    "da",
		"et":    "et",
		"fi":    "fi",
		"he":    "he",
		"hu":    "hu",
		"ja":    "ja",
		"ko":    "ko",
		"nl":    "nl",
		"nn":    "nn-no",
		"pl":    "pl",
		"si":    "sl",
		"sv":    "sv-se",
		"tr":    "tr",
		"zh-cn": "zh-cn",
		"zh-tw": "zh-tw",
	}
)

Functions

func GetDefaultLanguage

func GetDefaultLanguage(conf configx.Values) string

GetDefaultLanguage reads default language from config

func IdentityFunc added in v4.4.0

func IdentityFunc(translationID string, args ...interface{}) string

func UserLanguage

func UserLanguage(ctx context.Context, user *idm.User, conf configx.Values) string

UserLanguage looks for the user roles and check if a language parameter is set (starting from the last). Otherwise returns the default language from config

func UserLanguageFromContext

func UserLanguageFromContext(ctx context.Context, conf configx.Values, returnDefault bool) string

UserLanguageFromContext tries to find Claims in context and get the language for the corresponding user. If nothing is found, if returnDefault is true it returns the global default language, otherwise it returns an empty string.

func UserLanguagesFromRestRequest

func UserLanguagesFromRestRequest(req *restful.Request, conf configx.Values) []string

UserLanguagesFromRestRequest tries to find user language from various sources: X-Pydio-Language header, user language inside the system (set via roles), or Accept-Language standard header.

Types

type I18nBundle

type I18nBundle struct {
	*i18n.Bundle
}

func NewI18nBundle

func NewI18nBundle(box statics.FS) *I18nBundle

NewI18nBundle creates a usable I18nBundle

func (*I18nBundle) GetTranslationFunc

func (b *I18nBundle) GetTranslationFunc(languages ...string) TranslateFunc

GetTranslationFunc provides the correct translation func for language or the IdentityFunc if language is not supported. Languages can be a list of weighted languages as provided in the http header Accept-Language

func (*I18nBundle) LoadBoxTranslationFiles added in v4.4.0

func (b *I18nBundle) LoadBoxTranslationFiles(box statics.FS)

LoadBoxTranslationFiles loads goi18n translation files from boxes

type TranslateFunc added in v4.4.0

type TranslateFunc func(translationID string, args ...interface{}) string

Jump to

Keyboard shortcuts

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