locale

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 57

README

go-locale

Build Status Go Doc License go locale

go-locale is a Golang lib for cross-platform locale detection.

OS Support

Support all OS that Golang supported, except android:

POSIX Compatible Systems
  • Lookup env LANGUAGE
  • Lookup env LC_ALL
  • Lookup env LC_MESSAGES
  • Lookup env LANG
  • Read file $XDG_CONFIG_HOME/locale.conf
  • Read file $HOME/.config/locale.conf
  • Read file /etc/locale.conf
Js
  • Lookup env LANGUAGE
  • Lookup env LC_ALL
Windows
  • Lookup env LANGUAGE
  • Lookup env LC_ALL
  • Lookup env LC_MESSAGES
  • Lookup env LANG
  • Windows Registry
macOS X (darwin)
  • Lookup env LANGUAGE
  • Lookup env LC_ALL
  • Lookup env LC_MESSAGES
  • Lookup env LANG
  • macOS X User Defaults System
    • Lookup user AppleLocale
    • Lookup user AppleLanguages
    • Lookup global AppleLocale
    • Lookup global AppleLanguages

Usage

import (
    "github.com/Xuanwo/go-locale"
)

func main() {
    tag, err := locale.Detect()
    if err != nil {
        log.Fatal(err)
    }
    // Have fun with language.Tag!

    tags, err := locale.DetectAll()
    if err != nil {
        log.Fatal(err)
    }
    // Get all available tags
}

Acknowledgments

Inspired by jibber_jabber

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotDetected returns while no locale detected.
	ErrNotDetected = errors.New("not detected")
	// ErrNotSupported means current platform or language is not supported.
	ErrNotSupported = errors.New("not supported")
)

Functions

func Detect

func Detect() (tag language.Tag, err error)

Detect will detect current env's language.

func DetectAll

func DetectAll() (tags []language.Tag, err error)

DetectAll will detect current env's all available language.

Types

type Error

type Error struct {
	Op  string
	Err error
}

Error is the error returned by locale.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements xerrors.Wrapper

Jump to

Keyboard shortcuts

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