package langs

import "github.com/gohugoio/hugo/langs"

Package langs contains the language related types and function.

Index

Variables

var DeprecationFunc = func(item, alternative string, err bool) {}

This is injected from hugolib to avoid circular dependencies.

Functions

func DecodeConfig

func DecodeConfig(m map[string]any) (map[string]LanguageConfig, error)

func GetLocation

func GetLocation(l *Language) *time.Location

func GetTimeFormatter

func GetTimeFormatter(l *Language) htime.TimeFormatter

func GetTranslator

func GetTranslator(l *Language) locales.Translator

func SetParams

func SetParams(l *Language, params maps.Params)

Types

type Collator

type Collator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func GetCollator1

func GetCollator1(l *Language) *Collator

func GetCollator2

func GetCollator2(l *Language) *Collator

func (*Collator) CompareStrings

func (c *Collator) CompareStrings(a, b string) int

CompareStrings compares a and b. It returns -1 if a < b, 1 if a > b and 0 if a == b. Note that the Collator is not thread safe, so you may want to acquire a lock on it before calling this method.

type Language

type Language struct {
	// The language code, e.g. "en" or "no".
	// This is currently only settable as the key in the language map in the config.
	Lang string

	// Fields from the language config.
	LanguageConfig
	// contains filtered or unexported fields
}

func NewLanguage

func NewLanguage(lang, defaultContentLanguage, timeZone string, languageConfig LanguageConfig) (*Language, error)

NewLanguage creates a new language.

func (*Language) LanguageCode

func (l *Language) LanguageCode() string

func (*Language) Params

func (l *Language) Params() maps.Params

Params returns the language params. Note that this is the same as the Site.Params, but we keep it here for legacy reasons. Deprecated: Use the site.Params instead.

func (*Language) String

func (l *Language) String() string

type LanguageConfig

type LanguageConfig struct {
	// The language name, e.g. "English".
	LanguageName string

	// The language code, e.g. "en-US".
	LanguageCode string

	// The language title. When set, this will
	// override site.Title for this language.
	Title string

	// The language direction, e.g. "ltr" or "rtl".
	LanguageDirection string

	// The language weight. When set to a non-zero value, this will
	// be the main sort criteria for the language.
	Weight int

	// Set to true to disable this language.
	Disabled bool
}

LanguageConfig holds the configuration for a single language. This is what is read from the config file.

type Languages

type Languages []*Language

Languages is a sortable list of languages.

func (Languages) AsIndexSet

func (l Languages) AsIndexSet() map[string]int

AsIndexSet returns a map with the language code as key and index in l as value.

func (Languages) AsSet

func (l Languages) AsSet() map[string]bool

Source Files

config.go language.go

Directories

PathSynopsis
langs/i18n
Version
v0.144.2 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
11 packages
Last checked
13 hours ago

Tools for package owners.