langpick

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package langpick negotiates a site language from an Accept-Language header and names languages in their own script (endonyms) for language switchers.

Negotiate understands more than the two-letter prefix of each tag: an exact tag ("pt-BR") matches a supported code of the same spelling, and Chinese tags are mapped to the script subtags sites usually ship ("zh-CN", "zh-SG" → zh-Hans; "zh-TW", "zh-HK", "zh-MO" → zh-Hant), which a plain prefix match cannot tell apart.

Index

Constants

View Source
const (
	ChineseSimplified  = "zh-Hans"
	ChineseTraditional = "zh-Hant"
)

Script subtags for Chinese.

Variables

This section is empty.

Functions

func Name

func Name(code string) string

Name returns the endonym for code ("de" → "Deutsch", "zh-Hant" → "繁體中文"), or code itself when it is not known.

func Negotiate

func Negotiate(acceptLanguage string, supported []string) string

Negotiate returns the supported code for the first Accept-Language tag the site can serve, or "" when none matches. Tags are taken in header order; quality values are ignored because browsers already send tags in preference order. Per tag, in order:

  1. An exact, case-insensitive match ("pt-br" → "pt-BR").
  2. For Chinese: the script variant derived from the tag (Hant or a TW/HK/MO region → zh-Hant, anything else → zh-Hans), then bare "zh".
  3. The primary language subtag ("de-AT" → "de").

The returned value is always spelled as in supported.

Types

This section is empty.

Jump to

Keyboard shortcuts

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