package langs
import "github.com/gohugoio/hugo/langs"
Package langs contains the language related types and function.
Index ¶
- Variables
- func DecodeConfig(defaultContentLanguage string, disabledLanguages []string, m map[string]any) (*config.ConfigNamespace[map[string]LanguageConfig, LanguagesInternal], string, error)
- func GetLocation(l *Language) *time.Location
- func GetTimeFormatter(l *Language) htime.TimeFormatter
- func GetTranslator(l *Language) locales.Translator
- func IndexDefault(languages Languages) int
- func SetParams(l *Language, params maps.Params)
- type Collator
- func GetCollator1(l *Language) *Collator
- func GetCollator2(l *Language) *Collator
- func (c *Collator) CompareStrings(a, b string) int
- type Language
- func NewLanguage(lang, defaultContentLanguage, timeZone string, languageConfig LanguageConfig) (*Language, error)
- func (l *Language) IsDefault() bool
- func (l *Language) LanguageCode() string
- func (l *Language) Name() string
- func (l *Language) Params() maps.Params
- func (l *Language) String() string
- type LanguageConfig
- type LanguageInternal
- type Languages
- type LanguagesInternal
- func (ls LanguagesInternal) ForEachIndex() iter.Seq[int]
- func (ls LanguagesInternal) IndexDefault() int
- func (ls LanguagesInternal) IndexMatch(match predicate.P[string]) (iter.Seq[int], error)
- func (ls LanguagesInternal) Len() int
- func (ls LanguagesInternal) ResolveIndex(name string) int
- func (ls LanguagesInternal) ResolveName(i int) string
Variables ¶
This is injected from hugolib to avoid circular dependencies.
Functions ¶
func DecodeConfig ¶
func DecodeConfig(defaultContentLanguage string, disabledLanguages []string, m map[string]any) (*config.ConfigNamespace[map[string]LanguageConfig, LanguagesInternal], string, error)
func GetLocation ¶
func GetTimeFormatter ¶
func GetTimeFormatter(l *Language) htime.TimeFormatter
func GetTranslator ¶
func GetTranslator(l *Language) locales.Translator
func IndexDefault ¶
IndexDefault returns the index of the default language.
func SetParams ¶
Types ¶
type Collator ¶
func GetCollator1 ¶
func GetCollator2 ¶
func (*Collator) CompareStrings ¶
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 the key used in the languages map in the configuration,
// and 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) IsDefault ¶
func (*Language) LanguageCode ¶
func (*Language) Name ¶
Name is an alias for Lang.
func (*Language) 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 ¶
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 LanguageInternal ¶
type LanguageInternal struct {
// Name is the name of the role, extracted from the key in the config.
Name string
// Whether this role is the default role.
// This will be rendered in the root.
// There is only be one default role.
Default bool
LanguageConfig
}
type Languages ¶
type Languages []*Language
Languages is a sortable list of languages.
func (Languages) AsIndexSet ¶
AsIndexSet returns a map with the language code as key and index in l as value.
func (Languages) AsSet ¶
type LanguagesInternal ¶
type LanguagesInternal struct {
LanguageConfigs map[string]LanguageConfig
Sorted []LanguageInternal
}
func (LanguagesInternal) ForEachIndex ¶
func (ls LanguagesInternal) ForEachIndex() iter.Seq[int]
ForEachIndex returns an iterator for the indices of the languages.
func (LanguagesInternal) IndexDefault ¶
func (ls LanguagesInternal) IndexDefault() int
func (LanguagesInternal) IndexMatch ¶
IndexMatch returns an iterator for the roles that match the filter.
func (LanguagesInternal) Len ¶
func (ls LanguagesInternal) Len() int
func (LanguagesInternal) ResolveIndex ¶
func (ls LanguagesInternal) ResolveIndex(name string) int
func (LanguagesInternal) ResolveName ¶
func (ls LanguagesInternal) ResolveName(i int) string
Source Files ¶
Directories ¶
| Path | Synopsis |
|---|---|
| langs/i18n |
- Version
- v0.153.4 (latest)
- Published
- Dec 28, 2025
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 4 months ago –
Tools for package owners.