go-locale

Build Status Go Doc Go Report Card License

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

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

GitHub

https://github.com/Xuanwo/go-locale