...

Source file src/github.com/chai2010/gettext-go/util.go

Documentation: github.com/chai2010/gettext-go

     1  // Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gettext
     6  
     7  import (
     8  	"os"
     9  	"strings"
    10  )
    11  
    12  func getDefaultLanguage() string {
    13  	if v := os.Getenv("LC_MESSAGES"); v != "" {
    14  		return simplifiedLanguage(v)
    15  	}
    16  	if v := os.Getenv("LANG"); v != "" {
    17  		return simplifiedLanguage(v)
    18  	}
    19  	return "default"
    20  }
    21  
    22  func simplifiedLanguage(lang string) string {
    23  	// en_US/en_US.UTF-8/zh_CN/zh_TW/el_GR@euro/...
    24  	if idx := strings.Index(lang, ":"); idx != -1 {
    25  		lang = lang[:idx]
    26  	}
    27  	if idx := strings.Index(lang, "@"); idx != -1 {
    28  		lang = lang[:idx]
    29  	}
    30  	if idx := strings.Index(lang, "."); idx != -1 {
    31  		lang = lang[:idx]
    32  	}
    33  	return strings.TrimSpace(lang)
    34  }
    35  

View as plain text