locale

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 7 Imported by: 83

README

go-locale

Build Status GoDoc Go Report Card codecov License

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

OS Support

Linux

Check order

  • LANGUAGE env
  • LC_ALL env
  • LC_MESSAGES env
  • LANG env
  • locale command call

Support

  • All linux distributions
Windows

Check order

  • Win32 OLE

Support

  • Windows Vista or Windows Server 2008 Later
macOS X (darwin)

Check order

  • All check for Linux
  • User Defaults System

Support

  • All macOS X version

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